Getting nested fields in a Flink API Table fromDatastream

29 views Asked by At

I've got a nested datastream POJO that I turned into a table with the table API. Inside the POJO lies a nested body with various fields such as "media_id".

When I use a sqlQuery, I can easily access said fields like this :

SELECT body.media_id FROM myTable

But I'd like to use the table API and define this field with a schema like this:

Table myTable = tEnv.fromDataStream(source, Schema.newBuilder()
                .column("body.media_id", "STRING")
                .build());

Unfortunately, doing so returns an error :

Exception in thread "main" org.apache.flink.table.api.ValidationException: Cannot resolve field [body.media_id], input field list:[body, headers, id, ts, url].

Could you point out what I forgot/did wrong and a possible fix?

Thank you for your help,

1

There are 1 answers

0
Niko On

The problem here is that you declaring a column "body.media_id" of type STRING and for Flink . (point) it's just a character here.

.column("body.media_id", "STRING")

it's the same if it was _ instead of . -> "body_media_id"

In your case column body is not a STRING but something like ROW of some fields. ROW<media_id STRING, foo STRING>