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 ModuleState

From Leeroopedia


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

Overview

An immutable value class representing the complete state of an explore view module, including its identifier, filter expression, parameter values, and UI visibility flags.

Description

The ModuleState class encapsulates the configuration state of an explore view visualization module (e.g., time-chart, grouping-table, pie-chart, record-table). It stores the `moduleId`, a `moduleWhere` filter expression (defaulting to TRUE), a `parameterValues` dictionary, and boolean flags for `showModuleWhere` and `showControls`. The class provides immutable change methods, JSON serialization/deserialization via `fromJS` and `valueOf`, column rename propagation via `applyRename`, restriction to a query source via `restrictToQuerySource`, and smart column-to-module mapping via `applyShowColumn` and `applyShowMeasure`. A static `INIT_STATE` is initialized with the 'record-table' module.

Usage

Used as the primary state model for the explore view, persisted to localStorage, and updated by user interactions with module selectors, filter editors, and parameter controls.

Code Reference

Source Location

Signature

export class ModuleState {
  static INIT_STATE: ModuleState;
  static fromJS(js: any): ModuleState;

  public readonly moduleId: string;
  public readonly moduleWhere: SqlExpression;
  public readonly parameterValues: ParameterValues;
  public readonly showModuleWhere: boolean;
  public readonly showControls: boolean;

  constructor(value: ModuleStateValue);
  valueOf(): ModuleStateValue;
  change(newValues: Partial<ModuleStateValue>): ModuleState;
  changeModuleWhere(moduleWhere: SqlExpression): ModuleState;
  changeParameterValues(parameterValues: ParameterValues): ModuleState;
  applyRename(rename: Rename): ModuleState;
  restrictToQuerySource(querySource: QuerySource, where: SqlExpression): ModuleState;
  applyShowColumn(column: Column): ModuleState;
  applyShowMeasure(measure: Measure): ModuleState;
}

Import

import { ModuleState } from '../models/module-state';

I/O Contract

Inputs

Name Type Required Description
value / js ModuleStateValue Yes Object containing moduleId, optional moduleWhere, parameterValues, and UI flags
moduleWhere SqlExpression Yes A SQL filter expression scoped to the module
parameterValues ParameterValues Yes A dictionary of parameter name to value for the module's parameters
rename Rename (Map<string, string>) Yes A column rename mapping to propagate through parameter values
querySource QuerySource Yes The current query source to restrict filters and parameters against
column Column Yes A column to visualize, triggering automatic module selection
measure Measure Yes A measure to add to the current or a new module

Outputs

Name Type Description
(return) ModuleState A new ModuleState instance reflecting the requested changes
(return) ModuleStateValue A serializable plain object representation (valueOf)

Usage Examples

Create initial state and change module

import { ModuleState } from '../models/module-state';

const state = ModuleState.INIT_STATE;
// state.moduleId === 'record-table'

const newState = state.change({ moduleId: 'time-chart' });
// newState.moduleId === 'time-chart'

Apply show column to auto-select module

const column = { name: '__time', sqlType: 'TIMESTAMP', nativeType: 'LONG' };
const chartState = state.applyShowColumn(column);
// chartState.moduleId === 'time-chart'

Deserialize from localStorage

import { ModuleState } from '../models/module-state';

const saved = JSON.parse(localStorage.getItem('explore-state'));
const state = ModuleState.fromJS(saved);

Related Pages

Page Connections

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