diff --git a/notebooks/02-ingestion/12-spatial-dimensions.ipynb b/notebooks/02-ingestion/12-spatial-dimensions.ipynb index 5af7c91b..ee5f42fa 100644 --- a/notebooks/02-ingestion/12-spatial-dimensions.ipynb +++ b/notebooks/02-ingestion/12-spatial-dimensions.ipynb @@ -93,6 +93,27 @@ "status_client.version" ] }, + { + "cell_type": "markdown", + "id": "4fe649dc-a6c6-4dde-afcc-782d2cb73f0a", + "metadata": {}, + "source": [ + "### Import additional modules\n", + "\n", + "Run the following cell to import additional Python modules used by helper functions, and to insert a pause for those API calls that need time to complete." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9e2ad64e-ed63-4b30-adb1-d18844515456", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import time" + ] + }, { "cell_type": "markdown", "id": "70aabd26-6615-48ce-8011-adcc83e7d621", @@ -113,7 +134,6 @@ "outputs": [], "source": [ "def wait_for_datagen( job_name:str):\n", - " import time\n", " from IPython.display import clear_output\n", " # wait for the messages to be fully published \n", " done = False\n", @@ -135,7 +155,6 @@ "outputs": [], "source": [ "def wait_for_task( task_id):\n", - " import time\n", " from IPython.display import clear_output\n", " # wait for the messages to be fully published \n", " done = False\n", @@ -235,7 +254,7 @@ "metadata": {}, "outputs": [], "source": [ - "import json\n", + "table_name = 'example-clickstream-spatial'\n", "\n", "spatial_index_spec = {\n", " \"type\": \"index_parallel\",\n", @@ -259,7 +278,7 @@ " \"queryGranularity\": \"none\",\n", " \"rollup\": False\n", " },\n", - " \"dataSource\": \"example-spatial-index\",\n", + " \"dataSource\": table_name,\n", " \"timestampSpec\": {\n", " \"column\": \"time\",\n", " \"format\": \"iso\"\n", @@ -310,7 +329,9 @@ "\n", "task = rest_client.post(\"/druid/indexer/v1/task\", json.dumps(spatial_index_spec), headers=headers)\n", "task_id = json.loads(task.text)['task']\n", - "wait_for_task(task_id)" + "wait_for_task(task_id)\n", + "\n", + "time.sleep(25) # wait for the data to be available for query" ] }, { @@ -369,7 +390,7 @@ " \"queryType\": \"topN\",\n", " \"dataSource\": {\n", " \"type\": \"table\",\n", - " \"name\": \"example-spatial-index\"\n", + " \"name\": table_name\n", " },\n", " \"dimension\": {\n", " \"type\": \"default\",\n", @@ -430,7 +451,7 @@ "\n", "result = rest_client.post(\"/druid/v2\", json.dumps(rectangular_filter_query), headers=headers)\n", "\n", - "json.loads(result.text)[0]['result']\n" + "json.loads(result.text)[0]['result']" ] }, { @@ -466,7 +487,7 @@ " \"queryType\": \"topN\",\n", " \"dataSource\": {\n", " \"type\": \"table\",\n", - " \"name\": \"example-spatial-index\"\n", + " \"name\": table_name\n", " },\n", " \"dimension\": {\n", " \"type\": \"default\",\n", @@ -570,7 +591,7 @@ " \"queryType\": \"topN\",\n", " \"dataSource\": {\n", " \"type\": \"table\",\n", - " \"name\": \"example-spatial-index\"\n", + " \"name\": table_name\n", " },\n", " \"dimension\": {\n", " \"type\": \"default\",\n", @@ -631,7 +652,7 @@ "\n", "result = rest_client.post(\"/druid/v2\", json.dumps(polygon_filter_query), headers=headers)\n", "\n", - "json.loads(result.text)[0]['result']\n" + "json.loads(result.text)[0]['result']" ] }, { @@ -650,7 +671,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(f\"Drop datasource: [{druid.datasources.drop('example-spatial-index')}]\")\n" + "print(f\"Drop datasource: [{druid.datasources.drop(table_name)}]\")" ] }, { diff --git a/notebooks/02-ingestion/13-native-transforms.ipynb b/notebooks/02-ingestion/13-native-transforms.ipynb index 61e2570d..4a243c42 100644 --- a/notebooks/02-ingestion/13-native-transforms.ipynb +++ b/notebooks/02-ingestion/13-native-transforms.ipynb @@ -138,6 +138,26 @@ "datagen_headers = {'Content-Type': 'application/json'}" ] }, + { + "cell_type": "markdown", + "id": "f99415f4-b239-49ed-8844-859d3c928c1a", + "metadata": {}, + "source": [ + "### Import additional modules\n", + "\n", + "Run the following cell to import additional Python modules that you will use to force a pause in the notebook." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fc410394-48e9-4c6d-bcd6-0ee59c494ed9", + "metadata": {}, + "outputs": [], + "source": [ + "import time" + ] + }, { "cell_type": "markdown", "id": "2a7b7439-ad21-4808-96b1-8e3c992fa51e", @@ -430,6 +450,7 @@ "source": [ "requests.post(f\"{druid_host}/druid/indexer/v1/supervisor\", json.dumps(ingestion_spec), headers=druid_headers)\n", "druid.sql.wait_until_ready(table_name, verify_load_status=False)\n", + "time.sleep(60) # wait a moment for the data to become available\n", "display.table(f'{table_name}')" ] }, @@ -590,6 +611,7 @@ "source": [ "requests.post(f\"{druid_host}/druid/indexer/v1/supervisor\", json.dumps(ingestion_spec), headers=druid_headers)\n", "druid.sql.wait_until_ready(table_name, verify_load_status=False)\n", + "time.sleep(60) # wait a moment for the data to become available\n", "display.table(f'{table_name}')" ] }, @@ -729,7 +751,8 @@ "outputs": [], "source": [ "requests.post(f\"{druid_host}/druid/indexer/v1/supervisor\", json.dumps(ingestion_spec), headers=druid_headers)\n", - "druid.sql.wait_until_ready(table_name, verify_load_status=False)" + "druid.sql.wait_until_ready(table_name, verify_load_status=False)\n", + "time.sleep(60) # wait a moment for the data to become available" ] }, { diff --git a/notebooks/03-query/07-functions-datetime.ipynb b/notebooks/03-query/07-functions-datetime.ipynb index ff42b82b..b002e968 100644 --- a/notebooks/03-query/07-functions-datetime.ipynb +++ b/notebooks/03-query/07-functions-datetime.ipynb @@ -136,7 +136,9 @@ "id": "9c3d6b39-6551-4b2a-bdfb-9606aa92c853", "metadata": {}, "source": [ - "Finally, run the following cell to import additional Python modules that you will use to create visuals as part of the notebook." + "### Import additional modules\n", + "\n", + "Finally, run the following cell to import additional Python modules that you will use to create visuals and to force a pause in the notebooks." ] }, { @@ -148,7 +150,8 @@ "source": [ "import matplotlib\n", "import matplotlib.pyplot as plt\n", - "import pandas as pd" + "import pandas as pd\n", + "import time" ] }, { @@ -377,7 +380,9 @@ "* Reading secondary dimensions from a table using `MILLIS_TO_TIMESTAMP`.\n", "* Filtering data using secondary dimensions.\n", "\n", - "Run the cell below to create a new dimension - a secondary timestamp - that represents the end timestamp of each session." + "Run the cell below to create a new dimension - a secondary timestamp - that represents the end timestamp of each session.\n", + "\n", + "Notice the addition of the \"ended_at\" column, which is calculated using a number of time functions." ] }, { @@ -416,7 +421,8 @@ "\n", "display.run_task(sql)\n", "sql_client.wait_until_ready('example-koalas-fndatetime')\n", - "display.table('example-koalas-fndatetime')" + "display.table('example-koalas-fndatetime')\n", + "time.sleep(60) # wait a moment for the data to become available" ] }, { diff --git a/notebooks/03-query/08-functions-strings.ipynb b/notebooks/03-query/08-functions-strings.ipynb index 798c8714..4017f0bc 100644 --- a/notebooks/03-query/08-functions-strings.ipynb +++ b/notebooks/03-query/08-functions-strings.ipynb @@ -151,7 +151,8 @@ "source": [ "import matplotlib\n", "import matplotlib.pyplot as plt\n", - "import pandas as pd" + "import pandas as pd\n", + "import time" ] }, { @@ -531,7 +532,8 @@ "\n", "display.run_task(sql)\n", "sql_client.wait_until_ready('example-koalas-strings')\n", - "display.table('example-koalas-strings')" + "display.table('example-koalas-strings')\n", + "time.sleep(60) # wait a moment for the data to become available" ] }, { @@ -744,7 +746,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.3" + "version": "3.11.6" } }, "nbformat": 4, diff --git a/notebooks/03-query/19-groupby-earliest.ipynb b/notebooks/03-query/19-groupby-earliest.ipynb index 5de89516..97237125 100644 --- a/notebooks/03-query/19-groupby-earliest.ipynb +++ b/notebooks/03-query/19-groupby-earliest.ipynb @@ -89,12 +89,11 @@ "id": "472589e4-1026-4b3b-bb79-eedabb2b44c4", "metadata": {}, "source": [ - "\n", "### Load example data\n", "\n", "Once your Druid environment is up and running, ingest the sample data for this tutorial.\n", "\n", - "Run the following cell to create a table called `example-koalas-groupby`. Notice only columns required for this notebook are ingested from the overall sample dataset.\n", + "Run the following cell to create a table. Notice only columns required for this notebook are ingested from the overall sample dataset.\n", "\n", "This ingestion is also an example of roll up ingestion. \n", "- It aggregates by 15 minute blocks:\n", @@ -110,9 +109,6 @@ " LATEST_BY(\"session_length\",TIME_PARSE(\"timestamp\")) AS \"latest_session_length\"\n", "\n", " ```\n", - "LATEST and EARLIEST aggregations store a data structure in the database that holds the time of the latest or earliest value and the value itself. This allows it to be further aggregated across any combination of dimensions at query time.\n", - "\n", - "Such aggregate columns created at ingestion time, cannot then be used by EARLIEST_BY, LATEST_BY functions on an alternate time column. The reason is that the column's internal values were built with a different timeline and are therefore not comparable to a different timeline.\n", "\n", "When completed, you'll see table details." ] @@ -124,8 +120,10 @@ "metadata": {}, "outputs": [], "source": [ + "table_name = \"example-koalas-groupby\"\n", + "\n", "sql='''\n", - "REPLACE INTO \"example-koalas-groupby\" OVERWRITE ALL\n", + "REPLACE INTO \"''' + table_name + '''\" OVERWRITE ALL\n", "WITH \"ext\" AS (SELECT *\n", "FROM TABLE(\n", " EXTERN(\n", @@ -148,8 +146,8 @@ "'''\n", "\n", "display.run_task(sql)\n", - "sql_client.wait_until_ready('example-koalas-groupby')\n", - "display.table('example-koalas-groupby')" + "sql_client.wait_until_ready(table_name)\n", + "display.table(table_name)" ] }, { @@ -204,7 +202,7 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " \"loaded_image\",\n", " ROUND(AVG(\"latest_session_length\"),0) AS \"timetakenms_average\",\n", @@ -212,7 +210,7 @@ " MIN(\"latest_session_length\") AS \"timetakenms_min\",\n", " COUNT(*) AS \"count\",\n", " COUNT(DISTINCT \"country\") AS \"countries\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "GROUP BY 1\n", "'''\n", @@ -253,13 +251,13 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " \"loaded_image\",\n", " STRING_AGG(DISTINCT \"continent\", ',') AS \"string\",\n", " ARRAY_AGG(DISTINCT \"continent\") AS \"array\",\n", " count(*) AS \"count\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "GROUP BY 1\n", "'''\n", @@ -286,12 +284,12 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " \"continent\",\n", " EARLIEST_BY(\"country\",\"__time\",1024) AS \"earliest_country\",\n", " LATEST_BY(\"country\",\"__time\",1024) AS \"latest_country\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "GROUP BY 1\n", "'''\n", @@ -306,12 +304,12 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " \"continent\", \n", " EARLIEST(\"latest_session_length\" ) AS \"earliest_session_length\",\n", " LATEST(\"latest_session_length\" ) AS \"latest_session_length\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "GROUP BY 1\n", "'''\n", @@ -340,14 +338,14 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " REGEXP_EXTRACT(\"loaded_image\",'([a-zA-Z0-9\\s_\\\\.\\-\\(\\):])+(.jpg)$') AS \"loaded_image_filename\",\n", - " avg(session_length) AS \"timetakenms_average\",\n", - " max(session_length) AS \"timetakenms_max\",\n", - " min(session_length) AS \"timetakenms_min\",\n", + " avg(latest_session_length) AS \"timetakenms_average\",\n", + " max(latest_session_length) AS \"timetakenms_max\",\n", + " min(latest_session_length) AS \"timetakenms_min\",\n", " count(*) AS \"count\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "GROUP BY 1\n", "ORDER BY 2 DESC\n", @@ -373,11 +371,11 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " TIME_EXTRACT(\"__time\", 'HOUR') AS \"time\",\n", " count(*) AS \"count\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T00:00:00/2019-08-30T00:00:00')\n", "GROUP BY 1\n", "'''\n", @@ -404,14 +402,14 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " TIME_EXTRACT(\"__time\", 'HOUR') AS \"time\",\n", " TIME_EXTRACT(\"__time\", 'HOUR', 'America/Los_Angeles') AS \"time_LA\",\n", " TIME_EXTRACT(\"__time\", 'HOUR', 'Europe/Copenhagen') AS \"time_Cop\",\n", " TIME_EXTRACT(\"__time\", 'HOUR', 'Asia/Shanghai') AS \"time_Sha\",\n", " count(*) AS \"count\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T00:00:00/2019-08-26T00:00:00')\n", "GROUP BY 1,2,3,4\n", "ORDER BY 2 ASC\n", @@ -437,12 +435,12 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " STRING_FORMAT('%tR',TIME_FLOOR(\"__time\", 'PT1H')) AS \"time\",\n", " count(*) AS \"count\",\n", - " sum(session_length) AS \"timetakenms\"\n", - "FROM \"example-koalas-groupby\"\n", + " sum(latest_session_length) AS \"timetakenms\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T00:00:00/2019-08-26T00:00:00')\n", "GROUP BY 1\n", "'''\n", @@ -499,14 +497,14 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " REGEXP_EXTRACT(\"loaded_image\",'([a-zA-Z0-9\\s_\\\\.\\-\\(\\):])+(.jpg)$') AS \"loaded_image_filename\",\n", - " avg(session_length) AS \"timetakenms_average\",\n", - " max(session_length) AS \"timetakenms_max\",\n", - " min(session_length) AS \"timetakenms_min\",\n", + " avg(latest_session_length) AS \"timetakenms_average\",\n", + " max(latest_session_length) AS \"timetakenms_max\",\n", + " min(latest_session_length) AS \"timetakenms_min\",\n", " count(*) AS \"count\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "AND \"loaded_image\" LIKE '%jpg'\n", "GROUP BY 1\n", @@ -543,14 +541,14 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " REGEXP_EXTRACT(\"loaded_image\",'([a-zA-Z0-9\\s_\\\\.\\-\\(\\):])+(.jpg)$') AS \"loaded_image_filename\",\n", - " avg(session_length) AS \"timetakenms_average\",\n", - " max(session_length) AS \"timetakenms_max\",\n", - " min(session_length) AS \"timetakenms_min\",\n", + " avg(latest_session_length) AS \"timetakenms_average\",\n", + " max(latest_session_length) AS \"timetakenms_max\",\n", + " min(latest_session_length) AS \"timetakenms_min\",\n", " count(*) AS \"count\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "GROUP BY 1\n", "HAVING \"loaded_image_filename\" IS NOT NULL\n", @@ -579,14 +577,14 @@ }, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " REGEXP_EXTRACT(\"loaded_image\",'([a-zA-Z0-9\\s_\\\\.\\-\\(\\):])+(.jpg)$') AS \"loaded_image_filename\",\n", - " avg(session_length) AS \"timetakenms_average\",\n", - " max(session_length) AS \"timetakenms_max\",\n", - " min(session_length) AS \"timetakenms_min\",\n", + " avg(latest_session_length) AS \"timetakenms_average\",\n", + " max(latest_session_length) AS \"timetakenms_max\",\n", + " min(latest_session_length) AS \"timetakenms_min\",\n", " count(*) AS \"count\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "AND \"loaded_image\" LIKE '%jpg'\n", "GROUP BY 1\n", @@ -616,12 +614,12 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " REGEXP_EXTRACT(\"loaded_image\",'([a-zA-Z0-9\\s_\\\\.\\-\\(\\):])+(.jpg)$') AS \"loaded_image_filename\",\n", " count(*) FILTER (WHERE \"os\" LIKE 'OS %') AS \"count_OSX\",\n", " count(*) FILTER (WHERE \"os\" LIKE 'Windows %') AS \"count_windows\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "AND \"loaded_image\" LIKE '%jpg'\n", "GROUP BY 1\n", @@ -658,13 +656,13 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " \"browser\",\n", " \"os\",\n", - " max(session_length) AS \"max_session\",\n", + " max(latest_session_length) AS \"max_session\",\n", " count(*) AS \"count\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "AND \"os\" LIKE 'Windows%'\n", "GROUP BY 1, 2\n", @@ -692,13 +690,13 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " \"browser\",\n", " \"os\",\n", - " max(session_length) AS \"max_session\",\n", + " max(latest_session_length) AS \"max_session\",\n", " count(*) AS \"count\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "AND \"os\" LIKE 'Windows%'\n", "GROUP BY GROUPING SETS (\"browser\",\"os\")\n", @@ -726,14 +724,14 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " \"continent\",\n", " \"browser\",\n", " \"os\",\n", - " max(session_length) AS \"max_session\",\n", + " max(latest_session_length) AS \"max_session\",\n", " count(*) AS \"count\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "AND \"os\" LIKE 'Windows%'\n", "AND \"continent\" LIKE '%America'\n", @@ -766,14 +764,14 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " \"continent\",\n", " \"browser\",\n", " \"os\",\n", - " max(session_length) AS \"max_session\",\n", + " max(latest_session_length) AS \"max_session\",\n", " count(*) AS \"count\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "AND \"os\" LIKE 'OS %'\n", "AND \"continent\" LIKE '%America'\n", @@ -819,14 +817,14 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " \"continent\",\n", " \"browser\",\n", " \"os\",\n", - " max(session_length) AS \"max_session\",\n", + " max(latest_session_length) AS \"max_session\",\n", " count(*) AS \"count\"\n", - "FROM \"example-koalas-groupby\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T10:00:00/2019-08-25T18:00:00')\n", "AND \"os\" LIKE 'OS %'\n", "AND \"continent\" LIKE '%America'\n", @@ -870,12 +868,12 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " TIME_FLOOR(\"__time\", 'PT1H') AS \"time\",\n", " count(*) AS \"count\",\n", - " sum(session_length) AS \"timetakenms\"\n", - "FROM \"example-koalas-groupby\"\n", + " sum(latest_session_length) AS \"timetakenms\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T00:00:00/2019-08-26T00:00:00')\n", "GROUP BY 1\n", "'''\n", @@ -902,13 +900,13 @@ "metadata": {}, "outputs": [], "source": [ - "sql='''\n", + "sql=f'''\n", "SELECT\n", " TIME_FLOOR(\"__time\", 'PT1H') AS \"__time_by_hour\",\n", " \"os\",\n", " count(*) AS \"count\",\n", - " sum(session_length) AS \"timetakenms\"\n", - "FROM \"example-koalas-groupby\"\n", + " sum(latest_session_length) AS \"timetakenms\"\n", + "FROM \"{table_name}\"\n", "WHERE TIME_IN_INTERVAL(\"__time\", '2019-08-25T04:00:00/2019-08-25T06:00:00')\n", "GROUP BY 1,2\n", "'''\n", @@ -943,7 +941,7 @@ "metadata": {}, "outputs": [], "source": [ - "druid.datasources.drop(\"example-koalas-groupby\")" + "druid.datasources.drop(table_name)" ] }, {