verticapy.performance.vertica.qprof_interface.QueryProfilerInterface.import_profile¶
- static QueryProfilerInterface.import_profile(target_schema: str, key_id: str, filename: PathLike, tmp_dir: PathLike = '/tmp', auto_initialize: bool = True)¶
The static method
import_profilecan be used to create newQueryProfilerobject from the contents of a export bundle.Export bundles can be produced by the method
export_profile. The bundles contain system table data written into parquet files.- The method
import_profileexecutes the following steps: Unpacks the profie bundle
Creates tables in the in the target schema if they do not exist. The tables will be suffixed by
key_id.Copies the data from the parquet files into the tables
Creates a
QueryProfilerobject initialized to use data from the newly created and loaded tables.
The method returns the new
QueryProfilerobject.Parameters¶
- target_schema: str
The name of the schema to load data into
- key_id: str
The suffix for table names in the target_schema
- filename: os.PathLike
The file containing exported profile data
- tmp_dir: os.PathLike
The directory to use for temporary storage of unpacked files.
Returns¶
A QueryProfiler object
Examples¶
First, let’s import the
QueryProfilerobject.from verticapy.performance.vertica import QueryProfiler from verticapy.performance.vertica.collection.profile_export import ProfileExport
Now we can profile a query and create a set of system table replicas by calling the
QueryProfilerconstructor:qprof = QueryProfiler( "select transaction_id, statement_id, request, request_duration" " from query_requests where start_timestamp > now() - interval'1 hour'" " order by request_duration desc limit 10;", target_schema="replica_001", key_id="example123" )
We can use
export_profileto produce an export bundle. We choose to name our export bundle"query_requests_example_001.tar".qprof.export_profile(filename="query_requests_example_001.tar")
After producing an export bundle, we can import it into a different schema using
import_profile. For purposes of this example, we’ll import the data into another schema in the same database. We expect it is more common to import the bundle into another database.Let’s use the import schema name
import_002, which is distinct from the source schemareplica_001.qprof_imported = QueryProfiler.import_profile( target_schema="import_002", key_id="ex9876", filename="query_requests_example_001.tar" )
Now we use the
QueryProfilerto analyze the imported information. AllQueryProfilermethods are available. We’ll useget_qduration()as an example.print(f"First query duration was {qprof_imported.get_qduration()} seconds")
Let’s assume the query had a duration of 3.14 seconds. The output will be:
First query duration was 3.14 seconds
- The method