Implementation:Apache Druid ExpressionMeta
| Knowledge Sources | |
|---|---|
| Domains | Web_Console, Explore_View |
| Last Updated | 2026-02-10 10:00 GMT |
Overview
An immutable value class representing a named SQL expression with optional alias, used as the metadata model for columns and dimensions in the explore view.
Description
The ExpressionMeta class wraps a SqlExpression with an optional alias (`as`) and derives a display name. It provides static methods for inflation from serialized values, creation from Column objects, and SQL type evaluation by matching column references against a column list. Instance methods support immutable changes via `change`, `changeAs`, `changeExpression`, and `applyRename` (which renames column references within the expression). The class implements `valueOf` for serialization and `equals` for identity comparison.
Usage
Used in the explore view as the model for split columns, show columns, and other expression-based parameters in module configurations. Instances are stored in parameter values and persisted to localStorage.
Code Reference
Source Location
- Repository: Apache Druid
- File: web-console/src/views/explore-view/models/expression-meta.ts
- Lines: 1-118
Signature
export interface ExpressionMetaValue {
expression: SqlExpression;
as?: string;
}
export class ExpressionMeta {
static MAX_NAME_LENGTH: number;
static inflate(value: any): ExpressionMeta | undefined;
static inflateArray(value: any): ExpressionMeta[];
static defaultNameFromExpression(expression: SqlExpression): string;
static fromColumn(column: Column): ExpressionMeta;
static evaluateSqlType(expression: SqlExpression, columns?: readonly Column[]): string | undefined;
public readonly expression: SqlExpression;
public readonly as?: string;
public readonly name: string;
constructor(value: ExpressionMetaValue);
valueOf(): ExpressionMetaValue;
equals(other: ExpressionMeta | undefined): boolean;
change(newValues: Partial<ExpressionMetaValue>): this;
changeAs(as: string): this;
changeExpression(expression: SqlExpression): this;
applyRename(rename: Map<string, string>): this;
evaluateSqlType(columns?: readonly Column[]): string | undefined;
}
Import
import { ExpressionMeta } from '../models/expression-meta';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| value | ExpressionMetaValue |
Yes | An object containing a SqlExpression and optional alias string |
| column | Column |
Yes | A druid-query-toolkit Column to create an ExpressionMeta from (static factory) |
| rename | Map<string, string> |
Yes | A column name rename mapping to apply to the expression |
| columns | readonly Column[] |
No | Column metadata for SQL type evaluation |
Outputs
| Name | Type | Description |
|---|---|---|
| (return) | ExpressionMeta |
A new or inflated ExpressionMeta instance |
| (return) | ExpressionMeta[] |
An array of inflated instances from serialized data (inflateArray) |
| (return) | undefined | The SQL type of the expression if it refers to a known column |
Usage Examples
Create from a column
import { ExpressionMeta } from '../models/expression-meta';
const meta = ExpressionMeta.fromColumn({ name: 'channel', sqlType: 'VARCHAR', nativeType: 'STRING' });
// meta.name === 'channel'
// meta.expression === C('channel')
Rename columns in an expression
const renamed = meta.applyRename(new Map([['channel', 'source']]));
// renamed.expression now references 'source' instead of 'channel'
Inflate from serialized data
const inflated = ExpressionMeta.inflate({ expression: '"channel"', as: 'Source' });
// inflated.name === 'Source'