Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryProfilerComparison #295

Merged
merged 6 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
260 changes: 211 additions & 49 deletions project/ui/qprof-ui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@
"import plotly.graph_objects as go\n",
"from collections import defaultdict, Counter\n",
"import textwrap\n",
"from verticapy.performance.vertica import QueryProfilerInterface, QueryProfiler\n",
"from verticapy.performance.vertica import QueryProfilerInterface, QueryProfiler, QueryProfilerComparison\n",
"logging.info('[Query Profile Tree Page] Successfully Imported Libraries ')\n",
"output_initial = widgets.Output()\n",
"global qprof\n",
"global qprof2\n",
"comparison = False\n",
"with output_initial:\n",
" %store -r query_val\n",
" %store -r key_val\n",
Expand All @@ -98,6 +99,19 @@
" %store -r key_val_2\n",
" %store -r transaction_statement_list_val\n",
" %store -r control_query_val\n",
" %store -r transaction_comp1_val\n",
" %store -r statement_comp1_val\n",
" %store -r target_schema_comp1_val\n",
" %store -r key_comp1_val\n",
" %store -r query_comp1_val\n",
" %store -r session_control_1_val\n",
" %store -r transaction_comp2_val\n",
" %store -r statement_comp2_val\n",
" %store -r target_schema_comp2_val\n",
" %store -r key_comp2_val\n",
" %store -r query_comp2_val\n",
" %store -r session_control_2_val\n",
"\n",
" if \"file_val\" in globals():\n",
" if not \"key_val\" in globals():\n",
" characters = string.ascii_letters + string.digits # includes 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'\n",
Expand Down Expand Up @@ -145,7 +159,46 @@
" target_schema = target_schema_val_2 if \"target_schema_val_2\" in globals() else None,\n",
" key_id = key_val_2 if \"key_val_2\" in globals() else None,\n",
" check_tables = False,\n",
" )\n"
" )\n",
"\n",
" else:\n",
" comparison = True\n",
" if \"transaction_comp1_val\" in globals():\n",
" qprof1 = QueryProfilerInterface(\n",
" transactions = (eval(transaction_comp1_val),eval(statement_comp1_val)),\n",
" check_tables = False,\n",
" )\n",
" elif \"target_schema_comp1_val\" in globals():\n",
" qprof1 = QueryProfilerInterface(\n",
" target_schema = target_schema_comp1_val,\n",
" key_id = key_comp1_val,\n",
" check_tables = False,\n",
" )\n",
" elif \"query_comp1_val\" in globals():\n",
" qprof1 = QueryProfilerInterface(\n",
" query_comp1_val,\n",
" check_tables = False,\n",
" session_control = session_control_1_val if \"session_control_1_val\" in globals() else None,\n",
" )\n",
" if \"transaction_comp2_val\" in globals(): # Changed from transaction_comp1_val to transaction_comp2_val\n",
" qprof2 = QueryProfilerInterface( # Changed from qprof1 to qprof2\n",
" transactions = (eval(transaction_comp2_val),eval(statement_comp2_val)), # Changed from transaction_comp1_val to transaction_comp2_val\n",
" check_tables = False,\n",
" )\n",
" elif \"target_schema_comp2_val\" in globals(): # Changed from target_schema_comp1_val to target_schema_comp2_val\n",
" qprof2 = QueryProfilerInterface( # Changed from qprof1 to qprof2\n",
" target_schema = target_schema_comp2_val, # Changed from target_schema_comp1_val to target_schema_comp2_val\n",
" key_id = key_comp2_val, # Changed from key_comp1_val to key_comp2_val\n",
" check_tables = False,\n",
" )\n",
" elif \"query_comp2_val\" in globals(): # Changed from query_comp1_val to query_comp2_val\n",
" qprof2 = QueryProfilerInterface( # Changed from qprof1 to qprof2\n",
" query_comp2_val, # Changed from query_comp1_val to query_comp2_val\n",
" check_tables = False,\n",
" session_control = session_control_2_val if \"session_control_2_val\" in globals() else None, # Changed from session_control_1_val to session_control_2_val\n",
" )\n",
" qprof_comparison = QueryProfilerComparison(qprof1, qprof2)\n",
" "
]
},
{
Expand Down Expand Up @@ -334,6 +387,8 @@
"outputs": [],
"source": [
"top_accordion = widgets.Accordion(children=[qprof_save], titles=('Downloads',))\n",
"if comparison:\n",
" button_qprof_save.disabled = True\n",
"display(top_accordion)"
]
},
Expand Down Expand Up @@ -1329,6 +1384,41 @@
" drop_down_query_select = widgets.HTML(f\"<p style='color:red'>The following error occured: </p> <p> {e}</p>\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "57dec0ac-048c-400a-a0fa-32347a2f6982",
"metadata": {},
"outputs": [],
"source": [
"# Info/Warning Box\n",
"import ipywidgets as widgets\n",
"\n",
"def show_notification():\n",
" close_button = widgets.Button(\n",
" description=\"x\",\n",
" button_style=\"danger\",\n",
" layout={'width': '30px', 'height': '30px', 'margin': '0 0 0 10px'}\n",
" )\n",
"\n",
" def close_notification(_):\n",
" notification.close()\n",
" close_button.close()\n",
"\n",
" close_button.on_click(close_notification)\n",
"\n",
" notification = widgets.HTML(\n",
" value=\"<div style='background-color: #ffc107; padding: 10px; border-radius: 5px; display: flex; align-items: center;'>\"\n",
" \"<strong>Important:</strong>&nbsp;If you do not see the trees, please click on the tab 'Tree Style' and then click on 'Apply'. This will refresh the tree.\"\n",
" \"</div>\",\n",
" layout={'margin': '10px 0'}\n",
" )\n",
"\n",
" display(widgets.HBox([notification, close_button]))\n",
"\n",
"show_notification()"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -1340,7 +1430,10 @@
"\n",
"with output_tree:\n",
" logging.info(f'[Query Profile Tree Page] Trying to display the tree')\n",
" qprof.get_qplan_tree()\n",
" if comparison:\n",
" qprof_comparison.display()\n",
" else:\n",
" qprof.get_qplan_tree()\n",
" logging.info(f'[Query Profile Tree Page] Finished trying to display the tree')\n",
" \n",
"tabs = widgets.Tab()\n",
Expand All @@ -1351,19 +1444,22 @@
"child_4 = widgets.VBox([button_get_queries, output_get_queries])\n",
"child_5 = widgets.VBox([plot_tabs_main])\n",
"child_6 = widgets.VBox([other_info])\n",
"\n",
"tabs.children = [child_1, \n",
" child_2, \n",
" child_3, \n",
" child_4, \n",
" child_5, \n",
" child_6]\n",
"tabs.titles = [\"Tree\", \n",
" \"Query Events\", \n",
" \"Query Engine\", \n",
" \"Transaction List\", \n",
" \"Plots\",\n",
" \"Other info\"]\n",
"if comparison:\n",
" tabs.children = [child_1]\n",
" tabs.titles = [\"Tree\"]\n",
"else:\n",
" tabs.children = [child_1, \n",
" child_2, \n",
" child_3, \n",
" child_4, \n",
" child_5, \n",
" child_6]\n",
" tabs.titles = [\"Tree\", \n",
" \"Query Events\", \n",
" \"Query Engine\", \n",
" \"Transaction List\", \n",
" \"Plots\",\n",
" \"Other info\"]\n",
"\n",
"# Define the observer function\n",
"def on_tab_change(change):\n",
Expand Down Expand Up @@ -1543,41 +1639,103 @@
},
"outputs": [],
"source": [
"button_run_explain_plan = widgets.Button(description=\"Run Explain Plan\")\n",
"explain_output = widgets.Output()\n",
"try:\n",
" explain_dropdown_options = [i for i in range(len(qprof.transactions))]\n",
" explain_dropdown_disabled = False\n",
"except Exception as e:\n",
" explain_dropdown_options = []\n",
" explain_dropdown_disabled = True\n",
"if comparison:\n",
" button_run_explain_plan_1 = widgets.Button(description=\"Run Explain Plan\")\n",
" explain_output_1 = widgets.Output()\n",
" try:\n",
" explain_dropdown_options_1 = [i for i in range(len(qprof1.transactions))]\n",
" explain_dropdown_disabled_1 = False\n",
" except Exception as e:\n",
" explain_dropdown_options_1 = []\n",
" explain_dropdown_disabled_1 = True\n",
" \n",
" explain_dropdown_1 = widgets.Dropdown(\n",
" options=explain_dropdown_options_1,\n",
" description='Select Query Index',\n",
" disabled=explain_dropdown_disabled_1,\n",
" layout={'width': \"300px\"}\n",
" )\n",
" explain_dropdown_1.style.description_width = '130px'\n",
" \n",
"explain_dropdown = widgets.Dropdown(\n",
" options=explain_dropdown_options,\n",
" description='Select Query Index',\n",
" disabled=explain_dropdown_disabled,\n",
" layout={'width': \"300px\"}\n",
")\n",
"explain_dropdown.style.description_width = '130px'\n",
"\n",
"def on_button_clicked_run_explain_plan(b):\n",
" explain_output.clear_output()\n",
" with explain_output:\n",
" qprof.set_position(explain_dropdown.value)\n",
" qprof.get_qplan_explain()\n",
"\n",
" def on_button_clicked_run_explain_plan_1(b):\n",
" explain_output_1.clear_output()\n",
" with explain_output_1:\n",
" qprof1.set_position(explain_dropdown_1.value)\n",
" qprof1.get_qplan_explain()\n",
"\n",
"def on_button_clicked_run_query(b):\n",
" output_run_query.clear_output(wait=True)\n",
" global query_val, target_schema_val_2, key_val_2\n",
" with output_run_query:\n",
" query_val = query.value\n",
" logging.info(f\"\"\"[Query Profile Tree Page] Running the following custom query requested by the user :{query_val}.\"\"\")\n",
" run_query_result = vp.vDataFrame(query_val)\n",
" display(widgets.HTML(run_query_result._repr_html_()))\n",
" button_run_explain_plan_1.on_click(on_button_clicked_run_explain_plan_1)\n",
" \n",
" button_run_explain_plan_2 = widgets.Button(description=\"Run Explain Plan\")\n",
" explain_output_2 = widgets.Output()\n",
" try:\n",
" explain_dropdown_options_2 = [i for i in range(len(qprof2.transactions))]\n",
" explain_dropdown_disabled_2 = False\n",
" except Exception as e:\n",
" explain_dropdown_options_2 = []\n",
" explain_dropdown_disabled_2 = True\n",
" \n",
" explain_dropdown_2 = widgets.Dropdown(\n",
" options=explain_dropdown_options_2,\n",
" description='Select Query Index',\n",
" disabled=explain_dropdown_disabled_2, # Updated to use explain_dropdown_disabled_2\n",
" layout={'width': \"300px\"}\n",
" )\n",
" explain_dropdown_2.style.description_width = '130px'\n",
" \n",
" def on_button_clicked_run_explain_plan_2(b):\n",
" explain_output_2.clear_output()\n",
" with explain_output_2:\n",
" qprof2.set_position(explain_dropdown_2.value)\n",
" qprof2.get_qplan_explain()\n",
" \n",
" button_run_explain_plan_2.on_click(on_button_clicked_run_explain_plan_2)\n",
" left_side = widgets.VBox([explain_dropdown_1, button_run_explain_plan_1, explain_output_1])\n",
" left_side.layout.width = '50%'\n",
" right_side = widgets.VBox([explain_dropdown_2, button_run_explain_plan_2, explain_output_2])\n",
" right_side.layout.width = '50%'\n",
"\n",
"button_run_explain_plan.on_click(on_button_clicked_run_explain_plan)\n",
"explain_plan_widget = widgets.VBox([explain_dropdown, button_run_explain_plan, explain_output]) "
" vertica_border_line = widgets.HTML(\"\"\"\n",
" <style>\n",
" .vertical-line {\n",
" border-left: 2px solid lightgrey; /* Adjust thickness and color as needed */\n",
" height: 500px; /* Adjust height as needed */\n",
" }\n",
" </style>\n",
" </head>\n",
" <body>\n",
" \n",
" <div class=\"vertical-line\"></div>\n",
" \n",
" </body>\n",
" \"\"\") \n",
" explain_plan_widget = widgets.HBox([left_side,vertica_border_line, right_side])\n",
"else:\n",
" button_run_explain_plan = widgets.Button(description=\"Run Explain Plan\")\n",
" explain_output = widgets.Output()\n",
" try:\n",
" explain_dropdown_options = [i for i in range(len(qprof.transactions))]\n",
" explain_dropdown_disabled = False\n",
" except Exception as e:\n",
" explain_dropdown_options = []\n",
" explain_dropdown_disabled = True\n",
" \n",
" explain_dropdown = widgets.Dropdown(\n",
" options=explain_dropdown_options,\n",
" description='Select Query Index',\n",
" disabled=explain_dropdown_disabled,\n",
" layout={'width': \"300px\"}\n",
" )\n",
" explain_dropdown.style.description_width = '130px'\n",
" \n",
" def on_button_clicked_run_explain_plan(b):\n",
" explain_output.clear_output()\n",
" with explain_output:\n",
" qprof.set_position(explain_dropdown.value)\n",
" qprof.get_qplan_explain()\n",
" \n",
" button_run_explain_plan.on_click(on_button_clicked_run_explain_plan)\n",
" explain_plan_widget = widgets.VBox([explain_dropdown, button_run_explain_plan, explain_output]) \n",
" "
]
},
{
Expand All @@ -1595,7 +1753,11 @@
" consistency_check_out.clear_output(wait=True)\n",
" with consistency_check_out:\n",
" try:\n",
" qprof._check_v_table(ignore_operators_check=False)\n",
" if comparison:\n",
" qprof1._check_v_table(ignore_operators_check=False)\n",
" qprof2._check_v_table(ignore_operators_check=False)\n",
" else:\n",
" qprof._check_v_table(ignore_operators_check=False)\n",
" except Exception as e:\n",
" print(e)\n",
" consistency_check_button.disabled = False\n",
Expand Down
Loading
Loading