Skip to content

Commit

Permalink
Merge pull request #256 from vertica/query_profiler_upgrade_3
Browse files Browse the repository at this point in the history
QueryProfiler Tree UI - Added another tab for other useful DC tables
  • Loading branch information
mail4umar authored May 14, 2024
2 parents cbdc018 + 1eea5ae commit a2a7311
Showing 1 changed file with 86 additions and 2 deletions.
88 changes: 86 additions & 2 deletions project/ui/qprof-ui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"logging.info('[Query Profile Tree Page] Importing Libraries')\n",
"import pickle\n",
"import ipywidgets as widgets\n",
"import verticapy as vp\n",
"from verticapy.performance.vertica import QueryProfilerInterface, QueryProfiler\n",
"logging.info('[Query Profile Tree Page] Successfully Imported Libraries ')\n",
"output_initial = widgets.Output()\n",
Expand Down Expand Up @@ -255,6 +256,44 @@
"logging.info(f'[Query Profile Tree Page] Completed the script to automatically display the tree')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1f25ec1d-b2fa-404b-95d0-cddb86456456",
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" transaction_statement_list = qprof.transactions\n",
" logging.info(f'[Query Profile Tree Page] The list of transaction and statement ids are: {transaction_statement_list}')\n",
" # Construct the WHERE clause dynamically\n",
" where_clause = \" OR \".join([f\"(transaction_id = {elem[0]} AND statement_id = {elem[1]})\" for elem in transaction_statement_list])\n",
" \n",
" # Construct the query\n",
" query = f\"\"\"\n",
" SELECT transaction_id, statement_id, node_name, event_description, time, duration_us/1000000 AS duration_sec\n",
" FROM dc_slow_events\n",
" WHERE {where_clause}\n",
" ORDER BY duration_sec DESC\n",
" LIMIT 500;\n",
" \"\"\"\n",
" query_2 = f\"\"\"\n",
" SELECT *\n",
" FROM dc_optimizer_events\n",
" WHERE {where_clause};\n",
" \"\"\"\n",
" logging.info(f'[Query Profile Tree Page] Trying to get the DC SLOW EVENTS table')\n",
" res_1 = vp.vDataFrame(f\"\"\"{query}\"\"\")\n",
" res_2 = vp.vDataFrame(f\"\"\"{query_2}\"\"\")\n",
" table_1 = widgets.VBox([widgets.HTML(res_1._repr_html_())])\n",
" table_2 = widgets.VBox([widgets.HTML(res_2._repr_html_())])\n",
" tables = widgets.Tab()\n",
" tables.children = [table_1, table_2]\n",
" tables.titles = [\"Slow Events\", \"Optimimzer Events\"]\n",
"except Exception as e:\n",
" tables = widgets.VBox([widgets.HTML(f\"<p style='color:red'>The following error occured: </p> <p> {e}</p>\")])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -268,7 +307,52 @@
" logging.info(f'[Query Profile Tree Page] Trying to display the tree')\n",
" qprof.get_qplan_tree()\n",
" logging.info(f'[Query Profile Tree Page] Finished trying to display the tree')\n",
"display(output_tree)"
" \n",
"tabs = widgets.Tab()\n",
"\n",
"child_1 = widgets.VBox([output_tree])\n",
"child_2 = widgets.VBox([tables])\n",
"tabs.children = [child_1, child_2]\n",
"tabs.titles = [\"Tree\", \"Other info\"]\n",
"display(tabs)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9b4c74d6-b45e-42aa-b361-0605705587ed",
"metadata": {},
"outputs": [],
"source": [
"query = widgets.Textarea(\n",
" placeholder='Enter a SQL Query',\n",
" description='SQL Query:',\n",
" disabled=False,\n",
" layout=widgets.Layout(width='700px')\n",
")\n",
"button_run_query = widgets.Button(description=\"Run Query\")\n",
"output_run_query = widgets.Output()\n",
"query_val = None\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 query manually :{query_val}.\"\"\")\n",
" run_query_result = vp.vDataFrame(query_val)\n",
" display(widgets.HTML(run_query_result._repr_html_()))\n",
"\n",
"button_run_query.on_click(on_button_clicked_run_query)\n",
"manual_query = widgets.VBox([query, button_run_query, output_run_query])\n"
]
},
{
"cell_type": "markdown",
"id": "3c2d8946-e27e-47e5-a81b-42f142cbeb1b",
"metadata": {},
"source": [
"______"
]
},
{
Expand All @@ -278,7 +362,7 @@
"metadata": {},
"outputs": [],
"source": [
"accordion = widgets.Accordion(children=[output_initial], titles=('Execution/Error Details',))\n",
"accordion = widgets.Accordion(children=[manual_query, output_initial], titles=('Manual Queries','Execution/Error Details',))\n",
"logging.info(f'[Query Profile Tree Page] Trying to display the error log at the bottom of the page')\n",
"accordion\n"
]
Expand Down

0 comments on commit a2a7311

Please sign in to comment.