Skip to content

Commit

Permalink
[QPROF] New static method. (#1284)
Browse files Browse the repository at this point in the history
- New static method to compare two dictionaries.
 - Renaming ambiguous attributes.
  • Loading branch information
oualib authored Sep 26, 2024
1 parent e397408 commit f372d4c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 21 deletions.
4 changes: 2 additions & 2 deletions verticapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
__url__: str = "https://github.com/vertica/verticapy/"
__license__: str = "Apache License, Version 2.0"
__version__: str = "1.0.5"
__iteration__: int = 2
__date__: str = "25092024"
__iteration__: int = 1
__date__: str = "26092024"
__last_commit__: str = "845f1130772d54ecd184f71f57c92b76ed4b1628"
__long_version__: str = f"{__version__}-{__iteration__}{__date__}-{__last_commit__}"
__codecov__: float = 0.84
Expand Down
50 changes: 31 additions & 19 deletions verticapy/performance/vertica/qprof.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ class QueryProfiler:
Current Transaction ID.
statement_id: int
Current Statement ID.
session_params_current: dict
Current Session Parameters.
session_params_non_default_current: dict
Non Default Session Parameters used
to run the current/active query.
target_schema: dict
Name of the schema used to store
all the Vertica monitor and internal
Expand All @@ -241,9 +242,10 @@ class QueryProfiler:
tables_dtypes: list
Datatypes of all the loaded
performance tables.
session_params: list
Non Default Session Parameters used
to run the transactions.
session_params_non_default: list
``list`` of Non Default Session
Parameters used all the queries
that are profiled.
overwrite: bool
If set to ``True`` overwrites the
existing performance tables.
Expand Down Expand Up @@ -1151,7 +1153,7 @@ def __init__(
session_control_loop = session_control_loop[1:]

session_control_loop_all = []
session_params = []
session_params_non_default = []

for sc in session_control_loop:
if sc not in ({}, ""):
Expand Down Expand Up @@ -1209,10 +1211,12 @@ def __init__(
" will be skipped."
)
warnings.warn(warning_message, Warning)
session_params += [self._get_current_session_params()]
session_params_non_default += [
self._get_current_session_params_non_default()
]

self.session_control_params = session_control_loop_all
self.session_params = session_params
self.session_params_non_default = session_params_non_default

if len(self.transactions) == 0 and isinstance(key_id, NoneType):
raise ValueError("No transactions found.")
Expand Down Expand Up @@ -1261,17 +1265,19 @@ def __init__(
)

# CORRECTING WRONG ATTRIBUTES
if not (hasattr(self, "session_params")) or not (self.session_params):
self.session_params = [{} for x in self.transactions]
if not (hasattr(self, "session_params_non_default")) or not (
self.session_params_non_default
):
self.session_params_non_default = [{} for x in self.transactions]
try:
self.session_params_current = self.session_params[0]
self.session_params_non_default_current = self.session_params_non_default[0]
except:
self.session_params_current = {}
self.session_params_non_default_current = {}

# Tools

@staticmethod
def _get_current_session_params():
def _get_current_session_params_non_default():
"""
Returns a ``dict`` of the current
session parameters.
Expand Down Expand Up @@ -2063,9 +2069,11 @@ def set_position(self, idx: Union[int, tuple]) -> None:
self.qduration = self.qdurations[idx]
self.query_success = self.query_successes[idx]
try:
self.session_params_current = self.session_params[idx]
self.session_params_non_default_current = (
self.session_params_non_default[idx]
)
except:
self.session_params_current = {}
self.session_params_non_default_current = {}
else:
raise TypeError(
"Wrong type for parameter 'idx'. Expecting: int or tuple."
Expand All @@ -2090,9 +2098,11 @@ def next(self) -> None:
self.request = self.requests[idx]
self.qduration = self.qdurations[idx]
try:
self.session_params_current = self.session_params[idx]
self.session_params_non_default_current = self.session_params_non_default[
idx
]
except:
self.session_params_current = {}
self.session_params_non_default_current = {}

def previous(self) -> None:
"""
Expand All @@ -2112,9 +2122,11 @@ def previous(self) -> None:
self.request = self.requests[idx]
self.qduration = self.qdurations[idx]
try:
self.session_params_current = self.session_params[idx]
self.session_params_non_default_current = self.session_params_non_default[
idx
]
except:
self.session_params_current = {}
self.session_params_non_default_current = {}

# Main Method

Expand Down
39 changes: 39 additions & 0 deletions verticapy/performance/vertica/qprof_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,45 @@ def get_tree_elements(qprof1: ..., qprof2: ..., **qplan_tree_params) -> ...:

# Utils

@staticmethod
def dict_diff(dict1: dict, dict2: dict) -> dict:
"""
Returns a ``dict`` of the
differences between two
dictionaries.
Parameters
----------
dict1: dict
First ``dict``
dict2: dict
Second ``dict``.
Returns
-------
dict
``dict`` including the
differences.
Examples
--------
See :py:meth:`~verticapy.performance.vertica.qprof_utility`
for more information.
"""
diff = {}

# Check for keys in dict1 that are different or not in dict2
for key in dict1:
if key not in dict2 or dict1[key] != dict2[key]:
diff[key] = dict1[key]

# Check for keys in dict2 that are not in dict1
for key in dict2:
if key not in dict1:
diff[key] = dict2[key]

return diff

@staticmethod
def _get_label(
row: str, return_path_id: bool = True, row_idx: int = 0
Expand Down

0 comments on commit f372d4c

Please sign in to comment.