vertica/VerticaPy

[QPROF] Problem with `get_query_events`

Closed this issue · 0 comments

oualib commented

Discussed in #1113

Originally posted by yakirgb January 8, 2024
Hi,
Tried to use get_query_events that based on v_monitor.query_events
But looks that that v_monitor.query_events not mentioned in :

    @staticmethod
    def _v_table_dict() -> dict:
        """
        Tables used by the ``QueryProfiler``
        object and their linked schema.
        """
        return {
            "dc_requests_issued": "v_internal",
            "dc_query_executions": "v_internal",
            "dc_explain_plans": "v_internal",
            "execution_engine_profiles": "v_monitor",
            "query_plan_profiles": "v_monitor",
            "query_profiles": "v_monitor",
            "resource_pool_status": "v_monitor",
            "host_resources": "v_monitor",
        }

And there is no copy for this table.
The query going to incorrect location of tests.query_events .
Call to qprof.get_query_events() generate error of :

from verticapy.performance.vertica import QueryProfiler

qprof = QueryProfiler( 
    key_id='yakir_8',
    target_schema='tests',
    )

qprof.get_query_events()

{
	"name": "MissingRelation",
	"message": "Severity: ERROR, Message: Relation \"tests.query_events\" does not exist, Sqlstate: 42V01, Routine: throwRelationDoesNotExist, File: /data/jenkins/workspace/RE-ReleaseBuilds/RE-Knuckleboom_2/server/vertica/Catalog/CatalogLookup.cpp, Line: 4163, Error Code: 4568, SQL: 'CREATE LOCAL TEMPORARY TABLE \"_verticapy_tmp_table_aboola_prod_ec930134ae6011eea616acde48001122_\" ON COMMIT PRESERVE ROWS AS SELECT event_timestamp, node_name, event_category, event_type, event_description, operator_name, path_id, event_details, suggested_action FROM tests.query_events WHERE transaction_id=54043195862558648 AND statement_id=3 ORDER BY 1'",
	"stack": "---------------------------------------------------------------------------
MissingRelation                           Traceback (most recent call last)
Cell In[48], line 1
----> 1 qprof.get_query_events()

File ~/git/VerticaPy/verticapy/performance/vertica/qprof.py:2595, in QueryProfiler.get_query_events(self)
   2576 query = f\"\"\"
   2577     SELECT
   2578         event_timestamp,
   (...)
   2592     ORDER BY
   2593         1;\"\"\"
   2594 query = self._replace_schema_in_query(query)
-> 2595 vdf = vDataFrame(query)
   2596 return vdf

File ~/git/VerticaPy/verticapy/_utils/_sql/_collect.py:244, in save_verticapy_logs.<locals>.func_prec_save_logs(*args, **kwargs)
    241 json_dict = {**json_dict, **kwargs}
    242 save_to_query_profile(name=name, path=path, json_dict=json_dict)
--> 244 return func(*args, **kwargs)

File ~/git/VerticaPy/verticapy/core/vdataframe/base.py:633, in vDataFrame.__init__(self, input_relation, usecols, schema, external, symbol, sql_push_ext, _empty, _is_sql_magic, _clean_query)
    631     # Getting the main relation information
    632     main_relation = f\"({sql}) VERTICAPY_SUBTABLE\"
--> 633     dtypes = get_data_types(sql)
    634     isflex = False
    636 else:

File ~/git/VerticaPy/verticapy/sql/dtypes.py:242, in get_data_types(expr, column, table_name, schema, usecols)
    240         table = format_schema_table(schema, table_name)
    241         local = \"\"
--> 242     _executeSQL(
    243         query=f\"\"\"
    244             CREATE {local} TEMPORARY TABLE {table} 
    245             ON COMMIT PRESERVE ROWS 
    246             AS {expr}\"\"\",
    247         print_time_sql=False,
    248     )
    249 finally:
    250     drop(format_schema_table(schema, table_name), method=\"table\")

File ~/git/VerticaPy/verticapy/_utils/_sql/_sys.py:184, in _executeSQL(query, title, data, method, path, print_time_sql, sql_push_ext, symbol, _clean_query)
    182         cursor.copy(query, f)
    183 else:
--> 184     cursor.execute(query)
    185 elapsed_time = time.time() - start_time
    186 if conf.get_option(\"time_on\") and print_time_sql:

File /usr/local/lib/python3.9/site-packages/vertica_python/vertica/cursor.py:188, in Cursor.handle_ctrl_c.<locals>.wrap(self, *args, **kwargs)
    186 def wrap(self, *args, **kwargs):
    187     try:
--> 188         return func(self, *args, **kwargs)
    189     except KeyboardInterrupt:
    190         self.connection.cancel()

File /usr/local/lib/python3.9/site-packages/vertica_python/vertica/cursor.py:266, in Cursor.execute(self, operation, parameters, use_prepared_statements, copy_stdin, buffer_size)
    264     if parameters:
    265         operation = self.format_operation_with_parameters(operation, parameters)
--> 266     self._execute_simple_query(operation)
    268 return self

File /usr/local/lib/python3.9/site-packages/vertica_python/vertica/cursor.py:786, in Cursor._execute_simple_query(self, query)
    784 self._message = self.connection.read_message()
    785 if isinstance(self._message, messages.ErrorResponse):
--> 786     raise errors.QueryError.from_error_response(self._message, query)
    787 elif isinstance(self._message, messages.RowDescription):
    788     self.description = self._message.get_description()

MissingRelation: Severity: ERROR, Message: Relation \"tests.query_events\" does not exist, Sqlstate: 42V01, Routine: throwRelationDoesNotExist, File: /data/jenkins/workspace/RE-ReleaseBuilds/RE-Knuckleboom_2/server/vertica/Catalog/CatalogLookup.cpp, Line: 4163, Error Code: 4568, SQL: 'CREATE LOCAL TEMPORARY TABLE \"_verticapy_tmp_table_aboola_prod_ec930134ae6011eea616acde48001122_\" ON COMMIT PRESERVE ROWS AS SELECT event_timestamp, node_name, event_category, event_type, event_description, operator_name, path_id, event_details, suggested_action FROM tests.query_events WHERE transaction_id=54043195862558648 AND statement_id=3 ORDER BY 1'"
}```

Thank you,
Yakir Gibraltar
Taboola</div>