use of org.apache.flink.table.api.internal.TableImpl in project flink by apache.
the class HiveLookupJoinITCase method testLookupJoinBoundedPartitionedTable.
@Test
public void testLookupJoinBoundedPartitionedTable() throws Exception {
// constructs test data using dynamic partition
TableEnvironment batchEnv = HiveTestUtils.createTableEnvInBatchMode(SqlDialect.HIVE);
batchEnv.registerCatalog(hiveCatalog.getName(), hiveCatalog);
batchEnv.useCatalog(hiveCatalog.getName());
batchEnv.executeSql("insert overwrite bounded_partition_table values " + "(1,'a',08,2019,'08','01')," + "(1,'a',10,2020,'08','31')," + "(2,'a',21,2020,'08','31')," + "(2,'b',22,2020,'08','31')").await();
TableImpl flinkTable = (TableImpl) tableEnv.sqlQuery("select p.x, p.y, b.z, b.pt_year, b.pt_mon, b.pt_day from " + " default_catalog.default_database.probe as p" + " join bounded_partition_table for system_time as of p.p as b on p.x=b.x and p.y=b.y");
List<Row> results = CollectionUtil.iteratorToList(flinkTable.execute().collect());
assertEquals("[+I[1, a, 8, 2019, 08, 01], +I[1, a, 10, 2020, 08, 31], +I[2, b, 22, 2020, 08, 31]]", results.toString());
}
use of org.apache.flink.table.api.internal.TableImpl in project flink by apache.
the class HiveLookupJoinITCase method testLookupJoinPartitionedTableWithCreateTime.
@Test
public void testLookupJoinPartitionedTableWithCreateTime() throws Exception {
// constructs test data using dynamic partition
TableEnvironment batchEnv = HiveTestUtils.createTableEnvInBatchMode(SqlDialect.HIVE);
batchEnv.registerCatalog(hiveCatalog.getName(), hiveCatalog);
batchEnv.useCatalog(hiveCatalog.getName());
batchEnv.executeSql("insert overwrite partition_table_3 values " + "(1,'a',08,2020,'month1','01')," + "(1,'a',10,2020,'month2','02')," + "(2,'a',21,2020,'month1','02')," + "(2,'b',22,2020,'month3','20')," + "(3,'c',22,2020,'month3','20')," + "(3,'c',33,2017,'08','31')," + "(1,'a',101,2017,'09','01')," + "(2,'a',121,2019,'09','01')," + "(2,'b',122,2019,'09','01')").await();
// inert a new partition
batchEnv.executeSql("insert overwrite partition_table_3 values " + "(1,'a',101,2020,'08','01')," + "(2,'a',121,2020,'08','01')," + "(2,'b',122,2020,'08','01')").await();
TableImpl flinkTable = (TableImpl) tableEnv.sqlQuery("select p.x, p.y, b.z, b.pt_year, b.pt_mon, b.pt_day from " + " default_catalog.default_database.probe as p" + " join partition_table_3 for system_time as of p.p as b on p.x=b.x and p.y=b.y");
List<Row> results = CollectionUtil.iteratorToList(flinkTable.execute().collect());
assertEquals("[+I[1, a, 101, 2020, 08, 01], +I[2, b, 122, 2020, 08, 01]]", results.toString());
}
use of org.apache.flink.table.api.internal.TableImpl in project flink by apache.
the class HiveLookupJoinITCase method testLookupJoinTableWithColumnarStorage.
@Test
public void testLookupJoinTableWithColumnarStorage() throws Exception {
// constructs test data, as the DEFAULT_SIZE of VectorizedColumnBatch is 2048, we should
// write as least 2048 records to the test table.
List<Row> testData = new ArrayList<>(4096);
for (int i = 0; i < 4096; i++) {
testData.add(Row.of(String.valueOf(i)));
}
// constructs test data using values table
TableEnvironment batchEnv = HiveTestUtils.createTableEnvInBatchMode(SqlDialect.DEFAULT);
batchEnv.registerCatalog(hiveCatalog.getName(), hiveCatalog);
batchEnv.useCatalog(hiveCatalog.getName());
String dataId = TestValuesTableFactory.registerData(testData);
batchEnv.executeSql(String.format("create table value_source(x string, p as proctime()) with (" + "'connector' = 'values', 'data-id' = '%s', 'bounded'='true')", dataId));
batchEnv.executeSql("insert overwrite columnar_table select x from value_source").await();
TableImpl flinkTable = (TableImpl) tableEnv.sqlQuery("select t.x as x1, c.x as x2 from value_source t " + "left join columnar_table for system_time as of t.p c " + "on t.x = c.x where c.x is null");
List<Row> results = CollectionUtil.iteratorToList(flinkTable.execute().collect());
assertTrue("All records should be able to be joined, and the final results should be empty.", results.size() == 0);
}
use of org.apache.flink.table.api.internal.TableImpl in project flink by apache.
the class TableEnvHiveConnectorITCase method testDefaultPartitionName.
@Test
public void testDefaultPartitionName() throws Exception {
TableEnvironment tableEnv = getTableEnvWithHiveCatalog();
tableEnv.executeSql("create database db1");
tableEnv.executeSql("create table db1.src (x int, y int)");
tableEnv.executeSql("create table db1.part (x int) partitioned by (y int)");
HiveTestUtils.createTextTableInserter(hiveCatalog, "db1", "src").addRow(new Object[] { 1, 1 }).addRow(new Object[] { 2, null }).commit();
// test generating partitions with default name
tableEnv.executeSql("insert into db1.part select * from db1.src").await();
HiveConf hiveConf = hiveCatalog.getHiveConf();
String defaultPartName = hiveConf.getVar(HiveConf.ConfVars.DEFAULTPARTITIONNAME);
Table hiveTable = hmsClient.getTable("db1", "part");
Path defaultPartPath = new Path(hiveTable.getSd().getLocation(), "y=" + defaultPartName);
FileSystem fs = defaultPartPath.getFileSystem(hiveConf);
assertTrue(fs.exists(defaultPartPath));
TableImpl flinkTable = (TableImpl) tableEnv.sqlQuery("select y, x from db1.part order by x");
List<Row> rows = CollectionUtil.iteratorToList(flinkTable.execute().collect());
assertEquals("[+I[1, 1], +I[null, 2]]", rows.toString());
tableEnv.executeSql("drop database db1 cascade");
}
use of org.apache.flink.table.api.internal.TableImpl in project flink by apache.
the class HiveLookupJoinITCase method testLookupJoinPartitionedTableWithPartitionTime.
@Test
public void testLookupJoinPartitionedTableWithPartitionTime() throws Exception {
// constructs test data using dynamic partition
TableEnvironment batchEnv = HiveTestUtils.createTableEnvInBatchMode(SqlDialect.HIVE);
batchEnv.registerCatalog(hiveCatalog.getName(), hiveCatalog);
batchEnv.useCatalog(hiveCatalog.getName());
batchEnv.executeSql("insert overwrite partition_table_2 values " + "(1,'a',08,2020,'08','01')," + "(1,'a',10,2020,'08','31')," + "(2,'a',21,2019,'08','31')," + "(2,'b',22,2020,'08','31')," + "(3,'c',33,2017,'08','31')," + "(1,'a',101,2017,'09','01')," + "(2,'a',121,2019,'09','01')," + "(2,'b',122,2019,'09','01')").await();
TableImpl flinkTable = (TableImpl) tableEnv.sqlQuery("select p.x, p.y, b.z, b.pt_year, b.pt_mon, b.pt_day from " + " default_catalog.default_database.probe as p" + " join partition_table_2 for system_time as of p.p as b on p.x=b.x and p.y=b.y");
List<Row> results = CollectionUtil.iteratorToList(flinkTable.execute().collect());
assertEquals("[+I[1, a, 10, 2020, 08, 31], +I[2, b, 22, 2020, 08, 31]]", results.toString());
}
Aggregations