Skip to content

Commit

Permalink
Allowing multiple transaction ids and statement ids
Browse files Browse the repository at this point in the history
  • Loading branch information
mail4umar committed Apr 8, 2024
1 parent 2dd46ad commit 1174b05
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
12 changes: 10 additions & 2 deletions project/ui/qprof-ui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "0221f436-1e34-405a-b28c-293eac20c369",
"metadata": {
"scrolled": true
Expand All @@ -24,6 +24,7 @@
" %store -r file_val\n",
" %store -r target_schema_val_2\n",
" %store -r key_val_2\n",
" %store -r transaction_statement_list_val\n",
"\n",
" if \"file_val\" in globals():\n",
" qprof = QueryProfiler.import_profile(target_schema=target_schema_val,\n",
Expand Down Expand Up @@ -51,7 +52,14 @@
" transactions = (transaction_val, statement_val),\n",
" 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",
" )"
" )\n",
"\n",
" elif \"transaction_statement_list_val\" in globals():\n",
" qprof = QueryProfilerInterface(\n",
" transactions = transaction_statement_list_val,\n",
" 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",
" )\n"
]
},
{
Expand Down
53 changes: 47 additions & 6 deletions project/ui/qprof_main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"import verticapy as vp\n",
"from IPython.display import display,clear_output, IFrame, HTML\n",
"import pickle\n",
"import re\n",
"import webbrowser\n",
"from ipyfilechooser import FileChooser\n",
"import verticapy as vp\n",
Expand All @@ -27,7 +28,7 @@
"metadata": {},
"outputs": [],
"source": [
"def reset_values(query_val = None, key_val = None, target_schema_val = None, transaction_val = None, statement_val = None, file_val = None, key_val_2 = None, target_schema_val_2 = None): \n",
"def reset_values(query_val = None, key_val = None, target_schema_val = None, transaction_val = None, statement_val = None, file_val = None, key_val_2 = None, target_schema_val_2 = None, transaction_statement_list_val = None): \n",
" if query_val:\n",
" %store query_val\n",
" else:\n",
Expand Down Expand Up @@ -60,6 +61,11 @@
" %store target_schema_val_2\n",
" else:\n",
" %store -d target_schema_val_2\n",
" if transaction_statement_list_val:\n",
" %store transaction_statement_list_val\n",
" else:\n",
" %store -d transaction_statement_list_val\n",
" \n",
" notebook_url = '/voila/render/ui/qprof-ui.ipynb'\n",
" display(HTML(f\"<script>window.open('{notebook_url}');window.close();</script>\"))"
]
Expand Down Expand Up @@ -112,14 +118,12 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"button_2 = widgets.Button(description=\"Get Query Plan\")\n",
"output_2 = widgets.Output()\n",
"\n",
"key_val = None\n",
"target_schema_val = None\n",
"\n",
"\n",
"def on_button_clicked_2(b):\n",
" global key_val, target_schema_val\n",
" output_2.clear_output(wait=True)\n",
Expand Down Expand Up @@ -236,7 +240,7 @@
"key_2 = widgets.Text(description = \"Key\", placeholder = \"Enter Key (Optional)\", layout=widgets.Layout(width='300px'))\n",
"key_2.style.description_width = '100px'\n",
"target_schema_2 = widgets.Text(description = \"Target Schema (Optional)\", placeholder = \"Enter Schema\",layout=widgets.Layout(width='300px'))\n",
"target_schema_2.style.description_width = '100px'"
"target_schema_2.style.description_width = '150px'"
]
},
{
Expand Down Expand Up @@ -306,6 +310,43 @@
"create_1 = widgets.VBox([target_schema_2, key_2, query, button, output_0])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "947b5d38-5c30-4f77-87e9-7402e690ea06",
"metadata": {},
"outputs": [],
"source": [
"transaction_statement_list = widgets.Text(description = \"List of transaction IDs and statement IDs\", placeholder = \"[(trsansac_1, statemnt_1),(trsansac_2, statemnt_2)]\", layout=widgets.Layout(width='600px'))\n",
"transaction_statement_list.style.description_width = '240px'\n",
"button_4 = widgets.Button(description=\"Get Query Plan\")\n",
"output_4 = widgets.Output()\n",
"transaction_statement_list_val = None\n",
"target_schema_val_2 = None\n",
"key_val_2 = None\n",
"\n",
"\n",
"\n",
"def is_input_valid(input_string):\n",
" pattern = r'\\[\\((\\d+),(\\d+)\\)(,\\((\\d+),(\\d+)\\))*\\]'\n",
" return bool(re.match(pattern, input_string))\n",
"\n",
"def on_button_clicked_4(b):\n",
" output_4.clear_output(wait=True)\n",
" global target_schema_val_2, key_val_2, transaction_statement_list_val\n",
" with output_4:\n",
" if not is_input_valid(transaction_statement_list.value):\n",
" print(\"\\033[91m\\033[1m Error \\033[0m: Please check the input syntax. List of tuples is expected.\")\n",
" else:\n",
" target_schema_val_2 = target_schema_2.value\n",
" key_val_2 = key_2.value\n",
" transaction_statement_list_val = transaction_statement_list.value\n",
" reset_values(transaction_statement_list_val = transaction_statement_list_val, target_schema_val_2 = target_schema_val_2, key_val_2 = key_val_2)\n",
"\n",
"button_4.on_click(on_button_clicked_4)\n",
"create_list_transaction_statement = widgets.VBox([target_schema_2, key_2,transaction_statement_list, button_4, output_4])"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -314,8 +355,8 @@
"outputs": [],
"source": [
"tab_2 = widgets.Tab()\n",
"tab_2.children = [create_0, create_1]\n",
"tab_2.titles = [\"Transaction & Statement\", \"From SQL\"]\n",
"tab_2.children = [create_0, create_1, create_list_transaction_statement]\n",
"tab_2.titles = [\"Transaction & Statement\", \"From SQL\", \"Multiple Queries\"]\n",
"display(tab_2)"
]
},
Expand Down

0 comments on commit 1174b05

Please sign in to comment.