Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Apache Druid Values Query

From Leeroopedia
Revision as of 14:16, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Apache_Druid_Values_Query.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Web_Console, SQL_Generation
Last Updated 2026-02-10 10:00 GMT

Overview

Converts a Druid QueryResult into a SQL VALUES query that reproduces the result set as an inline table.

Description

The Values Query module transforms a druid-query-toolkit QueryResult (with typed header columns and rows) into a SQL SELECT ... FROM (VALUES ...) query. It handles type-specific serialization: COMPLEX<json> values are wrapped in PARSE_JSON, array columns are encoded with a separator and decoded via STRING_TO_ARRAY, COMPLEX binary types use DECODE_BASE64_COMPLEX, and standard types receive appropriate CAST expressions. The module also corrects for a legacy Druid behavior where ARRAY types may be described inconsistently in column metadata.

Usage

Used when exporting query results as SQL format in the download utilities, and in other scenarios where query results need to be materialized as inline SQL VALUES expressions.

Code Reference

Source Location

Signature

export function queryResultToValuesQuery(sample: QueryResult): SqlQuery;

Import

import { queryResultToValuesQuery } from './utils/values-query';

I/O Contract

Inputs

Name Type Required Description
sample QueryResult Yes A druid-query-toolkit QueryResult containing typed header columns and row data

Outputs

Name Type Description
(return) SqlQuery A SqlQuery AST representing SELECT ... FROM (VALUES (...), (...)) AS t(c1, c2, ...) with appropriate casts and type conversions per column

Usage Examples

Convert query results to a VALUES query

import { queryResultToValuesQuery } from './utils/values-query';

const valuesQuery = queryResultToValuesQuery(queryResult);
const sql = valuesQuery.toString();
// Produces: SELECT CAST("c1" AS VARCHAR) AS "channel", CAST("c2" AS BIGINT) AS "count"
// FROM (VALUES ('en', 100), ('de', 50)) AS "t" ("c1", "c2")

Use with download utilities

import { queryResultsToString } from './utils/download';

const sqlString = queryResultsToString(queryResult, 'sql');
// Internally calls queryResultToValuesQuery and converts to string

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment