use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Calc in project storm by apache.
the class StreamsCalcRule method convert.
@Override
public RelNode convert(RelNode rel) {
final Calc calc = (Calc) rel;
final RelNode input = calc.getInput();
return new StreamsCalcRel(calc.getCluster(), calc.getTraitSet().replace(StreamsLogicalConvention.INSTANCE), convert(input, input.getTraitSet().replace(StreamsLogicalConvention.INSTANCE)), calc.getProgram());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Calc in project beam by apache.
the class IOPushDownRuleTest method testIsProjectRenameOnlyProgram.
@Test
public void testIsProjectRenameOnlyProgram() {
List<Pair<Pair<String, Boolean>, Boolean>> tests = ImmutableList.of(// Selecting fields in a different order is only allowed with project push-down.
Pair.of(Pair.of("select unused2, name, id from TEST", true), true), Pair.of(Pair.of("select unused2, name, id from TEST", false), false), Pair.of(Pair.of("select id from TEST", false), true), Pair.of(Pair.of("select * from TEST", false), true), Pair.of(Pair.of("select id, name from TEST", false), true), Pair.of(Pair.of("select id+10 from TEST", false), false), // Note that we only care about projects.
Pair.of(Pair.of("select id from TEST where name='one'", false), true));
for (Pair<Pair<String, Boolean>, Boolean> test : tests) {
String sqlQuery = test.left.left;
boolean projectPushDownSupported = test.left.right;
boolean expectedAnswer = test.right;
BeamRelNode basicRel = sqlEnv.parseQuery(sqlQuery);
assertThat(basicRel, instanceOf(Calc.class));
Calc calc = (Calc) basicRel;
assertThat(test.toString(), BeamIOPushDownRule.INSTANCE.isProjectRenameOnlyProgram(calc.getProgram(), projectPushDownSupported), equalTo(expectedAnswer));
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Calc in project beam by apache.
the class TestTableProviderWithFilterPushDown method testIOSourceRel_withFilter_shouldProjectAllFields.
@Test
public void testIOSourceRel_withFilter_shouldProjectAllFields() {
String selectTableStatement = "SELECT name FROM TEST where name='two'";
BeamRelNode beamRelNode = sqlEnv.parseQuery(selectTableStatement);
PCollection<Row> result = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
assertThat(beamRelNode, instanceOf(BeamCalcRel.class));
// Condition should be pushed-down to IO level
assertNull(((Calc) beamRelNode).getProgram().getCondition());
assertThat(beamRelNode.getInput(0), instanceOf(BeamIOSourceRel.class));
List<String> projects = beamRelNode.getInput(0).getRowType().getFieldNames();
// When performing standalone filter push-down IO should project all fields.
assertThat(projects, containsInAnyOrder("unused1", "id", "name", "unused2", "b"));
assertEquals(Schema.builder().addStringField("name").build(), result.getSchema());
PAssert.that(result).containsInAnyOrder(row(result.getSchema(), "two"));
pipeline.run().waitUntilFinish(Duration.standardMinutes(2));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Calc in project beam by apache.
the class TestTableProviderWithFilterPushDown method testIOSourceRel_withUnsupportedFilter_calcPreservesCondition.
@Test
public void testIOSourceRel_withUnsupportedFilter_calcPreservesCondition() {
String selectTableStatement = "SELECT name FROM TEST where id+1=2";
BeamRelNode beamRelNode = sqlEnv.parseQuery(selectTableStatement);
PCollection<Row> result = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
assertThat(beamRelNode, instanceOf(BeamCalcRel.class));
// Unsupported condition should be preserved in a Calc
assertNotNull(((Calc) beamRelNode).getProgram().getCondition());
assertThat(beamRelNode.getInput(0), instanceOf(BeamIOSourceRel.class));
List<String> projects = beamRelNode.getInput(0).getRowType().getFieldNames();
// When performing standalone filter push-down IO should project all fields.
assertThat(projects, containsInAnyOrder("unused1", "id", "name", "unused2", "b"));
assertEquals(Schema.builder().addStringField("name").build(), result.getSchema());
PAssert.that(result).containsInAnyOrder(row(result.getSchema(), "one"));
pipeline.run().waitUntilFinish(Duration.standardMinutes(2));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Calc in project beam by apache.
the class TestTableProviderWithFilterPushDown method testIOSourceRel_withSupportedFilter_selectInRandomOrder.
@Test
public void testIOSourceRel_withSupportedFilter_selectInRandomOrder() {
String selectTableStatement = "SELECT unused2, id, name FROM TEST where b";
BeamRelNode beamRelNode = sqlEnv.parseQuery(selectTableStatement);
PCollection<Row> result = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
assertThat(beamRelNode, instanceOf(BeamCalcRel.class));
// Condition should be pushed-down to IO level
assertNull(((Calc) beamRelNode).getProgram().getCondition());
assertThat(beamRelNode.getInput(0), instanceOf(BeamIOSourceRel.class));
List<String> projects = beamRelNode.getInput(0).getRowType().getFieldNames();
// When performing standalone filter push-down IO should project all fields.
assertThat(projects, containsInAnyOrder("unused1", "id", "name", "unused2", "b"));
assertEquals(Schema.builder().addInt16Field("unused2").addInt32Field("id").addStringField("name").build(), result.getSchema());
PAssert.that(result).containsInAnyOrder(row(result.getSchema(), (short) 100, 1, "one"));
pipeline.run().waitUntilFinish(Duration.standardMinutes(2));
}
Aggregations