Implementation:Apache Druid Joda To Regexp
| Knowledge Sources | |
|---|---|
| Domains | Web_Console, Date_Time_Parsing |
| Last Updated | 2026-02-10 10:00 GMT |
Overview
Converts Joda-Time format strings into equivalent JavaScript regular expressions for date pattern validation.
Description
This module provides a lookup table mapping Joda-Time format fragments (such as YYYY, MM, dd, HH, mm, ss, SSS) to their corresponding regular expression patterns. The single exported function `jodaFormatToRegExp` replaces each recognized Joda fragment in a format string with its regex equivalent and returns a case-insensitive RegExp anchored with ^ and $. This enables validation of date strings against Joda-Time formats commonly used in Druid ingestion specifications.
Usage
Used during data ingestion configuration to validate that sample date strings match the user-specified Joda-Time format pattern, helping detect format mismatches before ingestion begins.
Code Reference
Source Location
- Repository: Apache Druid
- File: web-console/src/utils/joda-to-regexp.ts
- Lines: 1-77
Signature
export function jodaFormatToRegExp(jodaFormat: string): RegExp;
Import
import { jodaFormatToRegExp } from './utils/joda-to-regexp';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| jodaFormat | string |
Yes | A Joda-Time format string (e.g., "yyyy-MM-dd'T'HH:mm:ss.SSS") |
Outputs
| Name | Type | Description |
|---|---|---|
| (return) | RegExp |
A case-insensitive RegExp anchored with ^ and $ that matches date strings conforming to the given Joda format |
Usage Examples
Validate a date string against a Joda format
import { jodaFormatToRegExp } from './utils/joda-to-regexp';
const regex = jodaFormatToRegExp('yyyy-MM-dd');
regex.test('2024-01-15'); // true
regex.test('24-1-5'); // false
Match a full datetime format
import { jodaFormatToRegExp } from './utils/joda-to-regexp';
const regex = jodaFormatToRegExp('yyyy-MM-dd HH:mm:ss');
regex.test('2024-01-15 09:30:00'); // true