You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[client-v2] Reading a Variant, Nested, Decimal or Enum value nested in a Dynamic column fails or loses the type parameters #3003
When a value inside a Dynamic column has a composite concrete type, client-v2 rebuilds the concrete type from the binary type encoding in BinaryStreamReader.readDynamicData(). Four branches of that decoder produce a type that does not match what was encoded, which fails the whole query or silently returns a wrong value.
Steps to reproduce
All of the following are single-statement queries against 26.5.1 (also reproduces on earlier versions supporting Dynamic); num is a desync guard.
Variant nested in another type — the type name is wrapped twice (Variant(Variant(Int32, String))), so it parses to one variant element instead of two and the discriminator byte indexes the wrong element:
SELECT [1, 'a']::Array(Variant(Int32, String))::Dynamic AS v, 42::Int32 AS num
-> com.clickhouse.client.api.ClientException: Failed to get query response
Caused by: java.io.EOFException: End of stream reached before reading all data
Nested — only the element names are read; the element type encodings that follow each name (per the "Data types binary encoding" spec, Nested is encoded like a named Tuple) are neither consumed nor kept:
SELECT [(1, 'x'), (2, 'y')]::Nested(a Int32, b String)::Dynamic AS v, 42::Int32 AS num
-> java.lang.IllegalArgumentException: Unknown data type: b
Decimal nested in another type — the reconstructed column has no original type name, so a parent (array/tuple/map/variant/JSON) appends the bare Decimal64 and the wire-read precision and scale are dropped:
SELECT [1.25::Decimal64(4)]::Array(Decimal64(4))::Dynamic AS v
-> [12500] -- expected [1.2500]
Enum8 / Enum16 nested in another type — same cause, so the enum constants are dropped and every value reads back as <unknown>:
SELECT ['a']::Array(Enum8('a' = 1, 'b' = 2))::Dynamic AS v
-> [<unknown>] -- expected [a]
Additionally, Enum16 fails outright even at the top level of a Dynamic column when it has fewer than 128 constants, because the decoder picks the constant width from the number of constants instead of from the type tag (Enum8 = 0x17 encodes them as Int8, Enum16 = 0x18 as Int16):
SELECT ['a']::Array(Enum16('a' = 1000, 'b' = 2000))::Dynamic AS v
-> java.io.EOFException: End of stream reached before reading all data
Negative Enum8 constants (Enum8('a' = -1)) are read as unsigned for the same reason and never match.
Expected behaviour
Each of the queries above returns the value it inserted, and the trailing column stays intact.
Activity
Fix client-v2: keep the type parameters when rebuilding a type from a…