use of org.apache.flink.table.api.bridge.java.StreamTableEnvironment in project flink by apache.
the class HBaseConnectorITCase method testTableSourceSinkWithDDL.
@Test
public void testTableSourceSinkWithDDL() throws Exception {
StreamExecutionEnvironment execEnv = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tEnv = StreamTableEnvironment.create(execEnv, streamSettings);
// register HBase table testTable1 which contains test data
String table1DDL = createHBaseTableDDL(TEST_TABLE_1, true);
tEnv.executeSql(table1DDL);
// register HBase table which is empty
String table3DDL = createHBaseTableDDL(TEST_TABLE_3, true);
tEnv.executeSql(table3DDL);
String insertStatement = "INSERT INTO " + TEST_TABLE_3 + " SELECT rowkey," + " family1," + " family2," + " family3," + " family4" + " from " + TEST_TABLE_1;
TableResult tableResult = tEnv.executeSql(insertStatement);
// wait to finish
tableResult.await();
assertEquals("Expected INSERT rowKind", RowKind.INSERT, tableResult.collect().next().getKind());
// start a batch scan job to verify contents in HBase table
TableEnvironment batchEnv = TableEnvironment.create(batchSettings);
batchEnv.executeSql(table3DDL);
List<String> expected = new ArrayList<>();
expected.add("+I[1, 10, Hello-1, 100, 1.01, false, Welt-1, 2019-08-18T19:00, 2019-08-18, 19:00, 12345678.0001]");
expected.add("+I[2, 20, Hello-2, 200, 2.02, true, Welt-2, 2019-08-18T19:01, 2019-08-18, 19:01, 12345678.0002]");
expected.add("+I[3, 30, Hello-3, 300, 3.03, false, Welt-3, 2019-08-18T19:02, 2019-08-18, 19:02, 12345678.0003]");
expected.add("+I[4, 40, null, 400, 4.04, true, Welt-4, 2019-08-18T19:03, 2019-08-18, 19:03, 12345678.0004]");
expected.add("+I[5, 50, Hello-5, 500, 5.05, false, Welt-5, 2019-08-19T19:10, 2019-08-19, 19:10, 12345678.0005]");
expected.add("+I[6, 60, Hello-6, 600, 6.06, true, Welt-6, 2019-08-19T19:20, 2019-08-19, 19:20, 12345678.0006]");
expected.add("+I[7, 70, Hello-7, 700, 7.07, false, Welt-7, 2019-08-19T19:30, 2019-08-19, 19:30, 12345678.0007]");
expected.add("+I[8, 80, null, 800, 8.08, true, Welt-8, 2019-08-19T19:40, 2019-08-19, 19:40, 12345678.0008]");
Table countTable = batchEnv.sqlQuery("SELECT COUNT(h.rowkey) FROM " + TEST_TABLE_3 + " AS h");
assertEquals(new Long(expected.size()), countTable.execute().collect().next().getField(0));
String query = "SELECT " + " h.rowkey, " + " h.family1.col1, " + " h.family2.col1, " + " h.family2.col2, " + " h.family3.col1, " + " h.family3.col2, " + " h.family3.col3, " + " h.family4.col1, " + " h.family4.col2, " + " h.family4.col3, " + " h.family4.col4 " + " FROM " + TEST_TABLE_3 + " AS h";
TableResult tableResult3 = batchEnv.executeSql(query);
List<String> result = Lists.newArrayList(tableResult3.collect()).stream().map(Row::toString).sorted().collect(Collectors.toList());
assertEquals(expected, result);
}
use of org.apache.flink.table.api.bridge.java.StreamTableEnvironment in project flink by apache.
the class HBaseConnectorITCase method testHBaseLookupTableSource.
@Test
public void testHBaseLookupTableSource() {
StreamExecutionEnvironment execEnv = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tEnv = StreamTableEnvironment.create(execEnv, streamSettings);
tEnv.executeSql("CREATE TABLE " + TEST_TABLE_1 + " (" + " family1 ROW<col1 INT>," + " family2 ROW<col1 STRING, col2 BIGINT>," + " family3 ROW<col1 DOUBLE, col2 BOOLEAN, col3 STRING>," + " rowkey INT," + " family4 ROW<col1 TIMESTAMP(3), col2 DATE, col3 TIME(3), col4 DECIMAL(12, 4)>," + " PRIMARY KEY (rowkey) NOT ENFORCED" + ") WITH (" + " 'connector' = 'hbase-1.4'," + " 'table-name' = '" + TEST_TABLE_1 + "'," + " 'zookeeper.quorum' = '" + getZookeeperQuorum() + "'" + ")");
// prepare a source table
String srcTableName = "src";
DataStream<Row> srcDs = execEnv.fromCollection(testData).returns(testTypeInfo);
Table in = tEnv.fromDataStream(srcDs, $("a"), $("b"), $("c"), $("proc").proctime());
tEnv.registerTable(srcTableName, in);
// perform a temporal table join query
String dimJoinQuery = "SELECT" + " a," + " b," + " h.family1.col1," + " h.family2.col1," + " h.family2.col2," + " h.family3.col1," + " h.family3.col2," + " h.family3.col3," + " h.family4.col1," + " h.family4.col2," + " h.family4.col3," + " h.family4.col4 " + " FROM src JOIN " + TEST_TABLE_1 + " FOR SYSTEM_TIME AS OF src.proc as h ON src.a = h.rowkey";
Iterator<Row> collected = tEnv.executeSql(dimJoinQuery).collect();
List<String> result = CollectionUtil.iteratorToList(collected).stream().map(Row::toString).sorted().collect(Collectors.toList());
List<String> expected = new ArrayList<>();
expected.add("+I[1, 1, 10, Hello-1, 100, 1.01, false, Welt-1, 2019-08-18T19:00, 2019-08-18, 19:00, 12345678.0001]");
expected.add("+I[2, 2, 20, Hello-2, 200, 2.02, true, Welt-2, 2019-08-18T19:01, 2019-08-18, 19:01, 12345678.0002]");
expected.add("+I[3, 2, 30, Hello-3, 300, 3.03, false, Welt-3, 2019-08-18T19:02, 2019-08-18, 19:02, 12345678.0003]");
expected.add("+I[3, 3, 30, Hello-3, 300, 3.03, false, Welt-3, 2019-08-18T19:02, 2019-08-18, 19:02, 12345678.0003]");
assertEquals(expected, result);
}
use of org.apache.flink.table.api.bridge.java.StreamTableEnvironment in project flink by apache.
the class AvroTypesITCase method testAvroToAvro.
@Test
public void testAvroToAvro() {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
DataStream<User> ds = testData(env);
Table t = tEnv.fromDataStream(ds, selectFields(ds));
Table result = t.select($("*"));
List<User> results = CollectionUtil.iteratorToList(DataStreamUtils.collect(tEnv.toAppendStream(result, User.class)));
List<User> expected = Arrays.asList(USER_1, USER_2, USER_3);
assertEquals(expected, results);
}
use of org.apache.flink.table.api.bridge.java.StreamTableEnvironment in project flink by apache.
the class AvroTypesITCase method testAvroStringAccess.
@Test
public void testAvroStringAccess() {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
DataStream<User> ds = testData(env);
Table t = tEnv.fromDataStream(ds, selectFields(ds));
Table result = t.select($("name"));
List<Utf8> results = CollectionUtil.iteratorToList(result.execute().collect()).stream().map(row -> (Utf8) row.getField(0)).collect(Collectors.toList());
String expected = "Charlie\n" + "Terminator\n" + "Whatever";
TestBaseUtils.compareResultAsText(results, expected);
}
use of org.apache.flink.table.api.bridge.java.StreamTableEnvironment in project flink by apache.
the class AvroTypesITCase method testAvroObjectAccess.
@Test
public void testAvroObjectAccess() {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
DataStream<User> ds = testData(env);
Table t = tEnv.fromDataStream(ds, selectFields(ds));
Table result = t.filter($("type_nested").isNotNull()).select($("type_nested").flatten()).as("city", "num", "state", "street", "zip");
List<Address> results = CollectionUtil.iteratorToList(DataStreamUtils.collect(tEnv.toAppendStream(result, Address.class)));
String expected = USER_1.getTypeNested().toString();
TestBaseUtils.compareResultAsText(results, expected);
}
Aggregations