use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.
the class JdbcDriverTest method testInsertIntoCreatedTable.
@Test
public void testInsertIntoCreatedTable() throws Exception {
TestTableProvider tableProvider = new TestTableProvider();
Connection connection = JdbcDriver.connect(tableProvider, PipelineOptionsFactory.create());
connection.createStatement().executeUpdate("CREATE EXTERNAL TABLE person (id BIGINT, name VARCHAR) TYPE 'test'");
connection.createStatement().executeUpdate("CREATE EXTERNAL TABLE person_src (id BIGINT, name VARCHAR) TYPE 'test'");
tableProvider.addRows("person_src", row(1L, "aaa"), row(2L, "bbb"));
connection.createStatement().execute("INSERT INTO person SELECT id, name FROM person_src");
ResultSet selectResult = connection.createStatement().executeQuery("SELECT id, name FROM person");
List<Row> resultRows = readResultSet(selectResult).stream().map(resultValues -> resultValues.stream().collect(toRow(BASIC_SCHEMA))).collect(Collectors.toList());
assertThat(resultRows, containsInAnyOrder(row(1L, "aaa"), row(2L, "bbb")));
}
use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.
the class ThreeTablesSchema method testSystemNotReorderingWithoutRules.
@Test
public void testSystemNotReorderingWithoutRules() {
TestTableProvider tableProvider = new TestTableProvider();
createThreeTables(tableProvider);
List<RelOptRule> ruleSet = BeamRuleSets.getRuleSets().stream().flatMap(rules -> StreamSupport.stream(rules.spliterator(), false)).filter(rule -> !(rule instanceof BeamJoinPushThroughJoinRule)).filter(rule -> !(rule instanceof BeamJoinAssociateRule)).filter(rule -> !(rule instanceof JoinCommuteRule)).collect(Collectors.toList());
BeamSqlEnv env = BeamSqlEnv.builder(tableProvider).setPipelineOptions(PipelineOptionsFactory.create()).setRuleSets(ImmutableList.of(RuleSets.ofList(ruleSet))).build();
// This is Join(Join(medium, large), small) which should be converted to a join that large table
// is on the top.
BeamRelNode parsedQuery = env.parseQuery("select * from medium_table " + " JOIN large_table on large_table.medium_key = medium_table.large_key " + " JOIN small_table on medium_table.small_key = small_table.medium_key ");
assertTopTableInJoins(parsedQuery, "small_table");
}
use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.
the class ThreeTablesSchema method testSystemReorderingMediumLargeSmall.
@Test
public void testSystemReorderingMediumLargeSmall() {
TestTableProvider tableProvider = new TestTableProvider();
createThreeTables(tableProvider);
BeamSqlEnv env = BeamSqlEnv.withTableProvider(tableProvider);
// This is Join(Join(medium, large), small) which should be converted to a join that large table
// is on the top.
BeamRelNode parsedQuery = env.parseQuery("select * from medium_table " + " JOIN large_table on large_table.medium_key = medium_table.large_key " + " JOIN small_table on medium_table.small_key = small_table.medium_key ");
assertTopTableInJoins(parsedQuery, "large_table");
}
use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.
the class ThreeTablesSchema method testTableSizes.
@Test
public void testTableSizes() {
TestTableProvider tableProvider = new TestTableProvider();
createThreeTables(tableProvider);
Assert.assertEquals(1d, tableProvider.buildBeamSqlTable(tableProvider.getTable("small_table")).getTableStatistics(null).getRowCount(), 0.01);
Assert.assertEquals(3d, tableProvider.buildBeamSqlTable(tableProvider.getTable("medium_table")).getTableStatistics(null).getRowCount(), 0.01);
Assert.assertEquals(100d, tableProvider.buildBeamSqlTable(tableProvider.getTable("large_table")).getTableStatistics(null).getRowCount(), 0.01);
}
use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.
the class ThreeTablesSchema method testSystemNotReorderingSmallMediumLarge.
@Test
public void testSystemNotReorderingSmallMediumLarge() {
TestTableProvider tableProvider = new TestTableProvider();
createThreeTables(tableProvider);
BeamSqlEnv env = BeamSqlEnv.withTableProvider(tableProvider);
// This is a correct ordered join because large table is on the top. It should not change that.
BeamRelNode parsedQuery = env.parseQuery("select * from small_table " + " JOIN medium_table on medium_table.small_key = small_table.medium_key " + " JOIN large_table on large_table.medium_key = medium_table.large_key ");
assertTopTableInJoins(parsedQuery, "large_table");
}
Aggregations