diff --git a/project/ui/qprof-ui.ipynb b/project/ui/qprof-ui.ipynb index 6ede88a8..0027b587 100644 --- a/project/ui/qprof-ui.ipynb +++ b/project/ui/qprof-ui.ipynb @@ -155,7 +155,9 @@ "outputs": [], "source": [ "# Loading display settings\n", - "\n", + "#Default\n", + "vp.set_option(\"max_rows\", 20000)\n", + "vp.set_option(\"insert_comma_numbers\", True)\n", "# Saved\n", "with output_initial:\n", " # Attempt to load stored variables\n", @@ -514,64 +516,37 @@ " summary_vdf_main = summary_vdf\n", " \n", " # Update the table display\n", - " summary_update_table(node_name=summary_node_name_dropdown.value, path_id=summary_path_id_dropdown.value, localplan_id=summary_localplan_id_dropdown.value)\n", - "\n", + " display_vdf_across_paths(path_id=summary_path_id_dropdown.value)\n", + " display_vdf_across_nodes(path_id=summary_path_id_dropdown.value, localplan_id=summary_localplan_id_dropdown.value, operator_name=summary_operator_name_dropdown.value)\n", "\n", "# Attach the observer to each checkbox\n", "for cb in checkboxes:\n", " cb.observe(on_checkbox_change, names='value')\n", "\n", "# Selecting the granularity of the summary table\n", - "granularity_level = 0\n", - "granularity_column_list = [\"node_name\", \"path_id\", \"localplan_id\", \"operator_name\", \"thread_count\"]\n", "engine_table_granularity_switch = widgets.RadioButtons(\n", - " options=['Pivot Table of metrics', 'Summary across nodes', 'Summary across steps'],\n", - " value='Pivot Table of metrics', # Defaults to 'Pivot Table of metrics'\n", + " options=['Across paths', 'Across nodes'],\n", + " value='Across paths', # Defaults to 'Pivot Table of metrics'\n", " # description='Select Granularity Level:',\n", " disabled=False\n", ")\n", - "\n", + "granularity_level = 2\n", "engine_table_granularity_switch_title = widgets.HTML(' Select granularity level:')\n", "def on_granularity_change(change):\n", - " global granularity_level, summary_vdf, summary_vdf_main, granularity_column_list\n", " if change['type'] == 'change' and change['name'] == 'value':\n", - " if change['new'] == 'Pivot Table of metrics':\n", - " granularity_level = 0\n", - " summary_node_name_dropdown.disabled = False\n", - " summary_localplan_id_dropdown.disabled = False\n", - " summary_operator_name_dropdown.disabled = False\n", - " elif change['new'] == 'Summary across nodes':\n", + " if change['new'] == 'Across nodes':\n", " granularity_level = 1\n", - " summary_node_name_dropdown.value = \"All\"\n", " summary_node_name_dropdown.disabled = True\n", - " summary_path_id_dropdown.value = \"All\"\n", - " summary_localplan_id_dropdown.value = \"All\"\n", " summary_localplan_id_dropdown.disabled = False\n", - " summary_operator_name_dropdown.value = \"All\"\n", - " summary_operator_name_dropdown.disabled = False \n", - " elif change['new'] == 'Summary across steps':\n", + " summary_operator_name_dropdown.disabled = False\n", + " display_vdf_across_nodes(path_id=summary_path_id_dropdown.value, localplan_id=summary_localplan_id_dropdown.value, operator_name=summary_operator_name_dropdown.value)\n", + " elif change['new'] == 'Across paths':\n", " granularity_level = 2\n", - " summary_node_name_dropdown.value = \"All\"\n", " summary_node_name_dropdown.disabled = True\n", - " summary_path_id_dropdown.value = \"All\"\n", - " summary_localplan_id_dropdown.value = \"All\"\n", " summary_localplan_id_dropdown.disabled = True\n", - " summary_operator_name_dropdown.value = \"All\"\n", " summary_operator_name_dropdown.disabled = True\n", - " # Update the dataframe based on selected checkboxes\n", - " if granularity_level==0:\n", - " granularity_column_list = [\"node_name\", \"path_id\", \"localplan_id\", \"operator_name\", \"thread_count\"]\n", - " elif granularity_level==1:\n", - " granularity_column_list = [\"path_id\", \"localplan_id\", \"operator_name\", \"thread_count\"]\n", - " elif granularity_level==2:\n", - " granularity_column_list = [\"path_id\", \"thread_count\"]\n", - " column_list = granularity_column_list.copy()\n", - " selected_checkboxes = [cb.description for cb in checkboxes if cb.value]\n", - " column_list.extend(selected_checkboxes.copy())\n", - " summary_vdf = qprof._get_vdf_summary()[granularity_level][column_list]\n", + " display_vdf_across_paths(path_id=summary_path_id_dropdown.value)\n", " \n", - " # Update the table display\n", - " summary_update_table(node_name=summary_node_name_dropdown.value, path_id=summary_path_id_dropdown.value, localplan_id=summary_localplan_id_dropdown.value, operator_name=summary_operator_name_dropdown.value)\n", "\n", "\n", "\n", @@ -579,20 +554,28 @@ "\n", "try:\n", " # summary_vdf = qprof._get_vdf_summary()[0][\"node_name\", \"path_id\", \"localplan_id\", \"operator_name\", \"exec_time_us\", \"est_rows\", \"rle_prod_rows\"]\n", - " summary_vdf = None\n", - " summary_vdf_main = None\n", + " vdf_across_paths = None\n", + " vdf_across_nodes = None\n", "\n", - " def summary_update_table(node_name=\"All\", path_id=\"All\", localplan_id=\"All\", operator_name=\"All\"):\n", - " global summary_vdf\n", - " if summary_vdf is None:\n", + " def display_vdf_across_paths(path_id=\"All\"):\n", + " if vdf_across_paths is None:\n", " return\n", - " vdf = summary_vdf\n", + " vdf = vdf_across_paths.copy()\n", + " with engine_tab_summary_1:\n", + " engine_tab_summary_1.clear_output(wait=True)\n", + " if path_id != \"All\":\n", + " vdf = vdf[vdf[\"path_id\"] == path_id]\n", + " # display(widgets.HTML(vdf._repr_html_()))\n", + " display(vdf.idisplay())\n", + "\n", + " def display_vdf_across_nodes(path_id=\"All\", localplan_id=\"All\", operator_name=\"All\"):\n", + " if vdf_across_nodes is None:\n", + " return\n", + " vdf = vdf_across_nodes.copy()\n", " with engine_tab_summary_1:\n", " engine_tab_summary_1.clear_output(wait=True)\n", " if path_id != \"All\":\n", " vdf = vdf[vdf[\"path_id\"] == path_id]\n", - " if node_name != \"All\":\n", - " vdf = vdf[vdf[\"node_name\"] == node_name]\n", " if localplan_id != \"All\":\n", " vdf = vdf[vdf[\"localplan_id\"] == localplan_id]\n", " if operator_name != \"All\":\n", @@ -607,7 +590,8 @@ " options=['All'],\n", " description='Select Node Name:',\n", " style={'description_width': 'initial'},\n", - " value='All'\n", + " value='All',\n", + " disabled=True\n", " )\n", " summary_path_id_dropdown = widgets.Dropdown(\n", " options=['All'],\n", @@ -633,12 +617,16 @@ " if change['type'] == 'change' and change['name'] == 'value':\n", " selected_key = change['new']\n", " if selected_key == 'All':\n", - " path_id_dropdown.options = ['All'] + sorted(summary_vdf_main[\"path_id\"].distinct())\n", + " summary_path_id_dropdown.options = ['All'] + sorted(summary_vdf_main[\"path_id\"].distinct())\n", " else:\n", " vdf = summary_vdf_main[summary_vdf_main[\"node_name\"]==selected_key]\n", " summary_path_id_dropdown.options = ['All'] + sorted(vdf[\"path_id\"].distinct())\n", " summary_path_id_dropdown.value = 'All'\n", - " summary_update_table(node_name = selected_key)\n", + " if engine_table_granularity_switch.value == 'Across nodes':\n", + " display_vdf_across_nodes()\n", + " else:\n", + " display_vdf_across_paths()\n", + " \n", " detailed_update_table(node_name = selected_key)\n", " \n", " summary_node_name_dropdown.observe(summary_on_node_name_dropdown_change, names='value')\n", @@ -653,11 +641,14 @@ " if selected_key == 'All':\n", " summary_localplan_id_dropdown.options = ['All'] + sorted(vdf[\"localplan_id\"].distinct())\n", " else: \n", - " vdf = vdf[summary_vdf[\"path_id\"]==selected_key]\n", + " vdf = vdf[vdf[\"path_id\"]==selected_key]\n", " summary_localplan_id_dropdown.options = ['All'] + sorted(vdf[\"localplan_id\"].distinct())\n", " summary_localplan_id_dropdown.value = 'All'\n", - " summary_update_table(node_name = summary_node_name_dropdown.value,path_id = selected_key)\n", - " detailed_update_table(node_name = summary_node_name_dropdown.value,path_id = selected_key)\n", + " if engine_table_granularity_switch.value == 'Across nodes':\n", + " display_vdf_across_nodes(path_id = selected_key)\n", + " else:\n", + " display_vdf_across_paths(path_id = selected_key)\n", + " detailed_update_table(node_name = summary_node_name_dropdown.value, path_id = selected_key)\n", " \n", " summary_path_id_dropdown.observe(summary_on_path_id_dropdown_change, names='value')\n", " \n", @@ -673,10 +664,13 @@ " if selected_key == 'All':\n", " summary_operator_name_dropdown.options = ['All'] + sorted(vdf[\"operator_name\"].distinct())\n", " else:\n", - " vdf = vdf[summary_vdf[\"localplan_id\"]==selected_key]\n", + " vdf = vdf[vdf[\"localplan_id\"]==selected_key]\n", " summary_operator_name_dropdown.options = ['All'] + sorted(vdf[\"operator_name\"].distinct())\n", " summary_operator_name_dropdown.value = 'All'\n", - " summary_update_table(node_name = summary_node_name_dropdown.value,path_id = summary_path_id_dropdown.value,localplan_id = selected_key)\n", + " if engine_table_granularity_switch.value == 'Across nodes':\n", + " display_vdf_across_nodes(path_id = summary_path_id_dropdown.value, localplan_id = selected_key)\n", + " else:\n", + " display_vdf_across_paths(path_id = summary_path_id_dropdown.value)\n", " detailed_update_table(node_name = summary_node_name_dropdown.value,path_id = summary_path_id_dropdown.value,localplan_id = selected_key)\n", "\n", " summary_localplan_id_dropdown.observe(summary_on_localplan_id_dropdown_change, names='value') \n", @@ -692,21 +686,19 @@ " vdf=vdf[vdf[\"localplan_id\"]==summary_localplan_id_dropdown.value]\n", " if change['type'] == 'change' and change['name'] == 'value':\n", " selected_key = change['new']\n", - " summary_update_table(node_name = summary_node_name_dropdown.value,path_id = summary_path_id_dropdown.value,localplan_id = summary_localplan_id_dropdown.value, operator_name = selected_key)\n", - " detailed_update_table(node_name = summary_node_name_dropdown.value,path_id = summary_path_id_dropdown.value,localplan_id = summary_localplan_id_dropdown.value, operator_name = selected_key)\n", + " if engine_table_granularity_switch.value == 'Across nodes':\n", + " display_vdf_across_nodes(path_id=summary_path_id_dropdown.value, localplan_id=summary_localplan_id_dropdown.value, operator_name=selected_key)\n", + " else:\n", + " display_vdf_across_paths(path_id=summary_path_id_dropdown.value)\n", + " detailed_update_table(node_name=summary_node_name_dropdown.value, path_id=summary_path_id_dropdown.value, localplan_id=summary_localplan_id_dropdown.value, operator_name=selected_key)\n", " \n", " summary_operator_name_dropdown.observe(summary_on_operator_name_dropdown_change, names='value') \n", "\n", - " grid = widgets.GridspecLayout(2, 5, \n", - " # height='600px', \n", - " # width='100%'\n", - " )\n", - " # Add widgets to the grid\n", - " engine_table_granularity_title_switch= widgets.VBox([engine_table_granularity_switch_title,engine_table_granularity_switch], layout=widgets.Layout(padding='0 0 0 10px'))\n", - " grid[0:, 0:4] = widgets.VBox([widgets.HBox([engine_table_summary_controls,widgets.HTML(\"
\"),engine_table_granularity_title_switch]), engine_tab_summary_1])\n", - " grid[0:2, 4] = widgets.VBox([widgets.HTML('

Select Metrics

')] + checkboxes)\n", - "\n", - " engine_tab_summary_all = grid\n", + " engine_table_granularity_title_switch = widgets.VBox([engine_table_granularity_switch_title, engine_table_granularity_switch], layout=widgets.Layout(padding='0 0 0 10px'))\n", + " engine_tab_summary_all = widgets.VBox([\n", + " widgets.HBox([engine_table_summary_controls, widgets.HTML(\"
\"), engine_table_granularity_title_switch]),\n", + " engine_tab_summary_1\n", + " ])\n", "\n", "except Exception as e:\n", " engine_tab_summary_all = widgets.HTML(f\"

The following error occured:

{e}

\")\n", @@ -717,6 +709,26 @@ "\n", "\n", "# Tab for detailed Executio Engine Table\n", + "engine_table_detailed_selection_title = widgets.HTML(' Select detailed view:')\n", + "engine_table_detailed_selection_switch = widgets.RadioButtons(\n", + " options=['Pivot Table', 'Raw Table'],\n", + " value='Pivot Table',\n", + " disabled=False\n", + ")\n", + "engine_table_detailed_selection_title_switch = widgets.VBox([\n", + " engine_table_detailed_selection_title,\n", + " engine_table_detailed_selection_switch\n", + "], layout=widgets.Layout(padding='0 0 0 10px'))\n", + "\n", + "def on_detailed_view_change(change):\n", + " if change['type'] == 'change' and change['name'] == 'value':\n", + " detailed_update_table(\n", + " node_name=summary_node_name_dropdown.value,\n", + " path_id=summary_path_id_dropdown.value,\n", + " localplan_id=summary_localplan_id_dropdown.value,\n", + " operator_name=summary_operator_name_dropdown.value\n", + " )\n", + "engine_table_detailed_selection_switch.observe(on_detailed_view_change, names='value')\n", "engine_table_detailed_widget = widgets.Output()\n", "try:\n", " query = (f\"\"\" \n", @@ -727,10 +739,14 @@ " detailed_vdf = vp.vDataFrame(query)\n", " \n", " def detailed_update_table(node_name=\"All\", path_id=\"All\", localplan_id=\"All\", operator_name=\"All\"):\n", - " global detailed_vdf\n", - " vdf = detailed_vdf.copy()\n", + " global detailed_vdf, summary_vdf\n", + " \n", " with engine_table_detailed_widget:\n", " engine_table_detailed_widget.clear_output(wait=True)\n", + " if engine_table_detailed_selection_switch.value == \"Raw Table\":\n", + " vdf = detailed_vdf.copy()\n", + " elif engine_table_detailed_selection_switch.value == \"Pivot Table\":\n", + " vdf = summary_vdf.copy()\n", " if path_id != \"All\":\n", " vdf = vdf[vdf[\"path_id\"] == path_id]\n", " if node_name != \"All\":\n", @@ -746,36 +762,78 @@ "except Exception as e:\n", " engine_table_detailed_widget = widgets.HTML(f\"

The following error occured:

{e}

\") \n", "\n", - "engine_table_detailed = widgets.VBox([summary_node_name_dropdown, summary_path_id_dropdown, summary_localplan_id_dropdown, summary_operator_name_dropdown,engine_table_detailed_widget])\n", + "engine_table_detailed_top = widgets.HBox([engine_table_summary_controls, engine_table_detailed_selection_title_switch])\n", + "engine_table_detailed = widgets.VBox([\n", + " engine_table_detailed_top,\n", + " engine_table_detailed_widget])\n", "\n", "engine_table_tab = widgets.Tab()\n", "engine_table_tab.children = [engine_tab_summary_all, engine_table_detailed]\n", "engine_table_tab.titles = [\"Summary\", \"Detailed\"]\n", "\n", + "\n", + "def on_tab_change(change):\n", + " if change['new'] == 0: # Summary tab\n", + " update_summary_dropdowns()\n", + " else: # Detailed tab\n", + " enable_all_dropdowns()\n", + "\n", + "def update_summary_dropdowns():\n", + " if engine_table_granularity_switch.value == 'Across paths':\n", + " summary_node_name_dropdown.disabled = True\n", + " summary_path_id_dropdown.disabled = False\n", + " summary_localplan_id_dropdown.disabled = True\n", + " summary_operator_name_dropdown.disabled = True\n", + " else: # 'Across nodes'\n", + " summary_node_name_dropdown.disabled = True\n", + " summary_path_id_dropdown.disabled = False\n", + " summary_localplan_id_dropdown.disabled = False\n", + " summary_operator_name_dropdown.disabled = False\n", + "\n", + "def enable_all_dropdowns():\n", + " summary_node_name_dropdown.disabled = False\n", + " summary_path_id_dropdown.disabled = False\n", + " summary_localplan_id_dropdown.disabled = False\n", + " summary_operator_name_dropdown.disabled = False\n", + "\n", + "engine_table_tab.observe(on_tab_change, names='selected_index')\n", "# Button to calcualte Query Execution Engine data\n", "engine_table_button = widgets.Button(description = \"Fetch data\", layout=widgets.Layout(margin='10px 0 10px 0'))\n", "def on_engine_table_button_click(b):\n", " engine_table_button.disabled = True\n", - " global summary_vdf, summary_vdf_main, engine_tab_summary_1, granularity_column_list, granularity_level\n", + " global summary_vdf, summary_vdf_main, vdf_across_paths, vdf_across_nodes\n", " \n", " try:\n", - " summary_vdf_main = qprof._get_vdf_summary()[0][\"node_name\", \"path_id\", \"localplan_id\", \"operator_name\", \"exec_time_us\", \"prod_rows\", \"proc_rows\", \"clock_time_us\", \"mem_all_b\"] # TO FIX LIST\n", - " # column_list = granularity_column_list\n", - " # column_list.extend(selected_checkboxes)\n", - " # summary_vdf_main = qprof._get_vdf_summary()[granularity_level][column_list]\n", - " summary_vdf = summary_vdf_main\n", + " # Adjust the column list based on the current granularity level\n", + " if granularity_level == 2:\n", + " columns = [\"path_id\", \"thread_count\", \"exec_time_us\", \"prod_rows\", \"proc_rows\", \"clock_time_us\", \"mem_all_b\"]\n", + " elif granularity_level == 1:\n", + " columns = [\"path_id\", \"localplan_id\", \"operator_name\", \"thread_count\", \"exec_time_us\", \"prod_rows\", \"proc_rows\", \"clock_time_us\", \"mem_all_b\"]\n", + " else:\n", + " columns = [\"node_name\", \"path_id\", \"localplan_id\", \"operator_name\", \"thread_count\", \"exec_time_us\", \"prod_rows\", \"proc_rows\", \"clock_time_us\", \"mem_all_b\"]\n", + " \n", + "\n", + " summary_vdf = qprof._get_vdf_summary()[0][\"node_name\", \"path_id\", \"localplan_id\", \"operator_name\", \"thread_count\", \"exec_time_us\", \"prod_rows\", \"proc_rows\", \"clock_time_us\", \"mem_all_b\"]\n", + "\n", " # Update dropdowns\n", " summary_node_name_dropdown.options = ['All'] + sorted(summary_vdf[\"node_name\"].distinct())\n", " summary_path_id_dropdown.options = ['All'] + sorted(summary_vdf[\"path_id\"].distinct())\n", " summary_localplan_id_dropdown.options = ['All'] + sorted(summary_vdf[\"localplan_id\"].distinct())\n", " summary_operator_name_dropdown.options = ['All'] + sorted(summary_vdf[\"operator_name\"].distinct())\n", - " \n", + "\n", + " vdf_across_paths = qprof._get_vdf_summary()[2][\"path_id\", \"thread_count\", \"exec_time_us\", \"prod_rows\", \"proc_rows\", \"clock_time_us\", \"mem_all_b\"]\n", + " vdf_across_nodes = qprof._get_vdf_summary()[1][\"path_id\", \"localplan_id\", \"operator_name\", \"thread_count\", \"exec_time_us\", \"prod_rows\", \"proc_rows\", \"clock_time_us\", \"mem_all_b\"]\n", + " summary_vdf_main = summary_vdf\n", + "\n", " # Initial table updates\n", - " summary_update_table()\n", + " display_vdf_across_paths()\n", " detailed_update_table()\n", " except Exception as e:\n", - " engine_tab_summary_1 = widgets.HTML(f\"

The following error occurred:

{e}

\")\n", + " with engine_tab_summary_1:\n", + " engine_tab_summary_1.clear_output(wait=True)\n", + " display(widgets.HTML(f\"

The following error occurred:

{e}

\"))\n", " engine_table_button.disabled = False\n", + "\n", "engine_table_button.on_click(on_engine_table_button_click)\n", "\n", "\n", @@ -1269,7 +1327,7 @@ " if change['new'] == 2: # Check if the first tab (index 0) is selected\n", " try:\n", " update_table('All', 'All')\n", - " except Excetion as e:\n", + " except Exception as e:\n", " pass\n", " # Stop observing after the first time\n", " tabs.unobserve(on_tab_change, names='selected_index')\n", diff --git a/project/ui/qprof_main.ipynb b/project/ui/qprof_main.ipynb index a930ef1e..047d0d20 100644 --- a/project/ui/qprof_main.ipynb +++ b/project/ui/qprof_main.ipynb @@ -458,7 +458,37 @@ " create_tooltip(\"Enter the exact Query to search or part of it.\"),\n", " query_search_check])\n", "search_box_vbox = widgets.VBox([search_box_test, request_label_widget, query_search_widget, button_01, output_01])\n", - "search_box = widgets.Accordion(children=[search_box_vbox], titles=('Search for a query',))\n", + "\n", + "query_session_control_input = widgets.Text(description=\"SQL:\", placeholder=\"Enter Session Control SQL\",\n", + " layout={'width': \"650px\"})\n", + "query_session_control_button = widgets.Button(description=\"Run SQL\")\n", + "query_session_control_output = widgets.Output()\n", + "\n", + "def on_query_session_control_button_clicked(b):\n", + " query_session_control_button.disabled = True\n", + " query_session_control_output.clear_output(wait=True)\n", + " with query_session_control_output:\n", + " sql_query = query_session_control_input.value\n", + " if sql_query:\n", + " logging.info(f'[Query Profile Main Page] Running the following query for session parameter changes: {sql_query}')\n", + " vp._utils._sql._sys._executeSQL(sql_query)\n", + " print(\"Successfully ran the query for session parameter changes.\")\n", + " logging.info('[Query Profile Main Page] Successfully fran query for session parameter chagnes')\n", + " else:\n", + " print(\"\\033[91m\\033[1m Error! Please enter a SQL statement. \\033[0m\\033[0m\")\n", + " query_session_control_button.disabled = False\n", + "\n", + "query_session_control_button.on_click(on_query_session_control_button_clicked)\n", + "\n", + "query_session_control_box = widgets.VBox([\n", + " query_session_control_input,\n", + " query_session_control_button,\n", + " query_session_control_output\n", + "])\n", + "\n", + "# Update the accordion with the new child\n", + "search_box = widgets.Accordion(children=[search_box_vbox, query_session_control_box], titles=('Search for a query', 'Session Parameter Control'))\n", + "\n", "\n", "def on_button_clicked_01(b):\n", " output_01.clear_output(wait=True)\n",