Repository navigation
Conversation
eabfd41 to
daa3d48
Compare
| enumValue = column.getEnumConstants().validate(((Number) value).intValue()); | ||
| } else if (value instanceof Enum<?>) { | ||
| enumValue = ((Enum<?>)value).ordinal(); | ||
| enumValue = column.getEnumConstants().value(((Enum<?>) value).name()); |
There was a problem hiding this comment.
here is integer changed to string. Would it work?
There was a problem hiding this comment.
It does work. ClickHouseEnum.value(String) looks up the declared integer for that name (for example ‘inactive’ → 10), so the Java enum is converted by name and the integer is what gets written. Before this change it wrote ordinal(), which is wrong whenever the declared values differ from the position. The new integration tests use values like 5/10 and 500/1000 to check this.
| private enum Status { active, inactive } | ||
|
|
||
| @Test(dataProvider = "nonNullableEnumTypes") | ||
| public void testNonMemberNumberIntoEnumThrows(String typeName) { |
There was a problem hiding this comment.
Please convert to integration tests and place in DataTypesTests (client and JDBC)
There was a problem hiding this comment.
Moved to DataTypeTests. They cover String, number and Java enum inputs for Enum8 and Enum16 (checking both the name and the stored integer), and the invalid number / undeclared name cases.Added to JdbcDataTypeTests with the row-binary writer enabled, so the call actually reaches serializeEnumData. One test inserts a valid number, one checks that a non-member number fails and Removed the unit tests I had added in SerializerUtilsTest. please check updated changes
chernser
left a comment
There was a problem hiding this comment.
Thank you for the contribution!
please see comments.
integration tests should be added in both client-v2 and jdbc-v2
Thanks!
AI review gate — the gate never ran on this headThe org-required gate workflow has no run on What to do: a maintainer runs History (latest 5 heads, newest first)
|
|
Thank you for the update! So current change is good and looks correct. However we need to handle it properly.
|
Closes #3304
Problem
SerializerUtils.serializeEnumData()only validated theStringform of an Enum8/Enum16 value. Two other paths wrote data without checking:Numberwas written as-is, even if it is not a member of the column's enum (e.g.7intoEnum8('active' = 1, 'inactive' = 2))Enumwas written usingordinal(), which is the declaration index in Java and not the value declared in the column (Status.activeended up as0instead of1)The server accepts such rows, but reading them back as text then fails with
UNKNOWN_ELEMENT_OF_ENUM.Fix
Number: validated withClickHouseEnum.validate(int), so an unknown value fails on the client withUnknown enum value: 7Enum: mapped by name withClickHouseEnum.value(name()), so it is written as the declared value, and a constant that is not declared in the column failsTests
Tests
Integration tests (they need Docker, so they run with the
integrationgroup):DataTypeTests: a String, a valid member number and a Java enum are inserted into Enum8 and Enum16 columns with non-sequential declared values (5/10 and 500/1000), and both the name and the stored integer are checked. A non-member number and a Java enum constant not declared in the column fail withUnknown enum value: 7/Unknown enum name: active.JdbcDataTypeTests: withbeta.row_binary_for_simple_insertenabled, a valid member number is inserted into Enum8/Enum16 and read back, and a non-member number fails withUnknown enum value: 7.I ran them locally with Docker. Without the fix, the non-member number test in jdbc-v2 fails (nothing is thrown); with the fix, all of them pass.
Compatibility
Behavior change: values that used to be written silently (non-member numbers, Java enums via
ordinal()) now throwIllegalArgumentException. Valid strings, valid member numbers and valid Java enum names are unchanged.Added
history/latest/3304.md.Note
Medium Risk
This is a deliberate compatibility change: inserts that previously wrote non-member numbers or Java enums via
ordinal()now throw on the client, which may break callers but prevents silent bad enum data.Overview
Enum8/Enum16 client writes are now validated and mapped consistently in
SerializerUtils.serializeEnumData(). Numeric inputs must be a declared enum member (viaClickHouseEnum.validate); otherwise the client fails with messages likeUnknown enum value: 7instead of writing invalid bytes the server would accept. Javaenumconstants are resolved by name to the column's declared value, not byordinal(), so inserts match ClickHouse semantics and avoidUNKNOWN_ELEMENT_OF_ENUMon read.Integration coverage was added for client-v2 (
DataTypeTests) and jdbc-v2 row-binary inserts (JdbcDataTypeTests), plus a history note for issue #3304.Reviewed by Cursor Bugbot for commit b3fc5c6. Bugbot is set up for automated code reviews on this repo. Configure here.