Repository navigation
[client-v2] Reject Enum type names with a repeated value or name - #3368
Open
Indian-boult wants to merge 1 commit into
Open
Indian-boult wants to merge 1 commit into
Indian-boult wants to merge 1 commit into
Conversation
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
Indian-boult
force-pushed
the
fix/enum-duplicates
branch
from
November 22, 2026 17:35
72181c9 to
49854d3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)andEnum8('a' = 1, 'a' = 2)parsed fine in the client, while the server rejects both withDuplicate values in enumandDuplicate names in enum. With an application schema built from such a type,bwas written as 1 and read back asa.Both constructors now check for a repeated value or name and throw
IllegalArgumentExceptionwith the two entries in the message. The check runs after the implicit numbers from #3366 are given, soEnum8('a', 'b' = 1)fails the same way as on the server. TheString[], int[]constructor has two callers in the code,ClickHouseEnum.of(Class)and the Dynamic type decoder inBinaryStreamReader. 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.
ClickHouseEnumadds acheckUniquestep in both the parameter-list andString[]/int[]constructors so duplicate enum names or duplicate numeric values fail immediately with anIllegalArgumentExceptionnaming the conflicting entries.That validation runs when application-written type strings (e.g.
ClickHouseColumn.of) build enum metadata, including nested types such asTuple(..., 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.