Bharath Parlapalli
Bharath Parlapalli

Reputation: 75

KSQL - loop through of JSON array

I have a kafka topic data with the following structure:

    { property1:value1, 
      property2:value2, 
      property3: [    
       {
        subprop1:subval11,
        subprop2:subval12,
        subprop3:subval13    
       },    
       {
         subprop1:subval21,
         subprop2:subval22,
         subprop3:subval23
        },
        ...
     ] 
   }

in the KSQL documentation, I can declare a stream or table with the ARRAY format for the column, however, when I create the stream, I need to loop through this array.

My KSQL output should be:

PropertyID1 |subprop1 | subprop2 | subprop3
Value1      |subval11 | subval12 | subval13
Value1      |subval21 | subval22 | subval23

so what should my create stream function look like?

So far I have:

CREATE STREAM testarrayjsonstream \
  (property1 VARCHAR, \
   property3 ARRAY) \
  WITH (KAFKA_TOPIC='topic1', \
        VALUE_FORMAT='AVRO');

then I can do:

Create Stream testarrayjsontopic as \
select property1,property3[0]->subprop1 from testarrayjsonstream

but that only gives me only the first array element - I need to loop through to get all array elements. any pointers?

Upvotes: 0

Views: 1612

Answers (1)

Robin Moffatt
Robin Moffatt

Reputation: 32090

KSQL doesn't currently support this. You can upvote/comment on the issue here.

Upvotes: 1

Related Questions