Registry / database / druid-sql-parser

druid-sql-parser

JSON →
library1.2.7jsnpmunverified

A SQL parser and stringifier specifically for Apache Druid SQL syntax, version 1.2.7. It produces an AST (Abstract Syntax Tree) from Druid SQL queries and can serialize ASTs back to SQL strings. The library is lightweight with no dependencies, focusing on Druid-specific SQL features such as double-quoted identifiers and system tables like sys.server_segments. It is not a general SQL parser; it does not support all SQL dialects nor standard SQL fully. The package is stable with infrequent releases, last updated in early 2022. Differentiators: zero dependencies, simple API (parse and stringify), Druid-specific syntax support.

npm install druid-sql-parser
INSTALL
IMPORT
SIG · DRUID-SQL-PARSER
D
druid-sql-parser
databasejavascriptv1.2.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import { parse } from 'druid-sql-parser';
const parse = require('druid-sql-parser').parse;
ESM default export is an object with parse/stringify methods. Named export preferred.
stringify
import { stringify } from 'druid-sql-parser';
const { stringify } = require('druid-sql-parser').stringify;
Same as parse.
default
import parser from 'druid-sql-parser';
const parser = require('druid-sql-parser')();
Default import yields an object with parse and stringify methods. Not a function.

Parses a Druid SQL query into an AST, then converts the AST back to SQL string.

import { parse, stringify } from 'druid-sql-parser'; const ast = parse('SELECT "server" FROM sys.server_segments'); console.log(ast); // Output: { type: 'query', queryType: 'SELECT', ... } const sql = stringify(ast); console.log(sql); // Output: SELECT "server" FROM sys.server_segments
Debug
Known issues
gotchaThe parser does not support all standard SQL features such as JOINs or subqueries beyond basic SELECT.
fix
Use a more comprehensive SQL parser if you need general SQL support.
affects: <=1.2.7
gotchaQuoting identifiers with double quotes is required for Druid SQL, but the parser may not handle all edge cases like embedded quotes.
fix
Ensure identifiers are properly double-quoted; escape internal double quotes by doubling them.
affects: <=1.2.7
deprecatedThis package has not been updated since early 2022; Druid SQL syntax may have evolved.
fix
Check for newer versions or fork the repository for updates.
affects: <=1.2.7
gotchaThe default export is an object, not a function. Common mistake: calling it as a constructor.
fix
Use named exports: import { parse, stringify } from 'druid-sql-parser'.
affects: <=1.2.7
Errors
Common errors & fixes
TypeError: parser is not a function
Default import used as a function call.
fix
Use import parser from 'druid-sql-parser' and then parser.parse(sql).
SyntaxError: Unexpected token at line 1 column 1
Passing a non-SQL string or malformed SQL to parse().
fix
Ensure the input is a valid Druid SQL string.
Error: Unsupported query type
The parser only handles SELECT statements; other types like INSERT or CREATE are not supported.
fix
Only use SELECT queries with this parser.
Upgrade
Version history
1.2.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
Bingbot
1
Resources
druid-sql-parser — npm install druid-sql-parser · libregistry