use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testAsWithPojoAndGenericTypes.
@Test
public void testAsWithPojoAndGenericTypes() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
List<PojoWithGeneric> data = new ArrayList<>();
data.add(new PojoWithGeneric("Peter", 28, new HashMap<String, String>(), new ArrayList<String>()));
HashMap<String, String> hm1 = new HashMap<>();
hm1.put("test1", "test1");
data.add(new PojoWithGeneric("Anna", 56, hm1, new ArrayList<String>()));
HashMap<String, String> hm2 = new HashMap<>();
hm2.put("abc", "cde");
data.add(new PojoWithGeneric("Lucy", 42, hm2, new ArrayList<String>()));
Table table = tableEnv.fromDataSet(env.fromCollection(data), "name AS a, " + "age AS b, " + "generic AS c, " + "generic2 AS d").select("a, b, c, c as c2, d").select("a, b, c, c === c2, d");
DataSet<Row> ds = tableEnv.toDataSet(table, Row.class);
List<Row> results = ds.collect();
String expected = "Peter,28,{},true,[]\n" + "Anna,56,{test1=test1},true,[]\n" + "Lucy,42,{abc=cde},true,[]\n";
compareResultAsText(results, expected);
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testSimpleRegister.
@Test
public void testSimpleRegister() 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);
tableEnv.registerDataSet(tableName, ds);
Table t = tableEnv.scan(tableName);
Table result = t.select("f0, f1");
DataSet<Row> resultSet = tableEnv.toDataSet(result, Row.class);
List<Row> results = resultSet.collect();
String expected = "1,1\n" + "2,2\n" + "3,2\n" + "4,3\n" + "5,3\n" + "6,3\n" + "7,4\n" + "8,4\n" + "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 testAsWithAmbiguousFields.
@Test(expected = TableException.class)
public void testAsWithAmbiguousFields() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
// Must fail. Specified field names are not unique.
tableEnv.fromDataSet(CollectionDataSets.get3TupleDataSet(env), "a, b, b");
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testScanUnregisteredTable.
@Test(expected = TableException.class)
public void testScanUnregisteredTable() throws Exception {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
// Must fail. No table registered under that name.
tableEnv.scan("nonRegisteredTable");
}
use of org.apache.flink.table.api.java.BatchTableEnvironment in project flink by apache.
the class TableEnvironmentITCase method testCustomCalciteConfig.
@Test(expected = TableException.class)
public void testCustomCalciteConfig() {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());
CalciteConfig cc = new CalciteConfigBuilder().replaceOptRuleSet(RuleSets.ofList()).build();
tableEnv.getConfig().setCalciteConfig(cc);
DataSet<Tuple3<Integer, Long, String>> ds = CollectionDataSets.get3TupleDataSet(env);
Table t = tableEnv.fromDataSet(ds);
tableEnv.toDataSet(t, Row.class);
}
Aggregations