Giorgio Pellero
01/22/2025, 7:06 PMUNNEST a nested JSON column at ingestion time?
to be more precise, I'm using streaming ingestion from Kafka and each source row has a column that looks like this (simplified): {"items": [{"key": "item1", "value": {...}}, {"key": "item2", "value": {...}}, ..., {"key": "itemN", "value": {...}}]} - that is, items is not constant-sized.
to make the data easier to work with at query time I'd like to UNNEST it so that it results in something like this:
__time,item_key,item_value
1,item1,`{...}`
2,item2,`{...}`
...
N,itemN,`{...}`
where item_value is a COMPLEX<json>.
I can easily do this when batch ingesting using SQL, for example:
INSERT INTO "my_new_table"
SELECT
__time,
JSON_VALUE(item, '$.key') AS item_key,
JSON_VALUE(item, '$.value') AS item_value
FROM "original_table"
CROSS JOIN UNNEST(JSON_QUERY_ARRAY(original_column, '$.items')) AS item
PARTITIONED BY ...
so is this sort of unnesting possible for streaming ingestion?John Kowtko
01/22/2025, 8:44 PMGiorgio Pellero
01/23/2025, 6:47 AMflattenSpec, but my understanding is that it only allows flattening a nested column into other columns of the same row, whereas I'd like to unnest 1 source row into N Druid rows (at ingestion time). the docs don't seem to mention any unnest operator for flattenSpecJohn Kowtko
01/23/2025, 7:45 AMDavid Brauchli
01/23/2025, 2:35 PMDavid Brauchli
01/23/2025, 2:35 PMDavid Brauchli
01/23/2025, 2:37 PMDavid Brauchli
01/23/2025, 2:37 PMGiorgio Pellero
01/23/2025, 2:38 PM