Skip to content

Commit

Permalink
[QPROF] Filtering by operator. (#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
oualib authored Sep 26, 2024
1 parent f372d4c commit 10d042b
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
2 changes: 1 addition & 1 deletion verticapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
__url__: str = "https://github.com/vertica/verticapy/"
__license__: str = "Apache License, Version 2.0"
__version__: str = "1.0.5"
__iteration__: int = 1
__iteration__: int = 2
__date__: str = "26092024"
__last_commit__: str = "845f1130772d54ecd184f71f57c92b76ed4b1628"
__long_version__: str = f"{__version__}-{__iteration__}{__date__}-{__last_commit__}"
Expand Down
10 changes: 10 additions & 0 deletions verticapy/performance/vertica/qprof.py
Original file line number Diff line number Diff line change
Expand Up @@ -3305,6 +3305,16 @@ def get_qplan_tree(
of the corresponding
``path_id`` will be used.
Default: None
- op_filter:
``list`` of operators used
to disable some specific
``path_id``. If the ``path_id``
does not include all the
operators of the ``op_filter``
list: A minimalist representation
of the corresponding ``path_id``
will be used.
Default: None
- fontcolor:
Font color.
Default (light-m): #000000 (black)
Expand Down
72 changes: 70 additions & 2 deletions verticapy/performance/vertica/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ def _set_style(self, d: dict) -> None:
d["threshold_metric1"] = None
if "threshold_metric2" not in d:
d["threshold_metric2"] = None
if "op_filter" not in d:
d["op_filter"] = None
if "display_path_transition" not in d:
d["display_path_transition"] = True
if "display_annotations" not in d:
Expand Down Expand Up @@ -706,6 +708,69 @@ def _format_metrics(self, path_id: int) -> str:
return info
return ""

def _get_operators_path_id(self, path_id: Union[str, int]) -> list:
"""
Returns the ``list``
of operators for a
specific ``path_id``.
Parameters
----------
path_id: str | int
PATH ID.
Returns
-------
list
All the ``path_id`` operators.
Examples
--------
See :py:meth:`~verticapy.performance.vertica.tree`
for more information.
"""
try:
path_id = int(path_id)
except:
pass
if path_id in self.metric_value_op:
return [op for op in self.metric_value_op[path_id]]
return []

def _is_op_in_path_id(self, path_id: Union[str, int]) -> bool:
"""
Returns the ``True``
if all the input
``path_id`` operators
are in the ``op_filter``
``list``.
Parameters
----------
path_id: str | int
PATH ID.
Returns
-------
bool
Result of the
comparaison.
Examples
--------
See :py:meth:`~verticapy.performance.vertica.tree`
for more information.
"""
op_filter = self.style["op_filter"]
if not (op_filter):
return True
path_id_op = self._get_operators_path_id(path_id)
path_id_op = [str(op).lower().strip() for op in path_id_op]
for op in op_filter:
if str(op).lower().strip() not in path_id_op:
return False
return True

# DML: Target Projections

def _get_target_projection(self, row: str) -> list[str]:
Expand Down Expand Up @@ -1526,8 +1591,11 @@ def _gen_label_table(
if isinstance(metric_2, NoneType) or metric_2 < metric_2_t:
display_path_id = False

# Filter based on the operator.
filter_op = self._is_op_in_path_id(label)

# Special Display.
if not (display_path_id):
if not (display_path_id) or not (filter_op):
return (
'<<TABLE border="1" cellborder="1" cellspacing="0" '
f'cellpadding="0"><TR><TD WIDTH="{width * 2}" '
Expand Down Expand Up @@ -1790,7 +1858,7 @@ def _gen_labels(self) -> str:
if ns_icon != "":
ns_icon += " "
ns_icon += QprofUtility._get_execute_on(tooltip)
if not (display_path_id):
if not (display_path_id) or not (self._is_op_in_path_id(label)):
ns_icon = ""
# Final Tooltip.
description = "\n\nDescriptors\n------------\n" + "\n".join(
Expand Down

0 comments on commit 10d042b

Please sign in to comment.