Skip to content

Bug: parsing escaped enum names with multiple escape sequences #1839

Description

@claude

Summary

Enum names that contain escaped single quotes (e.g. DateTime(\'UTC\')) are not parsed correctly when:

  1. A single enum name contains more than one escape sequence, or
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions