Commit 1b25cfb
committed
Support the modern JSON type (#142)
Object('json') was removed from the server in 24.8, so JSON was not merely
legacy on current ClickHouse - it was unusable: reading a JSON column raised
UnknownTypeError, and the one format asynch implemented no longer existed
server-side.
Read path composes the format out of column readers rather than hand-rolling
it. dynamiccolumn.pyx implements SerializationDynamic/SerializationVariant:
the variant list arrives in the state prefix, global discriminators are
recovered by sorting the type names (SharedVariant sorts among them, so its
index has to be derived, not assumed), and values that match no declared
variant are decoded from their encodeDataType + serializeBinary blob. That
decoder builds the value's column reader from the decoded type string and
drives it over an in-memory reader, so every type asynch already supports is
reachable inside a shared JSON value for free.
jsoncolumn.pyx folds the per-path dynamic columns and the
Array(Tuple(String, String)) shared sub-column back into nested dicts,
including dotted-path denormalisation. Writing infers a spec per value,
groups rows per path and variant, and emits V2 framing; the block's items now
reach write_state_prefix, since the prefix lists the paths about to be
written. Dynamic is registered as a column type too - it shows up as a
variant spec for heterogeneous arrays.
Object('json') keeps its own reader: its framing (UInt8 version then a type
spec) is incompatible, and only old servers speak it.
Verified against ClickHouse 26.7: nested objects, heterogeneous and nested
arrays, arrays of objects, nulls, big integers, unicode, empty documents, a
2000-row multi-path batch, dict and text input, and server-side path access
(doc.a.b) on what the driver wrote. Round-trip equality holds for every
document in the test set.
Known gap: a JSON column nested inside Array/Tuple can be read but not
written - that needs the container columns to thread items through their
prefixes.1 parent 32d5401 commit 1b25cfb
8 files changed
Lines changed: 947 additions & 9 deletions
File tree
- asynch/proto/columns
- tests/test_proto/columns
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
35 | 41 | | |
36 | 42 | | |
37 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
213 | 236 | | |
214 | 237 | | |
215 | 238 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
138 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
139 | 145 | | |
140 | 146 | | |
141 | 147 | | |
| |||
183 | 189 | | |
184 | 190 | | |
185 | 191 | | |
186 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
187 | 198 | | |
188 | 199 | | |
189 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
0 commit comments