Repository navigation
Description
Description
client-v2 writes a Java enum value into a Dynamic column correctly when the enum is the value itself. When the enum is a key or a value of a Map, the insert fails on the server:
Code: 92. DB::Exception: DataTypeEnum enumeration cannot be empty: While executing WaitForAsyncInsert. (EMPTY_DATA_PASSED)
Tested with Client#register(Class, schema) + Client#insert(table, List<POJO>). RowBinaryFormatWriter uses the same SerializerUtils.serializeData path (RowBinaryFormatWriter.java:98, POJOSerDe.java:66).
Results (table (rowId Int32, field Dynamic)):
Java value of `field` result dynamicType(field)
Small.B (top level, contrast) stored 'B' Enum8('A' = 0, 'B' = 1, 'C' = 2)
Large.L150 (top level, contrast) stored 'L150' Enum16('L000' = 0, ...)
Map<String, Small> {k1=B, k2=C} EMPTY_DATA_PASSED -
Map<String, Large> {k1=L150} EMPTY_DATA_PASSED -
Map<Small, String> {C=v} EMPTY_DATA_PASSED -
(Small has 3 constants. Large has 200 constants, so the client selects Enum16 for it.)
The server accepts this type in Dynamic, but it does not accept an empty Enum:
SELECT map('k1','B')::Map(String, Enum8('A' = 0, 'B' = 1, 'C' = 2))::Dynamic AS d, dynamicType(d)
{'k1':'B'} Map(String, Enum8(\'A\' = 0, \'B\' = 1, \'C\' = 2))
SELECT CAST(1, 'Enum16()')
Code: 92. DB::Exception: Enum data type cannot be empty ... (EMPTY_DATA_PASSED)
The type encoding that the client writes (SerializerUtils.valueToColumnForDynamicType + writeDynamicTypeTag) has an Enum16 with 0 elements inside the Map. Small is Enum8 at the top level, but Enum16 inside the Map:
Small.B -> 17 03 01 41 00 01 42 01 01 43 02 Enum8, 3 elements (correct)
Map<String, Small> {k1=B} -> 27 15 18 00 Map(String, Enum16 with 0 elements)
Steps to reproduce
- Create table
twith aDynamiccolumn (the SQL is in the code example). - Register a POJO with
int rowIdandObject field, and insert one row wherefieldis aMap<String, MyEnum>. - The insert fails with
DataTypeEnum enumeration cannot be empty. Withfield = MyEnum.B(noMap), the same code works.
Error Log or Exception StackTrace
com.clickhouse.client.api.ServerException: Code: 92. DB::Exception: DataTypeEnum enumeration cannot be empty: While executing WaitForAsyncInsert. (EMPTY_DATA_PASSED) (version 26.9.1.1629 (official build))
Expected Behaviour
The row is inserted. dynamicType(field) is Map(String, Enum8('A' = 0, 'B' = 1, 'C' = 2)), with the same element list that the client already sends for a top-level Small value.
Root cause
SerializerUtils.enumValue2Column(client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/SerializerUtils.java:369-373) gives the column the correct data type and constants, but its original type name is the constant string"Enum16", without the elements. The name is also wrong forEnum8.- The
Mapbranch ofvalueToColumnForDynamicType(SerializerUtils.java:276-282) does not use the key and value column objects. It parses the concatenated type names (Map(String, Enum16)) again withClickHouseColumn.of, so the value column is anEnum16with no elements.writeDynamicTypeTag(SerializerUtils.java:410-425) then writes tag0x18with element count 0.
A top-level enum is not affected, because the client uses its column object (with the constants) directly.
The fix is a complete type name in enumValue2Column.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Code Example
Reproduction program (Java, 18 lines)
public enum Small { A, B, C }
public static class Row {
private int rowId;
private Object field;
public Row() {}
public Row(int rowId, Object field) { this.rowId = rowId; this.field = field; }
public int getRowId() { return rowId; }
public void setRowId(int v) { rowId = v; }
public Object getField() { return field; }
public void setField(Object v) { field = v; }
}
client.execute("CREATE TABLE t (rowId Int32, field Dynamic) ENGINE = MergeTree ORDER BY rowId").get().close();
client.register(Row.class, client.getTableSchema("t"));
client.insert("t", List.of(new Row(1, Small.B))).get().close(); // OK: Enum8('A' = 0, 'B' = 1, 'C' = 2)
client.insert("t", List.of(new Row(2, Map.of("k1", Small.B)))).get().close(); // ServerException: DataTypeEnum enumeration cannot be emptyConfiguration
Client Configuration
new Client.Builder()
.addEndpoint("http://localhost:8123")
.setUsername("default").setPassword("...")
.build();Environment
- Cloud
- Client version: client-v2
mainf73e372 - Language version: Java 17 (Temurin)
- OS: Linux (Docker)
ClickHouse Server
- ClickHouse Server version: 26.9.1.1629
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: in the code example- Sample data for all these tables: see the code example
Found by automated analysis (Polyglot AI) while working on #3342. Verified against a live server. Shortened on 2026-11-20: the edit history has the first version.
Activity