use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testTableRegisterNew.
@Test
public void testTableRegisterNew() throws Exception {
final String tableName = "MyTable";
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
Table t = tableEnv.fromDataSet(ds);
tableEnv.registerTable(tableName, t);
tableEnv.unregisterTable(tableName);
Table t2 = tableEnv.fromDataSet(ds).filter("f0 > 8");
tableEnv.registerTable(tableName, t2);
Table result = tableEnv.scan(tableName).select("f0, f1").filter("f0 > 7");
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "9,4\n" + "10,4\n" + "11,5\n" + "12,5\n" + "13,5\n" + "14,5\n" + "15,5\n" + "16,6\n" + "17,6\n" + "18,6\n" + "19,6\n" + "20,6\n" + "21,6\n";
compareResultAsText(results, expected);
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testNonStaticClassInput.
@Test(expected = TableException.class)
public void testNonStaticClassInput() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
// Must fail since class is not static
tableEnv.fromDataSet(env.fromElements(new MyNonStatic()), "name");
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableSourceITCase method testBatchTableSourceTableAPI.
@Test
public void testBatchTableSourceTableAPI() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
BatchTableSource csvTable = CommonTestData.getCsvTableSource();
tableEnv.registerTableSource("persons", csvTable);
Table result = tableEnv.scan("persons").select("id, first, last, score");
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "1,Mike,Smith,12.3\n" + "2,Bob,Taylor,45.6\n" + "3,Sam,Miller,7.89\n" + "4,Peter,Smith,0.12\n" + "5,Liz,Williams,34.5\n" + "6,Sally,Miller,6.78\n" + "7,Alice,Smith,90.1\n" + "8,Kelly,Williams,2.34\n";
compareResultAsText(results, expected);
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class SqlITCase method testJoin.
@Test
public void testJoin() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> ds1 = CollectionDataSets.getSmall3TupleDataSet(env);
DataSet<Tuple5<Integer, Long, Integer, String, Long>> ds2 = CollectionDataSets.get5TupleDataSet(env);
tableEnv.registerDataSet("t1", ds1, "a, b, c");
tableEnv.registerDataSet("t2", ds2, "d, e, f, g, h");
String sqlQuery = "SELECT c, g FROM t1, t2 WHERE b = e";
Table result = tableEnv.sql(sqlQuery);
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "Hi,Hallo\n" + "Hello,Hallo Welt\n" + "Hello world,Hallo Welt\n";
compareResultAsText(results, expected);
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class SqlITCase method testFilterFromDataSet.
@Test
public void testFilterFromDataSet() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
tableEnv.registerDataSet("DataSetTable", ds, "x, y, z");
String sqlQuery = "SELECT x FROM DataSetTable WHERE z LIKE '%Hello%'";
Table result = tableEnv.sql(sqlQuery);
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "2\n" + "3\n" + "4";
compareResultAsText(results, expected);
}
Aggregations