FLink Table API JAVA_BATCH_DEMO



org.apache.flink
flink-table-api-java-bridge_2.11
1.9.0



org.apache.flink
flink-table-planner_2.11
1.9.0



org.apache.flink
flink-streaming-scala_2.11
1.9.0









import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.java.BatchTableEnvironment;

/**
*
* FLink Java Batch Table API DEMO
*
* @author: create by maoxiangyi
* @version: v1.0
*/
public class WordCountSql {

public static void main(String[] args) throws Exception {
ExecutionEnvironment fbEnv = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment fbTableEnv = BatchTableEnvironment.create(fbEnv);

DataSet input = fbEnv.fromElements(
new WC("Hello", 1),
new WC("Ciao", 1),
new WC("Hello", 1)
);


// register the DataSet as table "WordCount"
fbTableEnv.registerDataSet("WordCount", input, "word, frequency");

// run a SQL query on the Table and retrieve the result as a new Table
Table table = fbTableEnv.sqlQuery(
"SELECT word, SUM(frequency) as frequency FROM WordCount GROUP BY word");

DataSet result = fbTableEnv.toDataSet(table, com.xesv5.mxy.WC.class);

result.print();
}
}










你可能感兴趣的:(FLink Table API JAVA_BATCH_DEMO)