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 QuerySource Introspection

From Leeroopedia


Knowledge Sources
Domains Visual_Exploration, Schema_Introspection
Last Updated 2026-02-10 00:00 GMT

Overview

Concrete class for creating a QuerySource from datasource introspection results in the Explore view.

Description

The QuerySource class provides the fromIntrospectResult static factory method that constructs a QuerySource from a LIMIT 0 query result. It:

  1. Filters out unsupported column types (OTHER except COMPLEX<json>)
  2. Extracts query-level measures if the source is a GROUP BY query
  3. Auto-detects measures for base tables (COUNT, SUM for numeric, APPROX_COUNT_DISTINCT for complex sketch types)
  4. Creates the makeLimitZeroIntrospectionQuery helper for efficient metadata-only queries

Usage

Call QuerySource.fromIntrospectResult() after running the introspection query. The resulting QuerySource drives the entire Explore view configuration.

Code Reference

Source Location

  • Repository: Apache Druid
  • File: web-console/src/views/explore-view/models/query-source.ts
  • Lines: L41-L409

Signature

export class QuerySource {
  static makeLimitZeroIntrospectionQuery(query: SqlQuery): SqlQuery

  static fromIntrospectResult(
    query: SqlQuery,
    baseColumns: readonly Column[],
    columns: readonly Column[],
  ): QuerySource

  public readonly query: SqlQuery;
  public readonly baseColumns: readonly Column[];
  public readonly columns: readonly Column[];
  public readonly measures: Measure[];
}

Import

import { QuerySource } from './models/query-source';

I/O Contract

Inputs

Name Type Required Description
query SqlQuery Yes The base SQL query (typically SELECT * FROM datasource)
baseColumns Column[] Yes Original columns from the base table
columns Column[] Yes Columns from the LIMIT 0 result (may differ if query has GROUP BY)

Outputs

Name Type Description
QuerySource QuerySource Object with columns array, measures array, and source query

Usage Examples

Introspecting a Datasource

import { QuerySource } from './models/query-source';

const baseQuery = SqlQuery.parse('SELECT * FROM "events"');
const introspectionQuery = QuerySource.makeLimitZeroIntrospectionQuery(baseQuery);
// introspectionQuery = SELECT * FROM (SELECT * FROM "events") LIMIT 0

const result = await runSqlQuery(introspectionQuery);

const querySource = QuerySource.fromIntrospectResult(
  baseQuery,
  result.columns,
  result.columns,
);

// querySource.columns = [
//   { name: '__time', sqlType: 'TIMESTAMP' },
//   { name: 'user', sqlType: 'VARCHAR' },
//   { name: 'count', sqlType: 'BIGINT' },
// ]
// querySource.measures = [
//   Measure({ expression: SUM("count"), as: 'sum_count' }),
//   Measure.COUNT,
// ]

Related Pages

Implements Principle

Requires Environment

Page Connections

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