Hi John,

please check the type that is coming in from the DataStream API via dataStream.getType(). It should be an instance of RowTypeInfo otherwise the Table API cannot extract the columns correctly.

Usually, you can overwrite the type of the last DataStream operation using the `.returns(Types.ROW(...))` call.

I hope this helps.

Regards,
Timo


On 14.05.21 09:01, John Smith wrote:
Hi,

Sorry if this is a duplicate question but I couldn't find any answer to my question. I am trying to convert a DataStream<Row> into a Table where the columns in the Row objects in the DataStream<Row> will become columns of the Table.
Here is how I tried to do it:

//Creating a DataStream of Row type. Let's assume the Row type has 3 columns:
// (c1 BIGINT, c2 String, c3 String)
DataStream<Row> rowStream = ....

// Convert it to a Table
Table t = tableEnv.fromDataStream(rowStream)

// Print the table
t.execute().print();

However, when I print the table it has one column of type Row instead of three columns (c1, c2, c3).

What I see in the print result is:

+----+--------------------------------+
| op |                                  f0   |
+----+--------------------------------+
| +I | +I{c1=1620968140951, ... |

What I would like to see is:

+----+-------------------------------------------+
| op |                        c1  |   c2   |    c3   |
+----+-------------------------------------------+
|   +I |  1620968140951 |  'foo'  |  'bar'  |

How can I convert the DataStream to a table that has the same columns as the columns in Row in the DataStream. Would really appreciate it if anyone can share a code snippet for the above example.

Thanks,
JS.


Reply via email to