vertica / VerticaPy

VerticaPy is a Python library that exposes sci-kit like functionality to conduct data science projects on data stored in Vertica, thus taking advantage Vertica’s speed and built-in analytics and machine learning capabilities.
https://www.vertica.com/python/
Apache License 2.0
219 stars 45 forks source link

QueryProfiler - get_qplan_tree does not work for short queries with one line of query plan #1155

Closed mail4umar closed 7 months ago

mail4umar commented 7 months ago

What is the requested change?

Below is the reproducer:

from verticapy.performance.vertica import QueryProfilerInterface
qprof = QueryProfilerInterface(
    "SELECT * from public.titanic"
)
qprof.get_qplan_tree()

Error:

---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
File /usr/local/lib/python3.12/site-packages/ipywidgets/widgets/interaction.py:66, in interactive_output.<locals>.observer(change)
     64 with out:
     65     clear_output(wait=True)
---> 66     f(**kwargs)
     67     show_inline_matplotlib_plots()

File /usr/local/lib/python3.12/site-packages/verticapy/performance/vertica/qprof_interface.py:211, in QueryProfilerInterface.update_qplan_tree(self, metric, index, path_id, apply_tree_clicked)
    209     display(box)
    210 else:
--> 211     raw = super().get_qplan_tree(
    212         metric=metric,
    213         path_id=path_id,
    214         return_graphviz=True,
    215         color_low=self.tree_style["color_low"],
    216         color_high=self.tree_style["color_high"],
    217     )
    218     output = read_package_file("html/index.html")
    219     output = replace_value(output, "var dotSrc = [];", f"var dotSrc = `{raw}`;")

File /usr/local/lib/python3.12/site-packages/verticapy/performance/vertica/qprof.py:2368, in QueryProfiler.get_qplan_tree(self, path_id, path_id_info, show_ancestors, metric, pic_path, return_graphviz, **tree_style)
   2358 obj = PerformanceTree(
   2359     rows,
   2360     show_ancestors=show_ancestors,
   (...)
   2365     style=tree_style,
   2366 )
   2367 if return_graphviz:
-> 2368     return obj.to_graphviz()
   2369 return obj.plot_tree(pic_path)

File /usr/local/lib/python3.12/site-packages/verticapy/performance/vertica/tree.py:1402, in PerformanceTree.to_graphviz(self)
   1400 else:
   1401     res += "\n"
-> 1402 res += self._gen_labels() + "\n"
   1403 res += self._gen_links() + "\n"
   1404 res += "}"

File /usr/local/lib/python3.12/site-packages/verticapy/performance/vertica/tree.py:1158, in PerformanceTree._gen_labels(self)
   1156 operator_icon = self._get_operator_icon(row)
   1157 if not (isinstance(self.metric[0], NoneType)):
-> 1158     alpha = (all_metrics[i] - m_min) / (m_max - m_min)
   1159     color = self._generate_gradient_color(alpha)
   1160 else:

ZeroDivisionError: float division by zero