From 1d0362b9e645804d4353972c6deb7325d1e747ec Mon Sep 17 00:00:00 2001 From: Umar Farooq Ghumman Date: Tue, 21 May 2024 11:08:13 -0500 Subject: [PATCH 1/2] Added features to Query Profiler Tree Page - Added a tab for transactions - Added option to download query report --- project/ui/qprof-ui.ipynb | 242 +++++++++++++++++++++++++++++++++----- 1 file changed, 215 insertions(+), 27 deletions(-) diff --git a/project/ui/qprof-ui.ipynb b/project/ui/qprof-ui.ipynb index 4b2a50f4..59496575 100644 --- a/project/ui/qprof-ui.ipynb +++ b/project/ui/qprof-ui.ipynb @@ -2,10 +2,25 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "c7fde2aa-9a00-43b2-8e83-dc89087fa142", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "0db0b48039f44b8998eb9d73e1748b64", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(HTML(value=\"{js_code}'))\n", + "\n", + "download_report_output = widgets.Output()\n", + "btn_report = Button(description='Click to download')\n", + "\n", + "def download_html(e=None):\n", + " # Define the HTML content\n", + " html_content = \"\"\"\n", + " \n", + " \n", + " \n", + " Sample HTML Page\n", + " \n", + " \n", + "

Hello, World!

\n", + "

This is a sample HTML page.

\n", + " \n", + " \n", + " \"\"\"\n", + " html_data = html_content.encode('utf-8')\n", + " trigger_download_report(html_data, 'sample.html')\n", + "\n", + "btn_report.on_click(download_html)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, "id": "da8af3a2-0c8c-4a82-a6ef-5edb15d53f72", "metadata": {}, "outputs": [], @@ -208,19 +278,62 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "47599ae0-6ffa-41d9-b16a-f346b3f52d72", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "0dea3cf917c74eb6875751a50fc4bcf2", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(HTML(value=\"
\n", + "\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "display(HTML(html_code))\n", "logging.info(f'[Query Profile Tree Page] Completed the script to automatically display the tree')" @@ -258,7 +398,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "1f25ec1d-b2fa-404b-95d0-cddb86456456", "metadata": {}, "outputs": [], @@ -290,16 +430,38 @@ " tables = widgets.Tab()\n", " tables.children = [table_1, table_2]\n", " tables.titles = [\"Slow Events\", \"Optimimzer Events\"]\n", + "\n", + "except Exception as e:\n", + " tables = widgets.VBox([widgets.HTML(f\"

The following error occured:

{e}

\")])\n", + "\n", + "try:\n", + " transactions_table = qprof.get_queries()\n", + " transactions_table = widgets.VBox([widgets.HTML(transactions_table._repr_html_())])\n", "except Exception as e:\n", - " tables = widgets.VBox([widgets.HTML(f\"

The following error occured:

{e}

\")])\n" + " transactions_table = widgets.VBox([widgets.HTML(f\"

The following error occured:

{e}

\")])" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "7e5b38a8-79dd-45b2-85de-6be16c74206f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "d63edd00d6f645c591e779ffdda312ff", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Tab(children=(VBox(children=(Output(),)), VBox(children=(VBox(children=(HTML(value=\"

The f…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "output_tree = widgets.Output()\n", "\n", @@ -311,15 +473,17 @@ "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", + "child_2 = widgets.VBox([transactions_table])\n", + "child_3 = widgets.VBox([tables])\n", + "\n", + "tabs.children = [child_1, child_2, child_3]\n", + "tabs.titles = [\"Tree\", \"Transaction\", \"Other info\"]\n", "display(tabs)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "9b4c74d6-b45e-42aa-b361-0605705587ed", "metadata": {}, "outputs": [], @@ -357,15 +521,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "32cf2caa-2a1d-4545-81c2-76400e458032", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "edd0d69812414b4bb84c1df5c213fdd5", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Accordion(children=(VBox(children=(Textarea(value='', description='SQL Query:', layout=Layout(width='700px'), …" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "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" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3e6fadfb-e275-4944-8926-cb8a33a9c866", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { From 06f1d0ddb96b3de695fd0f5482b09d4cbdf5d0d2 Mon Sep 17 00:00:00 2001 From: Umar Farooq Ghumman Date: Tue, 21 May 2024 11:33:19 -0500 Subject: [PATCH 2/2] Update qprof-ui.ipynb replaced the placeholder with actual HTML content of the qprof report. --- project/ui/qprof-ui.ipynb | 99 +++++++-------------------------------- 1 file changed, 16 insertions(+), 83 deletions(-) diff --git a/project/ui/qprof-ui.ipynb b/project/ui/qprof-ui.ipynb index 59496575..1630f5b7 100644 --- a/project/ui/qprof-ui.ipynb +++ b/project/ui/qprof-ui.ipynb @@ -9,7 +9,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "0db0b48039f44b8998eb9d73e1748b64", + "model_id": "02d833789e9d402d8b05bfcf10d8c179", "version_major": 2, "version_minor": 0 }, @@ -86,6 +86,7 @@ "from verticapy.performance.vertica import QueryProfilerInterface, QueryProfiler\n", "logging.info('[Query Profile Tree Page] Successfully Imported Libraries ')\n", "output_initial = widgets.Output()\n", + "global qprof\n", "with output_initial:\n", " %store -r query_val\n", " %store -r key_val\n", @@ -240,19 +241,9 @@ "btn_report = Button(description='Click to download')\n", "\n", "def download_html(e=None):\n", + " global qprof\n", " # Define the HTML content\n", - " html_content = \"\"\"\n", - " \n", - " \n", - " \n", - " Sample HTML Page\n", - " \n", - " \n", - "

Hello, World!

\n", - "

This is a sample HTML page.

\n", - " \n", - " \n", - " \"\"\"\n", + " html_content = qprof.to_html()\n", " html_data = html_content.encode('utf-8')\n", " trigger_download_report(html_data, 'sample.html')\n", "\n", @@ -285,7 +276,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "0dea3cf917c74eb6875751a50fc4bcf2", + "model_id": "c8c3fc00be5244139de35530d14bb193", "version_major": 2, "version_minor": 0 }, @@ -299,7 +290,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "e7b89a2cf9f24c238ba2ef49204639d5", + "model_id": "54b45da812df4224a1715f0880badfc7", "version_major": 2, "version_minor": 0 }, @@ -313,7 +304,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "84b851b39981427eb8862219957f079d", + "model_id": "4f5abbe49dd64384865f86f9dff2865c", "version_major": 2, "version_minor": 0 }, @@ -333,7 +324,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "abc47c4f-bd5a-491c-8c29-6ea00840aaa8", "metadata": {}, "outputs": [], @@ -360,37 +351,10 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "7ad589fc-a4eb-4262-8aca-30a103dceb4d", "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n", - "\n", - "\n", - " \n", - "\n", - "\n", - "\n", - "
\n", - " \n", - " \n", - " \n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "display(HTML(html_code))\n", "logging.info(f'[Query Profile Tree Page] Completed the script to automatically display the tree')" @@ -398,7 +362,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "1f25ec1d-b2fa-404b-95d0-cddb86456456", "metadata": {}, "outputs": [], @@ -443,25 +407,10 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "7e5b38a8-79dd-45b2-85de-6be16c74206f", "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "d63edd00d6f645c591e779ffdda312ff", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Tab(children=(VBox(children=(Output(),)), VBox(children=(VBox(children=(HTML(value=\"

The f…" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "output_tree = widgets.Output()\n", "\n", @@ -483,7 +432,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "id": "9b4c74d6-b45e-42aa-b361-0605705587ed", "metadata": {}, "outputs": [], @@ -521,26 +470,10 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "32cf2caa-2a1d-4545-81c2-76400e458032", "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "edd0d69812414b4bb84c1df5c213fdd5", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Accordion(children=(VBox(children=(Textarea(value='', description='SQL Query:', layout=Layout(width='700px'), …" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "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",