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 Filter Pattern Helpers

From Leeroopedia


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

Overview

Provides helper functions for initializing, formatting, updating, and converting filter patterns in the explore view.

Description

The Filter Pattern Helpers module supplies utility functions that bridge between the druid-query-toolkit's FilterPattern type and the explore view's filter UI. It includes `initPatternForColumn` which creates a sensible default filter pattern based on column type (timeRelative for TIMESTAMP, numberRange for numerics, values for strings), `formatPatternWithoutNegation` for human-readable display of filter patterns, `patternToBoundsQuery` for generating SQL queries that evaluate the time bounds of a relative filter, and `addOrUpdatePattern`/`updateFilterPattern`/`updateFilterClause` for immutably managing lists of filter patterns.

Usage

Used in the explore view's filter panel to initialize default filters when a column is selected, render filter descriptions in the UI, resolve time-relative filter bounds, and update filter state when users add or modify filter conditions.

Code Reference

Source Location

Signature

export function initPatternForColumn(column: Column): FilterPattern;
export function formatPatternWithoutNegation(pattern: FilterPattern, timezone: Timezone): string;
export function patternToBoundsQuery(source: SqlQuery, filterPattern: FilterPattern): SqlQuery | undefined;
export function addOrUpdatePattern(
  patterns: readonly FilterPattern[],
  oldPattern: FilterPattern | undefined,
  newPattern: FilterPattern,
): FilterPattern[];
export function updateFilterPattern(
  patterns: readonly FilterPattern[],
  newPattern: FilterPattern,
): FilterPattern[];
export function updateFilterClause(filter: SqlExpression, clause: SqlExpression): SqlExpression;

Import

import { initPatternForColumn, formatPatternWithoutNegation, updateFilterClause } from '../utils/filter-pattern-helpers';

I/O Contract

Inputs

Name Type Required Description
column Column Yes A druid-query-toolkit Column used to determine the default filter pattern type
pattern / filterPattern FilterPattern Yes A filter pattern object (values, contains, regexp, timeInterval, timeRelative, numberRange, mvContains, or custom)
timezone Timezone Yes A chronoshift Timezone for formatting time-based filter patterns
source SqlQuery Yes The source SQL query to wrap when computing time bounds
patterns readonly FilterPattern[] Yes The current array of filter patterns to update
oldPattern undefined No The existing pattern to replace when adding or updating
newPattern FilterPattern Yes The new pattern to insert or replace with
filter SqlExpression Yes An existing WHERE expression to update with a new clause
clause SqlExpression Yes A new filter clause expression to merge into the existing filter

Outputs

Name Type Description
(return) FilterPattern A default filter pattern for the given column type
(return) string A human-readable description of the filter pattern
(return) undefined A SQL query that evaluates the start/end bounds of a timeRelative filter, or undefined for non-time patterns
(return) FilterPattern[] An updated array of filter patterns
(return) SqlExpression An updated WHERE expression with the new clause merged in

Usage Examples

Initialize a filter for a timestamp column

import { initPatternForColumn } from '../utils/filter-pattern-helpers';

const pattern = initPatternForColumn({ name: '__time', sqlType: 'TIMESTAMP' });
// pattern.type === 'timeRelative'
// pattern.rangeDuration === 'P1D'

Format a filter pattern for display

import { formatPatternWithoutNegation } from '../utils/filter-pattern-helpers';
import { Timezone } from 'chronoshift';

const description = formatPatternWithoutNegation(
  { type: 'values', negated: false, column: 'channel', values: ['en', 'de'] },
  Timezone.UTC,
);
// description === 'channel: en, de'

Update a filter pattern list

import { updateFilterPattern } from '../utils/filter-pattern-helpers';

const updated = updateFilterPattern(existingPatterns, newPattern);
// Replaces the pattern matching the same column, or appends if not found

Related Pages

Page Connections

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