Skip to content

[client-v2] Reject Enum type names with a repeated value or name - #3368

Open
Indian-boult wants to merge 1 commit into
ClickHouse:mainfrom
Indian-boult:fix/enum-duplicates
Open

Indian-boult wants to merge 1 commit into
ClickHouse:mainfrom
Indian-boult:fix/enum-duplicates

Conversation

@Indian-boult

@Indian-boult Indian-boult commented Nov 18, 2026 •

Copy link
Copy Markdown

Summary

This PR builds on #3366, which is not merged yet. The first commit and the merge from main are the same as in #3366. Only the last commit is new here. I will rebase onto main after #3366 is merged, so the diff then shows only this change.

ClickHouseEnum did not check its entries for repeats. Enum8('a' = 1, 'b' = 1) and Enum8('a' = 1, 'a' = 2) parsed fine in the client, while the server rejects both with Duplicate values in enum and Duplicate names in enum. With an application schema built from such a type, b was written as 1 and read back as a.

Both constructors now check for a repeated value or name and throw IllegalArgumentException with the two entries in the message. The check runs after the implicit numbers from #3366 are given, so Enum8('a', 'b' = 1) fails the same way as on the server. The String[], int[] constructor has two callers in the code, ClickHouseEnum.of(Class) and the Dynamic type decoder in BinaryStreamReader. Java enums and server type names never repeat, so those paths are not affected. There is no range check, since older servers accept values outside the Enum8 range.

Compatibility. A type that the server rejects now fails in the client at parse time instead of writing wrong data. new ClickHouseEnum(String[], int[]) is public and now throws for repeats. No other API changes.

Tests. ClickHouseColumnTest has a data provider with repeated values, repeated names and an implicit value that clashes with an explicit one, plus a check for the array constructor and a case that shows names differing only in case are still allowed. The failure happens in the client before any request, so there is no new integration test. I ran DataTypeTests and RowBinaryFormatWriterTest against a 26.10 server to check the Dynamic decoder.

Closes #3349

Checklist

Update by Indian-boult, 22 Nov 2026 17:35 UTC. Rebased onto main as one commit, so this PR no longer depends on #3366 and the diff shows only the duplicate check. The test cases that needed implicit numbers from #3366 are gone. Two cases are new, a name with = inside and names that differ only in case.


Note

Medium Risk
Stricter validation at parse time may break apps that previously built invalid Enum schemas; behavior now aligns with the server and prevents silent wrong read/write mappings.

Overview
Enum type parsing now rejects invalid definitions that ClickHouse would reject on the server. ClickHouseEnum adds a checkUnique step in both the parameter-list and String[]/int[] constructors so duplicate enum names or duplicate numeric values fail immediately with an IllegalArgumentException naming the conflicting entries.

That validation runs when application-written type strings (e.g. ClickHouseColumn.of) build enum metadata, including nested types such as Tuple(..., Nullable(Enum8(...))). Case-distinct names (e.g. 'a' vs 'A') remain valid.

Unit tests cover repeated values/names, nested parsing, the array constructor, and a changelog entry for client-v2/jdbc-v2 (#3349).

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

ClickHouseEnum did not check for repeated values or names, so a type like
Enum8('a' = 1, 'b' = 1) was accepted. Both labels were written with the
same value and 'b' read back as 'a'. The server rejects these types.

Check both constructors and throw IllegalArgumentException that names the
two entries.

Closes ClickHouse#3349
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.

[client-v2] Enum type parsing accepts duplicate ordinals and duplicate labels: Enum8('a' = 1, 'b' = 1) silently stores 'b' as 'a'

1 participant