use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel in project beam by apache.
the class BigtableFilterTest method testIsSupported.
@Test
public void testIsSupported() {
BeamRelNode beamRelNode = sqlEnv.parseQuery(query);
assertThat(beamRelNode, instanceOf(BeamCalcRel.class));
BigtableFilter filter = new BigtableFilter(((BeamCalcRel) beamRelNode).getProgram().split().right, BASIC_SCHEMA);
assertThat("Query: '" + query + "' is expected to be " + (isSupported ? "supported." : "unsupported."), filter.getNotSupported().isEmpty() == isSupported);
}
use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel in project beam by apache.
the class TestTableProviderWithFilterAndProjectPushDown method testIOSourceRel_selectOneFieldsMoreThanOnce_withSupportedPredicate.
@Test
public void testIOSourceRel_selectOneFieldsMoreThanOnce_withSupportedPredicate() {
String selectTableStatement = "SELECT b, b, b, b, b FROM TEST where b";
// Calc must not be dropped
BeamRelNode beamRelNode = sqlEnv.parseQuery(selectTableStatement);
PCollection<Row> result = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
assertThat(beamRelNode, instanceOf(BeamCalcRel.class));
// Supported predicate should be pushed-down
assertNull(((BeamCalcRel) beamRelNode).getProgram().getCondition());
assertThat(beamRelNode.getInput(0), instanceOf(BeamIOSourceRel.class));
// Make sure project push-down was done
List<String> pushedFields = beamRelNode.getInput(0).getRowType().getFieldNames();
assertThat(pushedFields, containsInAnyOrder("b"));
assertEquals(Schema.builder().addBooleanField("b").addBooleanField("b0").addBooleanField("b1").addBooleanField("b2").addBooleanField("b3").build(), result.getSchema());
PAssert.that(result).containsInAnyOrder(row(result.getSchema(), true, true, true, true, true));
pipeline.run().waitUntilFinish(Duration.standardMinutes(2));
}
use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel in project beam by apache.
the class BigQueryFilterTest method testIsSupported.
@Test
public void testIsSupported() {
ImmutableList<Pair<String, Boolean>> sqlQueries = ImmutableList.of(Pair.of("select * from TEST where unused1=100", true), Pair.of("select * from TEST where unused1 in (100, 200)", true), Pair.of("select * from TEST where unused1+10=110", true), Pair.of("select * from TEST where b", true), Pair.of("select * from TEST where unused1>100 and unused1<=200 and id<>1 and (name='two' or id=2)", true), Pair.of("select * from TEST where unused2=200", true), Pair.of("select * from TEST where name like 'o%e'", true), // Functions involving more than one column are not supported yet.
Pair.of("select * from TEST where unused1=unused2 and id=2", false), Pair.of("select * from TEST where unused1+unused2=10", false));
for (Pair<String, Boolean> query : sqlQueries) {
String sql = query.getLeft();
Boolean isSupported = query.getRight();
BeamRelNode beamRelNode = sqlEnv.parseQuery(sql);
assertThat(beamRelNode, instanceOf(BeamCalcRel.class));
BigQueryFilter filter = new BigQueryFilter(((BeamCalcRel) beamRelNode).getProgram().split().right);
assertThat("Query: '" + sql + "' is expected to be " + (isSupported ? "supported." : "unsupported."), filter.getNotSupported().isEmpty() == isSupported);
}
}
use of org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel in project beam by apache.
the class BeamAggregateProjectMergeRuleTest method testBeamAggregateProjectMergeRule_withProjectTable_withPredicate.
@Test
public void testBeamAggregateProjectMergeRule_withProjectTable_withPredicate() {
// When an IO supports project push-down, Projects should be merged with an IO.
String sqlQuery = "select SUM(id) as id_sum from TEST_PROJECT where unused1=1 group by name";
BeamRelNode beamRel = sqlEnv.parseQuery(sqlQuery);
BeamAggregationRel aggregate = (BeamAggregationRel) beamRel.getInput(0);
BeamCalcRel calc = (BeamCalcRel) aggregate.getInput();
BeamIOSourceRel ioSourceRel = (BeamIOSourceRel) calc.getInput();
// Make sure project push-down took place.
assertThat(ioSourceRel, instanceOf(BeamPushDownIOSourceRel.class));
assertThat(ioSourceRel.getRowType().getFieldNames(), containsInAnyOrder("name", "id", "unused1"));
}
Aggregations