Principle:Apache Druid Query Composition
| Knowledge Sources | |
|---|---|
| Domains | SQL_Querying, Developer_Experience |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
A code editing principle that provides an intelligent SQL/JSON editor with autocompletion, syntax highlighting, and schema-aware suggestions for composing Druid queries.
Description
Query Composition enables users to write Druid SQL or native JSON queries in a full-featured code editor. The editor provides:
- Syntax highlighting: Druid SQL keywords, functions, and identifiers colored for readability
- Autocompletion: Context-aware suggestions for SQL keywords, function names, table names, and column names from the discovered schema
- Multi-mode editing: Supports both SQL queries and native JSON queries
- Cursor tracking: Reports cursor position for error highlighting and prefix line calculation
The autocompletion engine combines static SQL keyword/function lists with dynamic schema metadata (table and column names) to provide relevant suggestions as the user types.
Usage
Use this principle during all query authoring activities. The editor is the primary input mechanism for the Workbench and is used for both ad-hoc queries and ingestion SQL.
Theoretical Basis
Query composition follows a schema-aware code completion pattern:
Completion Sources:
Static: SQL keywords (SELECT, FROM, WHERE, ...) + Druid functions (TIME_PARSE, APPROX_COUNT_DISTINCT, ...)
Dynamic: Table names + Column names from INFORMATION_SCHEMA
Completion Trigger:
User types → Ace editor fires changeSession → completer.getCompletions(prefix)
Returns: [{ value, meta, score }] ranked by relevance