From 81c5454d02bc09ebbb61965bd347a6ccef4808a1 Mon Sep 17 00:00:00 2001 From: Umar Farooq Ghumman Date: Fri, 9 Aug 2024 16:33:20 -0500 Subject: [PATCH] QueryProfiler Main Page - Multiple SQL queries directly from text --- project/ui/qprof_main.ipynb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/project/ui/qprof_main.ipynb b/project/ui/qprof_main.ipynb index 45001a7a..78b27a2c 100644 --- a/project/ui/qprof_main.ipynb +++ b/project/ui/qprof_main.ipynb @@ -574,16 +574,32 @@ "output_0 = widgets.Output()\n", "query_val = None\n", "\n", + "# Split the queries\n", + "def query_list(sql_queries: str):\n", + " # Split the input string by \";\"\n", + " queries = [query.strip() for query in sql_queries.split(';') if query.strip()]\n", + " return queries\n", + "\n", + "# Check if there is at least one space inside the query - to avoid the \";;\" typo mistake.\n", + "def query_check(queries: list):\n", + " for query in queries:\n", + " if ' ' not in query:\n", + " return 1\n", + " return 0\n", + " \n", + "\n", "def on_button_clicked_0(b):\n", " output_0.clear_output(wait=True)\n", " global query_val, target_schema_val_2, key_val_2\n", " with output_0:\n", " target_schema_val_2 = target_schema_2.value\n", + " query_val = query_list(query.value)\n", " if not target_schema_val_2 == \"\" and not schema_exists(target_schema_val_2):\n", " print(\"\\033[91m\\033[1m Error! The schema does not exist. \\033[0m\\033[0m\")\n", + " elif query_check(query_val):\n", + " print(\"\\033[91m\\033[1m Error! Re-check your query. \\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",