KsqlDB for nested data

5 views
Skip to first unread message

Hamed Hatami

unread,
Sep 27, 2024, 5:05:39 AM9/27/24
to ksqldb-users
Hi guysI've got a question regarding KsqlDB stream creation for Avro events.
In my use case , there're unions used in the Avro schemas so when it comes to the messages/events structure, in some element's value it could be varied (nested data dynamicity)
One key in the event could have different object type as value and now I'm going to create a KsqlDB stream, it just lets me hardcode the structure by using STRUCT keyword

CREATE STREAM AVRO_DEMO_STREAM ( `eventTime` TIMESTAMP, `localEventTime` TIMESTAMP, `itemId` STRUCT<`id` VARCHAR>, `metadata` STRUCT<     `timeCreated` TIMESTAMP,     `source` STRUCT<`systemName` VARCHAR,     `subSystem` VARCHAR,`instance` VARCHAR>,     `eventId` VARCHAR,     `eventClass` VARCHAR>, `originMetadata` STRUCT<`user` STRUCT<`ActiveDirectoryUser` STRUCT<`firstName` VARCHAR, `lastName` VARCHAR, `userPrincipalName` VARCHAR>>>, `typeCode` VARCHAR, `isDamaged` BOOLEAN, `location` STRUCT<`GeoLocation` STRUCT<`coordinates` STRUCT <`lat` DOUBLE, `lng` DOUBLE>,`accuracy` DOUBLE>>) WITH (KAFKA_TOPIC='avro_topic',VALUE_FORMAT='AVRO');

In the above example, "location" and "originMetadata" values could be varied conditionally
So that the above stream only works for one message format not all events meet the schema validation 

Any clue, how to make this KsqlDB stream generic to support flexible nested json structure?

BR,
Hamed. 



Reply all
Reply to author
Forward
0 new messages