Skip to content

Commit

Permalink
QueryProfiler - Tooltip display for opeartors that produce variable l…
Browse files Browse the repository at this point in the history
…ength data
  • Loading branch information
mail4umar committed Jan 21, 2025
1 parent ec14e4c commit 7602452
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
59 changes: 57 additions & 2 deletions verticapy/performance/vertica/qprof.py
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,8 @@ def _v_table_dict() -> dict:
"projection_columns": "v_catalog",
"resource_acquisitions": "v_monitor",
"resource_pools": "v_catalog",
"dc_plan_step_properties": "v_internal",
"dc_plan_steps": "v_internal",
}

@staticmethod
Expand Down Expand Up @@ -2881,13 +2883,14 @@ def _get_metric_val(self) -> tuple:
title="Getting the metrics for each operator.",
method="fetchall",
)
res = self._get_ool_metric(res)
metric_value_op = {}
for me in res:
if me[0] not in metric_value_op:
metric_value_op[me[0]] = {}
if me[2] not in metric_value_op[me[0]]:
metric_value_op[me[0]][me[2]] = {}
for idx, col in enumerate(cols):
for idx, col in enumerate(cols + ["ool"]):
current_metric = me[3 + idx]
if not isinstance(current_metric, NoneType):
if current_metric == int(current_metric):
Expand All @@ -2897,7 +2900,6 @@ def _get_metric_val(self) -> tuple:
else:
current_metric = -1
metric_value_op[me[0]][me[2]][col] = current_metric

# Summary.
query = self.get_qexecution_report(granularity=2, genSQL=True)
res = _executeSQL(
Expand Down Expand Up @@ -2926,6 +2928,59 @@ def _get_metric_val(self) -> tuple:
# Returning the metric.
return metric_value_op, metric_value

def _get_ool_metric(self, list_of_metrics):
for i, data in enumerate(list_of_metrics):
path_id = data[0]
baseplan_id = data[1]
operator = data[2]

query = f"""
SELECT
ps.path_id,
ps.baseplan_id,
ps.step_type AS operator_name,
MAX(CASE WHEN LOWER(pp.property_name) LIKE '%ool%' THEN 1 ELSE 0 END) AS has_ool
FROM
v_internal.dc_plan_step_properties pp
JOIN
v_internal.dc_plan_steps ps
ON
pp.transaction_id = ps.transaction_id AND
pp.statement_id = ps.statement_id AND
pp.plan_id = ps.plan_id AND
pp.step_key = ps.step_key AND
pp.node_name = ps.node_name
WHERE
pp.transaction_id = {self.transaction_id} AND
pp.statement_id = {self.statement_id} AND
ps.path_id = {path_id} AND
ps.baseplan_id = {baseplan_id} AND
ps.step_type = '{operator}'
GROUP BY
ps.path_id,
ps.baseplan_id,
ps.step_type
ORDER BY
ps.path_id,
ps.baseplan_id,
ps.step_type;
"""
query = self._replace_schema_in_query(query)
try:
res = _executeSQL(
query,
title="Getting the corresponding query",
method="fetchall",
)
if res:
list_of_metrics[i].append(res[0][3])
else:
list_of_metrics[i].append(None)
except:
res = []

return list_of_metrics

def _get_all_op(self) -> list[str]:
"""
Returns the input ``transaction``
Expand Down
1 change: 1 addition & 0 deletions verticapy/performance/vertica/qprof_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def _get_metrics_name(metric: str, inv: bool = False) -> str:
"rows_processed_sip": "Rows processed by SIPs expression",
"total_rows_read_join_sort": "Total rows read in join sort",
"total_rows_read_sort": "Total rows read in sort",
"ool": "Produces variable length data",
}
if inv:
look_up_table_inv = {v: k for k, v in look_up_table.items()}
Expand Down
8 changes: 7 additions & 1 deletion verticapy/performance/vertica/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ def _set_style(self, d: dict) -> None:
"proc_rows",
"prod_rows",
"thread_count",
"ool",
]
self.style = d

Expand Down Expand Up @@ -722,7 +723,12 @@ def _format_metrics(self, path_id: int) -> str:
else:
me_val_str = format(round(me_val_str, 3), ",")
metric_name = QprofUtility._get_metrics_name(me)
info += f" - {metric_name}: {me_val_str}\n"
if not (me == "ool" and (me_val_str != "1")):
# Skipping if ool is not True
if me == "ool" and me_val_str == "1":
info += f" - {metric_name}: True\n"
else:
info += f" - {metric_name}: {me_val_str}\n"
if len(info) > 0 and info[-1] == "\n":
info = info[:-1]
return info
Expand Down

0 comments on commit 7602452

Please sign in to comment.