Search in sources :

Example 31 with BatchTableEnvironment

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);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Table(org.apache.flink.table.api.Table) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Row(org.apache.flink.types.Row) BatchTableEnvironment(org.apache.flink.table.api.java.BatchTableEnvironment) Test(org.junit.Test)

Example 32 with BatchTableEnvironment

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);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Table(org.apache.flink.table.api.Table) Tuple3(org.apache.flink.api.java.tuple.Tuple3) Row(org.apache.flink.types.Row) BatchTableEnvironment(org.apache.flink.table.api.java.BatchTableEnvironment) Test(org.junit.Test)

Example 33 with BatchTableEnvironment

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");
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) BatchTableEnvironment(org.apache.flink.table.api.java.BatchTableEnvironment) Test(org.junit.Test)

Example 34 with BatchTableEnvironment

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");
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) BatchTableEnvironment(org.apache.flink.table.api.java.BatchTableEnvironment) Test(org.junit.Test)

Example 35 with BatchTableEnvironment

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);
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) CalciteConfigBuilder(org.apache.flink.table.calcite.CalciteConfigBuilder) Table(org.apache.flink.table.api.Table) CalciteConfig(org.apache.flink.table.calcite.CalciteConfig) Tuple3(org.apache.flink.api.java.tuple.Tuple3) BatchTableEnvironment(org.apache.flink.table.api.java.BatchTableEnvironment) Test(org.junit.Test)

Aggregations

ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)38 BatchTableEnvironment (org.apache.flink.table.api.java.BatchTableEnvironment)38 Test (org.junit.Test)36 Table (org.apache.flink.table.api.Table)30 Row (org.apache.flink.types.Row)19 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)12 ArrayList (java.util.ArrayList)6 TableConfig (org.apache.flink.table.api.TableConfig)4 HTable (org.apache.hadoop.hbase.client.HTable)4 Tuple5 (org.apache.flink.api.java.tuple.Tuple5)2 BatchTableSource (org.apache.flink.table.sources.BatchTableSource)2 HashMap (java.util.HashMap)1 Tuple4 (org.apache.flink.api.java.tuple.Tuple4)1 TupleTypeInfo (org.apache.flink.api.java.typeutils.TupleTypeInfo)1 CalciteConfig (org.apache.flink.table.calcite.CalciteConfig)1 CalciteConfigBuilder (org.apache.flink.table.calcite.CalciteConfigBuilder)1