use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testIllegalName.
@Test(expected = TableException.class)
public void testIllegalName() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
Table t = tableEnv.fromDataSet(ds);
// Must fail. Table name matches internal name pattern.
tableEnv.registerTable("_DataSetTable_42", t);
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testAsWithNonFieldReference1.
@Test(expected = TableException.class)
public void testAsWithNonFieldReference1() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
// Must fail. as() does only allow field name expressions
tableEnv.fromDataSet(CollectionDataSets.get3TupleDataSet(env), "a + 1, b, c");
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testAsFromAndToTuple.
@Test
public void testAsFromAndToTuple() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
Table table = tableEnv.fromDataSet(CollectionDataSets.get3TupleDataSet(env), "a, b, c").select("a, b, c");
TypeInformation<?> ti = new TupleTypeInfo<Tuple3<Integer, Long, String>>(BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
DataSet<?> ds = tableEnv.toDataSet(table, ti);
List<?> results = ds.collect();
String expected = "(1,1,Hi)\n" + "(2,2,Hello)\n" + "(3,2,Hello world)\n" + "(4,3,Hello world, how are you?)\n" + "(5,3,I am fine.)\n" + "(6,3,Luke Skywalker)\n" + "(7,4,Comment#1)\n" + "(8,4,Comment#2)\n" + "(9,4,Comment#3)\n" + "(10,4,Comment#4)\n" + "(11,5,Comment#5)\n" + "(12,5,Comment#6)\n" + "(13,5,Comment#7)\n" + "(14,5,Comment#8)\n" + "(15,5,Comment#9)\n" + "(16,6,Comment#10)\n" + "(17,6,Comment#11)\n" + "(18,6,Comment#12)\n" + "(19,6,Comment#13)\n" + "(20,6,Comment#14)\n" + "(21,6,Comment#15)\n";
compareResultAsText(results, expected);
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testRegisterExistingDatasetTable.
@Test(expected = TableException.class)
public void testRegisterExistingDatasetTable() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
tableEnv.registerDataSet("MyTable", ds);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.getSmall5TupleDataSet(env);
// Must fail. Name is already used for different table.
tableEnv.registerDataSet("MyTable", ds2);
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class WordCountSQL method main.
// *************************************************************************
// PROGRAM
// *************************************************************************
public static void main(String[] args) throws Exception {
// set up execution environment
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));
// register the DataSet as table "WordCount"
tEnv.registerDataSet("WordCount", input, "word, frequency");
// run a SQL query on the Table and retrieve the result as a new Table
Table table = tEnv.sql("SELECT word, SUM(frequency) as frequency FROM WordCount GROUP BY word");
DataSet<WC> result = tEnv.toDataSet(table, WC.class);
result.print();
}
Aggregations