use of org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv 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.impl.BeamSqlEnv 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.impl.BeamSqlEnv 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");
}
use of org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv in project beam by apache.
the class BigQueryReadWriteIT method testSQLWrite.
@Test
public void testSQLWrite() {
BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(new BigQueryTableProvider());
String createTableStatement = "CREATE EXTERNAL TABLE TEST( \n" + " c_bigint BIGINT, \n" + " c_tinyint TINYINT, \n" + " c_smallint SMALLINT, \n" + " c_integer INTEGER, \n" + " c_float FLOAT, \n" + " c_double DOUBLE, \n" + " c_boolean BOOLEAN, \n" + " c_timestamp TIMESTAMP, \n" + " c_varchar VARCHAR, \n " + " c_char CHAR, \n" + " c_arr ARRAY<VARCHAR> \n" + ") \n" + "TYPE 'bigquery' \n" + "LOCATION '" + bigQueryTestingTypes.tableSpec() + "'";
sqlEnv.executeDdl(createTableStatement);
String insertStatement = "INSERT INTO TEST VALUES (" + "9223372036854775807, " + "127, " + "32767, " + "2147483647, " + "1.0, " + "1.0, " + "TRUE, " + "TIMESTAMP '2018-05-28 20:17:40.123', " + "'varchar', " + "'char', " + "ARRAY['123', '456']" + ")";
sqlEnv.parseQuery(insertStatement);
BeamSqlRelUtils.toPCollection(pipeline, sqlEnv.parseQuery(insertStatement));
pipeline.run().waitUntilFinish(Duration.standardMinutes(5));
bigQueryTestingTypes.assertThatAllRows(SOURCE_SCHEMA_TWO).now(containsInAnyOrder(row(SOURCE_SCHEMA_TWO, 9223372036854775807L, (byte) 127, (short) 32767, 2147483647, (float) 1.0, 1.0, true, parseTimestampWithUTCTimeZone("2018-05-28 20:17:40.123"), "varchar", "char", Arrays.asList("123", "456"))));
}
use of org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv in project beam by apache.
the class BigQueryReadWriteIT method testSQLRead_withExport.
@Test
public void testSQLRead_withExport() throws IOException {
bigQueryTestingTypes.insertRows(SOURCE_SCHEMA_TWO, row(SOURCE_SCHEMA_TWO, 9223372036854775807L, (byte) 127, (short) 32767, 2147483647, (float) 1.0, 1.0, true, parseTimestampWithUTCTimeZone("2018-05-28 20:17:40.123"), "varchar", "char", Arrays.asList("123", "456")));
BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(new BigQueryTableProvider());
String createTableStatement = "CREATE EXTERNAL TABLE TEST( \n" + " c_bigint BIGINT, \n" + " c_tinyint TINYINT, \n" + " c_smallint SMALLINT, \n" + " c_integer INTEGER, \n" + " c_float FLOAT, \n" + " c_double DOUBLE, \n" + " c_boolean BOOLEAN, \n" + " c_timestamp TIMESTAMP, \n" + " c_varchar VARCHAR, \n " + " c_char CHAR, \n" + " c_arr ARRAY<VARCHAR> \n" + ") \n" + "TYPE 'bigquery' \n" + "LOCATION '" + bigQueryTestingTypes.tableSpec() + "'" + "TBLPROPERTIES " + "'{ " + METHOD_PROPERTY + ": \"" + Method.EXPORT.toString() + "\" }'";
sqlEnv.executeDdl(createTableStatement);
String selectTableStatement = "SELECT * FROM TEST";
PCollection<Row> output = BeamSqlRelUtils.toPCollection(readPipeline, sqlEnv.parseQuery(selectTableStatement));
PAssert.that(output).containsInAnyOrder(row(SOURCE_SCHEMA_TWO, 9223372036854775807L, (byte) 127, (short) 32767, 2147483647, (float) 1.0, 1.0, true, parseTimestampWithUTCTimeZone("2018-05-28 20:17:40.123"), "varchar", "char", Arrays.asList("123", "456")));
PipelineResult.State state = readPipeline.run().waitUntilFinish(Duration.standardMinutes(5));
assertThat(state, equalTo(State.DONE));
}
Aggregations