Implementation:Apache Druid DemoQueries
| Knowledge Sources | |
|---|---|
| Domains | Web Console, Query Workbench |
| Last Updated | 2026-02-10 10:00 GMT |
Overview
Defines a set of demo SQL queries for the Apache Druid web console workbench, showcasing the sql-msq-task engine's ingestion and query capabilities.
Description
This module exports a getDemoQueries() function that returns an array of TabEntry objects, each containing a pre-configured WorkbenchQuery with a demo SQL query string. The demos form a progressive tutorial that guides users through the multi-stage query (MSQ) task engine features: basic data ingestion from external sources, data transformation with rollup, data enrichment via JOINs, re-ingestion from existing datasources, data filtering/deletion, inline SELECT queries, and large-scale sorting. All queries use a base context of maxNumTasks: 2.
Usage
Called by the workbench view to populate the demo tabs when the user activates the demo mode. Each returned TabEntry becomes a separate query tab in the workbench editor.
Code Reference
Source Location
- Repository: Apache Druid
- File: web-console/src/views/workbench-view/demo-queries.ts
- Lines: 1-306
Signature
export function getDemoQueries(): TabEntry[]
Import
import { getDemoQueries } from './demo-queries';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | - | - | This function takes no parameters. |
Outputs
| Name | Type | Description |
|---|---|---|
| TabEntry[] | TabEntry[] |
An array of 7 demo tab entries, each with an id, tabName, and a WorkbenchQuery containing a SQL query string and context configuration.
|
Usage Examples
Loading Demo Queries into the Workbench
import { getDemoQueries } from './demo-queries';
const demoTabs = getDemoQueries();
// demoTabs is an array of TabEntry objects:
// [
// { id: 'demo1', tabName: 'Demo 1', query: WorkbenchQuery },
// { id: 'demo2', tabName: 'Demo 2', query: WorkbenchQuery },
// ...
// { id: 'demo6', tabName: 'Demo 6', query: WorkbenchQuery },
// ]
Demo Query Descriptions
| Demo | Title | Engine | Description |
|---|---|---|---|
| Demo 1 | Basic Ingestion | sql-msq-task (default) | Reads a JSON file from an HTTP source using TABLE(EXTERN(...)) and writes it into the kttm_simple datasource using REPLACE INTO ... OVERWRITE ALL. Demonstrates the simplest possible ingestion (SELECT *).
|
| Demo 2 | Rollup Ingestion | sql-msq-task (default) | Builds on Demo 1 by selecting specific columns, parsing timestamps, filtering rows (iOS only), applying GROUP BY for rollup with aggregates (COUNT, SUM, APPROX_COUNT_DISTINCT_DS_HLL), and using PARTITIONED BY HOUR with CLUSTERED BY.
|
| Demo 3 | JOIN Enrichment | sql-msq-task (default) | Extends Demo 2 by JOINing with an external TSV file (country lookup) to add Capital and ISO3 columns. Also demonstrates computed columns (browser_major via REGEXP_EXTRACT).
|
| Demo 4a | Re-ingestion from Druid | sql-msq-task (default) | Same transformation as Demo 3, but reads from the kttm_simple datasource (created in Demo 1) instead of external data. Demonstrates mixing Druid tables with external data sources.
|
| Demo 4b | Data Deletion | sql-msq-task (default) | Reads from and writes to the same datasource (kttm_simple), filtering out all rows for 'New Zealand'. Demonstrates in-place data transformation.
|
| Demo 5 | Inline SELECT | sql-msq-task (default) | Runs a SELECT query without REPLACE/INSERT, computing aggregates (COUNT DISTINCT) across external data with JOINs. Demonstrates the MSQ engine for ad-hoc queries. |
| Demo 6 | Large-Scale Sorting | sql-msq-task (explicit) | Re-sorts the kttm_simple datasource on arbitrary columns (session, number). Demonstrates sorting capabilities that are not possible with the native SQL engine.
|
Internals
Base Query Configuration
All demo queries are built from a base WorkbenchQuery with:
const BASE_QUERY = WorkbenchQuery.blank().changeQueryContext({ maxNumTasks: 2 });
This limits the MSQ engine to 2 concurrent tasks, suitable for demo/testing environments.
Data Sources Used
- External HTTP:
https://static.imply.io/example-data/kttm-v2/kttm-v2-2019-08-25.json.gz(JSON format) - External HTTP:
https://static.imply.io/example-data/lookup/countries.tsv(TSV format) - Druid datasource:
kttm_simple(created by Demo 1, used by Demos 4a, 4b, 6)
Demo 6 Engine Override
Demo 6 is the only demo that explicitly sets the engine to sql-msq-task via .changeEngine('sql-msq-task'), as it runs a SELECT without INSERT/REPLACE which would otherwise default to the native engine.