Skip to content

Parse Enum type names that omit element numbers - #1190

Merged
joe-clickhouse merged 5 commits into
ClickHouse:mainfrom
anubhavlal07:fix/enum-implicit-values
Nov 16, 2026
Merged

joe-clickhouse merged 5 commits into
ClickHouse:mainfrom
anubhavlal07:fix/enum-implicit-values

Conversation

@anubhavlal07

@anubhavlal07 anubhavlal07 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #1189.

parse_enum expected every element to be 'name' = number, so a type name like Enum8('a', 'b') failed with ValueError: invalid literal for int() with base 10: ''. This hit get_from_name and inserts that pass column_type_names, including the Nullable, Array, Tuple and Map forms.

I changed parse_enum so the = number part is optional, and it fills in the missing numbers the way the server does in autoAssignNumberForEnum (src/DataTypes/DataTypeEnum.cpp):

  • the base is 1, or the first element's number when the first element has one
  • an element without a number at index i gets base + i
  • the elements after the first must all have a number or all omit it. Other mixes still raise ValueError, and so does 'a' = with no number

The numbers are filled in before the bare Enum picks Enum8 or Enum16, so Enum('a' = 127, 'b') becomes Enum16('a' = 127, 'b' = 128).

Tests: a parametrized test checks get_from_name(...).name for scalar, Nullable and Array forms, a negative base, an escaped quote in a name, 'x=y' as a name, and the Enum16 change. Another checks the inner Enum types for Tuple and Map (their own names keep the input string as written, same as on main), and a third checks that the mixed forms are rejected. tests/unit_tests/test_driver/test_parser.py: 122 passed; the new cases fail on main.

I used Claude Code to help prepare this change; I reviewed the diff and ran the tests locally.

Checklist

  • Unit tests covering the common scenarios were added (no integration test; the change is parser-only)
  • A human-readable description of the changes was provided to include in CHANGELOG

Note

Low Risk
Parser-only behavior with unit test coverage; no wire format or insert encoding changes beyond correct type resolution from type names.

Overview
parse_enum no longer requires every enum member to use 'name' = number. Types such as Enum8('a', 'b'), mixed forms like Enum8('a' = 5, 'b'), and nested uses (Nullable, Array, Tuple, Map) now parse and canonicalize to explicit numbers using ClickHouse-style rules: base 1 when the first member has no value, otherwise the first member’s number, then base + index for any following members that omit a value. Elements after the first must either all specify values or all omit them; invalid mixes still raise ValueError.

get_from_name and inserts that rely on column_type_names (for example bare Enum('a','b') resolving to Enum8('a' = 1, 'b' = 2) or Enum('a' = 127, 'b') to Enum16(...)) stop failing with empty-int conversion errors. CHANGELOG documents the fix; test_parser.py adds parametrized success cases and rejection tests for malformed omitted-value syntax.

Reviewed by Cursor Bugbot for commit 0465a67. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread clickhouse_connect/driver/parser.py Resolved
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

AI review gate — Human approval in place of AI review

Approved on the head commit by joe-clickhouse (write access, not the author), standing in for the AI review:

  • Cursor Bugbot is still reviewing this commit.

What to do:

  • Nothing to do yet if the review is running. The gate turns green when it finishes clean.
  • No review showing up? Post bugbot run as a new top-level PR comment. If that does nothing, Bugbot is probably not enabled for this repository: ask a repository administrator.

Evaluated at 0465a67e. This required workflow does not re-run on its own once the AI review later concludes — check the Cursor Bugbot check on this commit directly for its current state.

@joe-clickhouse

joe-clickhouse commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Pushed a small follow-up on top of your branch. parse_enum now raises when the names and values don't line up, so a missing comma like Enum8('a' 'b', 'c') no longer drops a label. Added those cases to the reject test. Thanks for the fix!

Signed-off-by: Joe Spadola <joe.spadola@clickhouse.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit dd70c59. Configure here.

Comment thread clickhouse_connect/driver/parser.py Resolved
@joe-clickhouse
joe-clickhouse requested a review from a team as a code owner November 16, 2026 22:49
@joe-clickhouse
joe-clickhouse merged commit 7a58313 into ClickHouse:main Nov 16, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enum type names without explicit values (Enum8('a', 'b')) fail to parse: ValueError: invalid literal for int() with base 10: ''

3 participants