Skip to content

Commit

Permalink
Merge pull request #272 from vertica/nocode_ui_pages_update_07
Browse files Browse the repository at this point in the history
QueryProfiler UI Main Page - Added dropdown for schema and key
  • Loading branch information
mail4umar authored Jun 13, 2024
2 parents a5b7b37 + e12f89e commit e8aca99
Showing 1 changed file with 153 additions and 23 deletions.
176 changes: 153 additions & 23 deletions project/ui/qprof_main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,93 @@
"____"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b1c447e3-0a23-41ff-bcf5-0aa2f83b4141",
"metadata": {},
"outputs": [],
"source": [
"# Function to update the options of the key dropdown based on the selection of the schema dropdown\n",
"def update_key_dropdown_options(change):\n",
" # Get the selected schema from the first dropdown\n",
" selected_schema = change.new\n",
" \n",
" # Query for the table names based on the selected schema\n",
" query = f\"SELECT DISTINCT table_name FROM tables WHERE table_name LIKE '%_dc_explain_plans_%' AND table_schema = '{selected_schema}' ORDER BY 1;\"\n",
" vdf = vp.vDataFrame(query)\n",
" \n",
" # Manipulate table names\n",
" length_to_remove = len(selected_schema) + len(\"_dc_explain_plans_\") + 1\n",
" vdf['table_name'] = vdf['table_name'].apply(f\"SUBSTR(table_name, {length_to_remove})\")\n",
" \n",
" # Update options of the second dropdown\n",
" key_dropdown.options = [i[0] for i in vdf.to_list()]\n",
"\n",
"# Function to observe the value of the key and target_schema widget and disable both dropdowns if there is any user value\n",
"def observe_value_change(change):\n",
" # If the key widget or target_schema widget has any user value, disable both dropdowns\n",
" if key.value or target_schema.value:\n",
" schema_dropdown.disabled = True\n",
" key_dropdown.disabled = True\n",
" else:\n",
" schema_dropdown.disabled = False\n",
" key_dropdown.disabled = False\n",
"\n",
"\n",
"# Query for the options of the first dropdown\n",
"query = \"SELECT DISTINCT table_schema FROM tables WHERE table_name LIKE '%_dc_explain_plans_%' ORDER BY 1;\"\n",
"vdf = vp.vDataFrame(query)\n",
"schema_dropdown_options = [i[0] for i in vdf.to_list()]\n",
"\n",
"# Create the first dropdown\n",
"schema_dropdown = widgets.Dropdown(\n",
" options=schema_dropdown_options,\n",
" value = None,\n",
" description='Schema List',\n",
" disabled=False,\n",
" layout={'width': \"250px\"}\n",
")\n",
"schema_dropdown.style.description_width = '100px'\n",
"\n",
"# Create the second dropdown with initial options\n",
"key_dropdown = widgets.Dropdown(\n",
" options=[], # Initial options, will be updated dynamically\n",
" description='Key List',\n",
" disabled=False,\n",
" layout={'width': \"250px\"}\n",
")\n",
"key_dropdown.style.description_width = '100px'\n",
"\n",
"# Observe changes in the first dropdown and trigger the update function\n",
"schema_dropdown.observe(update_key_dropdown_options, names='value')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dc6abb5f-e563-470c-9348-f309bf3c0501",
"metadata": {},
"outputs": [],
"source": [
"schema_name = \"alu\"\n",
"query = f\"SELECT schema_name FROM v_catalog.schemata WHERE schema_name = '{schema_name}';\"\n",
"vdf = vp.vDataFrame(query)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d3612bc2-cc28-45ca-a77c-f30dd05660cd",
"metadata": {},
"outputs": [],
"source": [
"def schema_exists(schema_name):\n",
" query = f\"SELECT schema_name FROM v_catalog.schemata WHERE schema_name = '{schema_name}';\"\n",
" vdf = vp.vDataFrame(query)\n",
" return vdf.shape()[0] > 0"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -228,10 +315,13 @@
" global key_val, target_schema_val\n",
" output_2.clear_output(wait=True)\n",
" with output_2:\n",
" key_val = key.value\n",
" target_schema_val = target_schema.value\n",
" logging.info(f\"[Query Profile Main Page] For load from schema and key option, saved key value as :{key_val}, target schema as {target_schema_val}. \")\n",
" reset_values(key_val = key_val, target_schema_val = target_schema_val)\n",
" key_val = key.value if key.value else key_dropdown.value\n",
" target_schema_val = target_schema.value if target_schema.value else schema_dropwdown.value\n",
" if not schema_exists(target_schema_val):\n",
" print(\"\\033[91m\\033[1m Error! The schema does not exist. \\033[0m\\033[0m\")\n",
" else:\n",
" logging.info(f\"[Query Profile Main Page] For load from schema and key option, saved key value as :{key_val}, target schema as {target_schema_val}. \")\n",
" reset_values(key_val = key_val, target_schema_val = target_schema_val)\n",
"\n",
"button_2.on_click(on_button_clicked_2)\n",
"\n",
Expand All @@ -244,8 +334,8 @@
" global key_val, target_schema_val, file_val\n",
" output_3.clear_output(wait=True)\n",
" with output_3:\n",
" key_val = key.value\n",
" target_schema_val = target_schema.value\n",
" key_val = key.value if key.value else key_dropdown.value\n",
" target_schema_val = target_schema.value if target_schema.value else schema_dropdown.value\n",
" file_val = uploader.value\n",
" logging.info(f\"[Query Profile Main Page] For load from file option, saved key value as :{key_val}, target schema as {target_schema_val}, file name as {file_val}.\")\n",
" if target_schema_val == \"\" or file_val == \"\":\n",
Expand Down Expand Up @@ -289,6 +379,34 @@
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18fa4233-c940-47e0-89a2-ca2937642916",
"metadata": {},
"outputs": [],
"source": [
"html_arrow = \"\"\"\n",
"<style>\n",
".container {\n",
" display: flex;\n",
" align-items: center; /* Center vertically */\n",
" padding-left: 5px; /* Add padding to the left */\n",
"}\n",
"\n",
".arrow {\n",
" font-weight: bold; /* Make the arrow bold */\n",
" font-size: 2em; /* Make the arrow slightly bigger */\n",
"}\n",
"</style>\n",
"\n",
"<div class=\"container\">\n",
" Or select from a list\n",
" <span class=\"arrow\">&rarr;</span> \n",
"</div>\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -304,10 +422,13 @@
"uploader_combo = widgets.HBox([uploader, create_tooltip(\"Select the tar file that you obtained after exporting the query profile object.\")])\n",
"from ipyfilechooser import FileChooser\n",
"\n",
"# Observe changes in the key and target_schema widget to disable both dropdowns if there is any user value\n",
"key.observe(observe_value_change, names='value')\n",
"target_schema.observe(observe_value_change, names='value')\n",
"\n",
"tab = widgets.Tab()\n",
"target_schema_combo = widgets.HBox([target_schema, create_tooltip(\"Enter the target schema that you used to save the QueryProfiler object. This will not work if you have not saved your query profile already.\")])\n",
"key_combo = widgets.HBox([key, create_tooltip(\"Enter the unique key that you used to save the QueryProfiler object. This will not work if you have not saved your query profile already.\")])\n",
"target_schema_combo = widgets.HBox([target_schema,widgets.HTML(html_arrow), schema_dropdown, create_tooltip(\"Enter the target schema that you used to save the QueryProfiler object. This will not work if you have not saved your query profile already.\")])\n",
"key_combo = widgets.HBox([key, widgets.HTML(html_arrow), key_dropdown, create_tooltip(\"Enter the unique key that you used to save the QueryProfiler object. This will not work if you have not saved your query profile already.\")])\n",
"child_1 = widgets.VBox([target_schema_combo,key_combo,button_2, output_2])\n",
"child_2 = widgets.VBox([target_schema_combo,key_combo,uploader_combo,button_3, output_3])\n",
"tab.children = [child_1, child_2]\n",
Expand Down Expand Up @@ -423,11 +544,14 @@
" global target_schema_val_2, key_val_2, statement_val, transaction_val\n",
" with output_1:\n",
" target_schema_val_2 = target_schema_2.value\n",
" key_val_2 = key_2.value\n",
" transaction_val = transaction.value\n",
" statement_val = statement.value\n",
" logging.info(f\"[Query Profile Main Page] For create option, saved key value as :{key_val_2}, target schema as {target_schema_val_2}, transaction id as {transaction_val}, statement id as {statement_val}.\")\n",
" reset_values(statement_val = statement_val, transaction_val = transaction_val, target_schema_val_2 = target_schema_val_2, key_val_2 = key_val_2)\n",
" if not schema_exists(target_schema_val_2):\n",
" print(\"\\033[91m\\033[1m Error! The schema does not exist. \\033[0m\\033[0m\")\n",
" else:\n",
" key_val_2 = key_2.value\n",
" transaction_val = transaction.value\n",
" statement_val = statement.value\n",
" logging.info(f\"[Query Profile Main Page] For create option, saved key value as :{key_val_2}, target schema as {target_schema_val_2}, transaction id as {transaction_val}, statement id as {statement_val}.\")\n",
" reset_values(statement_val = statement_val, transaction_val = transaction_val, target_schema_val_2 = target_schema_val_2, key_val_2 = key_val_2)\n",
"\n",
"button_1.on_click(on_button_clicked_1)\n",
"create_0 = widgets.VBox([target_schema_2_combo, key_2_combo,transaction_combo,statement_combo, button_1, output_1])"
Expand Down Expand Up @@ -464,10 +588,13 @@
" global query_val, target_schema_val_2, key_val_2\n",
" with output_0:\n",
" target_schema_val_2 = target_schema_2.value\n",
" key_val_2 = key_2.value\n",
" query_val = query.value\n",
" logging.info(f\"\"\"[Query Profile Main Page] For create using query option, saved key value as :{key_val_2}, target schema as {target_schema_val_2}, query as \"{query_val}\".\"\"\")\n",
" reset_values(query_val = query_val, target_schema_val_2 = target_schema_val_2, key_val_2 = key_val_2)\n",
" if not schema_exists(target_schema_val_2):\n",
" print(\"\\033[91m\\033[1m Error! The schema does not exist. \\033[0m\\033[0m\")\n",
" else:\n",
" key_val_2 = key_2.value\n",
" query_val = query.value\n",
" logging.info(f\"\"\"[Query Profile Main Page] For create using query option, saved key value as :{key_val_2}, target schema as {target_schema_val_2}, query as \"{query_val}\".\"\"\")\n",
" reset_values(query_val = query_val, target_schema_val_2 = target_schema_val_2, key_val_2 = key_val_2)\n",
"\n",
"button.on_click(on_button_clicked_0)\n",
"create_1 = widgets.VBox([target_schema_2_combo, key_2_combo, query, button, output_0])\n"
Expand Down Expand Up @@ -503,11 +630,14 @@
" 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",
" transaction_statement_list_val.replace(\" \", \"\")\n",
" logging.info(f\"[Query Profile Main Page] For create using multiple transaction ids and keys, saved key value as :{key_val_2}, target schema as {target_schema_val_2}, List of transactions and statements as {transaction_statement_list_val}.\")\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",
" if not schema_exists(target_schema_val_2):\n",
" print(\"\\033[91m\\033[1m Error! The schema does not exist. \\033[0m\\033[0m\")\n",
" else:\n",
" key_val_2 = key_2.value\n",
" transaction_statement_list_val = transaction_statement_list.value\n",
" transaction_statement_list_val.replace(\" \", \"\")\n",
" logging.info(f\"[Query Profile Main Page] For create using multiple transaction ids and keys, saved key value as :{key_val_2}, target schema as {target_schema_val_2}, List of transactions and statements as {transaction_statement_list_val}.\")\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_combo, key_2_combo,transaction_statement_list_combo, button_4, output_4])"
Expand Down Expand Up @@ -660,7 +790,7 @@
"</head>\n",
"<body>\n",
" <div class=\"version\">\n",
" Page version update date: 6/10/2024\n",
" Page version update date: 6/12/2024\n",
" </div>\n",
"</body>\n",
"</html>"
Expand Down

0 comments on commit e8aca99

Please sign in to comment.