Skip navigation links

Back to Flink Website

Package org.apache.flink.table.api.java

Table API (Java)
A BatchTableEnvironment can be used to create a Table from a DataSet.

See: Description

Package org.apache.flink.table.api.java Description

Table API (Java)
A BatchTableEnvironment can be used to create a Table from a DataSet. Equivalently, a StreamTableEnvironment can be used to create a Table from a DataStream.

Tables can be used to perform SQL-like queries on data. Please have a look at Table to see which operations are supported and how query strings are written.

Example:


 ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
 BatchTableEnvironment tEnv = TableEnvironment.getTableEnvironment(env);

 DataSet<WC> input = env.fromElements(
   new WC("Hello", 1),
   new WC("Ciao", 1),
   new WC("Hello", 1));

 Table table = tEnv.fromDataSet(input);

 Table filtered = table
     .groupBy("word")
     .select("word.count as count, word")
     .filter("count = 2");

 DataSet<WC> result = tEnv.toDataSet(filtered, WC.class);

 result.print();
 

As seen above, a Table can be converted back to the underlying API representation using BatchTableEnvironment.toDataSet(Table, java.lang.Class), StreamTableEnvironment.toAppendStream(Table, java.lang.Class)}, or StreamTableEnvironment.toRetractStream(Table, java.lang.Class)}.

Skip navigation links

Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.