use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testTableUnregister.
@Test(expected = TableException.class)
public void testTableUnregister() 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);
// Must fail. Table name is not register anymore.
tableEnv.scan(tableName).select("f0, f1").filter("f0 > 7");
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testAsWithToManyFields.
@Test(expected = TableException.class)
public void testAsWithToManyFields() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
// Must fail. Too many field names specified.
tableEnv.fromDataSet(CollectionDataSets.get3TupleDataSet(env), "a, b, c, d");
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testAsFromAndToPrivateFieldPojo.
@Test
public void testAsFromAndToPrivateFieldPojo() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
List<PrivateSmallPojo> data = new ArrayList<>();
data.add(new PrivateSmallPojo("Peter", 28, 4000.00, "Sales"));
data.add(new PrivateSmallPojo("Anna", 56, 10000.00, "Engineering"));
data.add(new PrivateSmallPojo("Lucy", 42, 6000.00, "HR"));
Table table = tableEnv.fromDataSet(env.fromCollection(data), "department AS a, " + "age AS b, " + "salary AS c, " + "name AS d").select("a, b, c, d");
DataSet<PrivateSmallPojo2> ds = tableEnv.toDataSet(table, PrivateSmallPojo2.class);
List<PrivateSmallPojo2> results = ds.collect();
String expected = "Sales,28,4000.0,Peter\n" + "Engineering,56,10000.0,Anna\n" + "HR,42,6000.0,Lucy\n";
compareResultAsText(results, expected);
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testAsWithToFewFields.
@Test(expected = TableException.class)
public void testAsWithToFewFields() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
// Must fail. Not enough field names specified.
tableEnv.fromDataSet(CollectionDataSets.get3TupleDataSet(env), "a, b");
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableSourceITCase method testBatchTableSourceSQL.
@Test
public void testBatchTableSourceSQL() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
BatchTableSource csvTable = CommonTestData.getCsvTableSource();
tableEnv.registerTableSource("persons", csvTable);
Table result = tableEnv.sql("SELECT last, FLOOR(id), score * 2 FROM persons WHERE score < 20");
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "Smith,1,24.6\n" + "Miller,3,15.78\n" + "Smith,4,0.24\n" + "Miller,6,13.56\n" + "Williams,8,4.68\n";
compareResultAsText(results, expected);
}
Aggregations