Nejatians
Nejatians

Reputation: 70

How to cast String type to array of struct with ksql

I have a topic in Kafka which have a schema like:

    Name              Type
    ID               STRING
   ORDER_STATUS       INTEGER
   ORDER_ITEM_JSON    STRING

ORDER_ITEM_JSON is a string of items itself:

 "ORDER_ITEM_JSON":"[{\"item_id\":\"943\",\"category_id_fk\":\"42\",\"item_count\":\"1\",\"item_price\":55900,\"item_price_without_discount\":55900},{\"item_id\":\"1235\",\"category_id_fk\":\"42\",\"item_count\":\"1\",\"item_price\":25500,\"item_price_without_discount\":25500},{\"item_id\":\"1250\",\"category_id_fk\":\"42\",\"item_count\":\"1\",\"item_price\":37500,\"item_price_without_discount\":37500}]"

How can I cast this string field to an array of struct in ksql?

Upvotes: 0

Views: 1130

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 191831

I think you should re-create the stream with ARRAY<STRUCT already defined rather than cast afterwards.

Examples on dealing with nested json

Upvotes: 1

Related Questions