Summary
Enum names that contain escaped single quotes (e.g. DateTime(\'UTC\')) are not parsed correctly when:
- A single enum name contains more than one escape sequence, or
- Any earlier enum value contains escape sequences (positions bleed into the next value).
Root Cause
In lib/column/enum.go, extractEnumNamedValues has two bugs:
Bug 1 — skippedValueTokens is never reset between values
The slice that records backslash positions is declared before the main loop and is never cleared when a new string starts. Positions from a previous enum value are re-applied to the next value's foundName, corrupting it.
Bug 2 — stale positions when removing multiple backslashes
The removal loop (lines 152-154) applies the original source positions without adjusting for prior removals. Each removal shortens the slice by 1, so subsequent positions are off-by-one per preceding removal.
Reproducing Query
SELECT variantType(CAST(toDateTime('2024-01-15 10:30:00', 'UTC'), 'Variant(String, DateTime(\'UTC\'))'))
ClickHouse returns a value of type Enum8('String' = 0, 'DateTime(\'UTC\')' = 1). The Go client parses the enum name incorrectly, yielding a corrupted string instead of DateTime('UTC').
Related
Central tracking issue: ClickHouse/integrations-ai-playground#17
Summary
Enum names that contain escaped single quotes (e.g.
DateTime(\'UTC\')) are not parsed correctly when:Root Cause
In
lib/column/enum.go,extractEnumNamedValueshas two bugs:Bug 1 —
skippedValueTokensis never reset between valuesThe slice that records backslash positions is declared before the main loop and is never cleared when a new string starts. Positions from a previous enum value are re-applied to the next value's
foundName, corrupting it.Bug 2 — stale positions when removing multiple backslashes
The removal loop (lines 152-154) applies the original source positions without adjusting for prior removals. Each removal shortens the slice by 1, so subsequent positions are off-by-one per preceding removal.
Reproducing Query
ClickHouse returns a value of type
Enum8('String' = 0, 'DateTime(\'UTC\')' = 1). The Go client parses the enum name incorrectly, yielding a corrupted string instead ofDateTime('UTC').Related
Central tracking issue: ClickHouse/integrations-ai-playground#17