Search in sources :

Example 6 with BeamCalcRel

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);
}
Also used : BeamCalcRel(org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel) BeamRelNode(org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode) Test(org.junit.Test)

Example 7 with BeamCalcRel

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));
}
Also used : BeamCalcRel(org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel) BeamRelNode(org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode) BeamIOSourceRel(org.apache.beam.sdk.extensions.sql.impl.rel.BeamIOSourceRel) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 8 with BeamCalcRel

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);
    }
}
Also used : BeamCalcRel(org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel) BeamRelNode(org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode) Pair(org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Example 9 with BeamCalcRel

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"));
}
Also used : BeamCalcRel(org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel) BeamRelNode(org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode) BeamPushDownIOSourceRel(org.apache.beam.sdk.extensions.sql.impl.rel.BeamPushDownIOSourceRel) BeamAggregationRel(org.apache.beam.sdk.extensions.sql.impl.rel.BeamAggregationRel) BeamIOSourceRel(org.apache.beam.sdk.extensions.sql.impl.rel.BeamIOSourceRel) Test(org.junit.Test)

Aggregations

BeamCalcRel (org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel)9 BeamRelNode (org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode)8 Test (org.junit.Test)8 BeamIOSourceRel (org.apache.beam.sdk.extensions.sql.impl.rel.BeamIOSourceRel)5 Row (org.apache.beam.sdk.values.Row)4 Pair (org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair)1 BeamAggregationRel (org.apache.beam.sdk.extensions.sql.impl.rel.BeamAggregationRel)1 BeamPushDownIOSourceRel (org.apache.beam.sdk.extensions.sql.impl.rel.BeamPushDownIOSourceRel)1 MongoDbFilter (org.apache.beam.sdk.extensions.sql.meta.provider.mongodb.MongoDbTable.MongoDbFilter)1 RelNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode)1 Calc (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Calc)1 LogicalCalc (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalCalc)1