4

I am using Flink Table API using Java where I want to convert DataSet to DataStream .... Following is my code :

TableEnvironment tableEnvironment=new TableEnvironment();
Table tab1=table.where("related_value < 2014").select("related_value,ref_id");
DataSet<MyClass>ds2=tableEnvironment.toDataSet(tab1, MyClass.class);
DataStream<MyClass> d=tableEnvironment.toDataStream(tab1, MyClass.class);

But when I try to execute this program,it throws following exception :

org.apache.flink.api.table.ExpressionException: Invalid Root for JavaStreamingTranslator: Root(ArraySeq((related_value,Double), (ref_id,String))). Did you try converting a Table based on a DataSet to a DataStream or vice-versa? I want to know how we can convert DataSet to DataStream using Flink Table API ??

Another thing I want to know that, for Pattern matching, there is Flink CEP Library available.But is it feasible to use Flink Table API for Pattern Matching ??

Akki
  • 493
  • 1
  • 11
  • 23
  • Please do not ask multiple questions in one Stackoverflow question. Open another thread for your pattern matching question instead. – Fabian Hueske May 13 '16 at 07:41

2 Answers2

3

Flink's Table API was not designed to convert a DataSet into a DataStream and vice versa. It is not possible to do that with the Table API and there is also no other way to do it with Flink at the moment.

Unifying the DataStream and DataSet APIs (handling batch processing as a special case of streaming, i.e., as bounded streams) is on the long-term roadmap of Flink.

Fabian Hueske
  • 18,707
  • 2
  • 44
  • 49
  • Ok.....just want to know whether Flink's Table API can be used for Pattern Matching or CEP ?? – Akki May 13 '16 at 09:15
  • 1
    Please open a new question for that. Stackoverflow is not a place for discussions, it is a question and answer service. Other people won't find answers if multiple questions are answered under the same topic. – Fabian Hueske May 13 '16 at 12:45
0

You cannot convert to DataStream API when using TableEnvironment, you must create an StreamTableEnvironment to convert from table to DataStream, something like this:

final EnvironmentSettings fsSettings = EnvironmentSettings.newInstance().useBlinkPlanner().inStreamingMode().build();
final StreamTableEnvironment fsTableEnv = StreamTableEnvironment.create(configuration, fsSettings);
DataStream<String> finalRes = fsTableEnv.toAppendStream(tableNameHere, MyClass.class);

Hope to help you in somehow.

Kind regards!

Alter
  • 903
  • 1
  • 11
  • 27