简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM