Search in sources :

Example 26 with BatchTableEnvironment

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

Example 27 with BatchTableEnvironment

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

Example 28 with BatchTableEnvironment

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

Example 29 with BatchTableEnvironment

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

Example 30 with BatchTableEnvironment

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);
}
Also used : BatchTableSource(org.apache.flink.table.sources.BatchTableSource) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Table(org.apache.flink.table.api.Table) Row(org.apache.flink.types.Row) 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