I have messages in Avro format in Kafka. These have to converted to table and selected using SQL, then converted to stream and finally sink. There are multiple Kafka topics with different Avro schemas, hence dynamic tables are required.
Here is the code which I am using
StreamExecutionEnvironment env = ...;
StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
FlinkKafkaConsumer<MyAvroClass> kafkaConsumer = ...;
var kafkaInputStream = env.addSource(kafkaConsumer, "kafkaInput");
Table table = tableEnv.fromDataStream(kafkaInputStream);
tableEnv.executeSql("DESCRIBE " + table).print();
...
MyAvroClass
is Avro class which extends SpecificRecordBase
and contains an array.
code for this class.
public class MyAvroClass extends SpecificRecordBase implements SpecificRecord {
// avro fields
private String event_id;
private User user;
private List<Item> items;
// getter, setters, constructors, builders, ...
}
I am unable to access elements of items
field. When I print table description, I see that items is of type ANY
+------------+-------------------------------------------------------------+------+-----+--------+-----------+
| name | type | null | key | extras | watermark |
+------------+-------------------------------------------------------------+------+-----+--------+-----------+
| event_id | STRING | true | | | |
| items | LEGACY('RAW', 'ANY<java.util.List>') | true | | | |
| user | LEGACY('STRUCTURED_TYPE', 'POJO<com.company.events.User>') | true | | | |
+------------+-------------------------------------------------------------+------+-----+--------+-----------+
How can I convert it to a type using which I can query the from items? Thanks in advance