Skip to content

Commit aa184c4

Browse files
authored
Update jsonextract-to-parse-many-attributes-at-a-time.md
Added schema inference done by clickhouse-local
1 parent ef41de5 commit aa184c4

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

content/en/altinity-kb-queries-and-syntax/jsonextract-to-parse-many-attributes-at-a-time.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,33 @@ successful: 1
3939

4040
```
4141

42+
A good approach to get a proper schema from a json message is to let `clickhouse-local` schema inference do the job:
43+
44+
```bash
45+
$ ls example_message.json
46+
example_message.json
47+
48+
$ clickhouse-local --query="DESCRIBE file('example_message.json', 'JSONEachRow')" --format="Vertical";
49+
50+
Row 1:
51+
──────
52+
name: resourceLogs
53+
type: Array(Tuple(
54+
resource Nullable(String),
55+
scopeLogs Array(Tuple(
56+
logRecords Array(Tuple(
57+
attributes Array(Tuple(
58+
key Nullable(String),
59+
value Tuple(
60+
stringValue Nullable(String)))),
61+
body Tuple(
62+
stringValue Nullable(String)),
63+
observedTimeUnixNano Nullable(String),
64+
spanId Nullable(String),
65+
traceId Nullable(String))),
66+
scope Nullable(String)))))
67+
```
68+
4269
For very subnested dynamic JSON files, if you don't need all the keys, you could parse sublevels specifically. Still this will require several JSONExtract calls but each call will have less data to parse so complexity will be reduced for each pass: O(log n)
4370

4471
```sql

0 commit comments

Comments
 (0)