From 10d042becc3b18ab4cbc075fa38e942bac24be44 Mon Sep 17 00:00:00 2001 From: Badr Ouali <32390048+oualib@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:00:11 -0400 Subject: [PATCH] [QPROF] Filtering by operator. (#1285) Should close: - https://jira.verticacorp.com/jira/browse/VER-97042?filter=-1 --- verticapy/__init__.py | 2 +- verticapy/performance/vertica/qprof.py | 10 ++++ verticapy/performance/vertica/tree.py | 72 +++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/verticapy/__init__.py b/verticapy/__init__.py index 26cfc8bff..33b2e9e9f 100755 --- a/verticapy/__init__.py +++ b/verticapy/__init__.py @@ -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__}" diff --git a/verticapy/performance/vertica/qprof.py b/verticapy/performance/vertica/qprof.py index 2892b026d..2731d97e2 100755 --- a/verticapy/performance/vertica/qprof.py +++ b/verticapy/performance/vertica/qprof.py @@ -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) diff --git a/verticapy/performance/vertica/tree.py b/verticapy/performance/vertica/tree.py index 15e8e5205..f2c7fae4b 100644 --- a/verticapy/performance/vertica/tree.py +++ b/verticapy/performance/vertica/tree.py @@ -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: @@ -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]: @@ -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 ( '<
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( |