use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class SqlITCase method testSelectFromTable.
@Test
public void testSelectFromTable() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
Table in = tableEnv.fromDataSet(ds, "a,b,c");
tableEnv.registerTable("T", in);
String sqlQuery = "SELECT a, c FROM T";
Table result = tableEnv.sql(sqlQuery);
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "1,Hi\n" + "2,Hello\n" + "3,Hello world\n" + "4,Hello world, how are you?\n" + "5,I am fine.\n" + "6,Luke Skywalker\n" + "7,Comment#1\n" + "8,Comment#2\n" + "9,Comment#3\n" + "10,Comment#4\n" + "11,Comment#5\n" + "12,Comment#6\n" + "13,Comment#7\n" + "14,Comment#8\n" + "15,Comment#9\n" + "16,Comment#10\n" + "17,Comment#11\n" + "18,Comment#12\n" + "19,Comment#13\n" + "20,Comment#14\n" + "21,Comment#15\n";
compareResultAsText(results, expected);
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class SqlITCase method testAggregation.
@Test
public void testAggregation() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
tableEnv.registerDataSet("AggTable", ds, "x, y, z");
String sqlQuery = "SELECT sum(x), min(x), max(x), count(y), avg(x) FROM AggTable";
Table result = tableEnv.sql(sqlQuery);
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "231,1,21,21,11";
compareResultAsText(results, expected);
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class SqlITCase method testValues.
@Test
public void testValues() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
String sqlQuery = "VALUES (1, 'Test', TRUE, DATE '1944-02-24', 12.4444444444444445)," + "(2, 'Hello', TRUE, DATE '1944-02-24', 12.666666665)," + "(3, 'World', FALSE, DATE '1944-12-24', 12.54444445)";
Table result = tableEnv.sql(sqlQuery);
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "3,World,false,1944-12-24,12.5444444500000000\n" + "2,Hello,true,1944-02-24,12.6666666650000000\n" + // Calcite converts to decimals and strings with equal length
"1,Test ,true,1944-02-24,12.4444444444444445\n";
compareResultAsText(results, expected);
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testNonStaticClassOutput.
@Test(expected = TableException.class)
public void testNonStaticClassOutput() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
// Must fail since class is not static
Table t = tableEnv.fromDataSet(env.fromElements(1, 2, 3), "number");
tableEnv.toDataSet(t, MyNonStatic.class);
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testRegisterTableFromOtherEnv.
@Test(expected = TableException.class)
public void testRegisterTableFromOtherEnv() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv1 = TableEnvironment.getTableEnvironment(env, config());
BatchTableEnvironment tableEnv2 = TableEnvironment.getTableEnvironment(env, config());
Table t = tableEnv1.fromDataSet(CollectionDataSets.get3TupleDataSet(env));
// Must fail. Table is bound to different TableEnvironment.
tableEnv2.registerTable("MyTable", t);
}
Aggregations