use of org.apache.calcite.rel.logical.LogicalFilter in project storm by apache.
the class TestRelNodeCompiler method testFilter.
@Test
public void testFilter() throws Exception {
String sql = "SELECT ID + 1 FROM FOO WHERE ID > 3";
TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverDummyTable(sql);
JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
LogicalProject project = (LogicalProject) state.tree();
LogicalFilter filter = (LogicalFilter) project.getInput();
try (StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw)) {
RelNodeCompiler compiler = new RelNodeCompiler(pw, typeFactory);
// standalone mode doesn't use inputstreams argument
compiler.visitFilter(filter, Collections.EMPTY_LIST);
pw.flush();
Assert.assertThat(sw.toString(), containsString("> 3"));
}
try (StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw)) {
RelNodeCompiler compiler = new RelNodeCompiler(pw, typeFactory);
// standalone mode doesn't use inputstreams argument
compiler.visitProject(project, Collections.EMPTY_LIST);
pw.flush();
Assert.assertThat(sw.toString(), containsString(" + 1"));
}
}
use of org.apache.calcite.rel.logical.LogicalFilter in project calcite by apache.
the class FilterCalcMergeRule method onMatch.
// ~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
final LogicalFilter filter = call.rel(0);
final LogicalCalc calc = call.rel(1);
// We'll have chance to merge later, when the over is expanded.
if (calc.getProgram().containsAggs()) {
return;
}
// Create a program containing the filter.
final RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
final RexProgramBuilder progBuilder = new RexProgramBuilder(calc.getRowType(), rexBuilder);
progBuilder.addIdentity();
progBuilder.addCondition(filter.getCondition());
RexProgram topProgram = progBuilder.getProgram();
RexProgram bottomProgram = calc.getProgram();
// Merge the programs together.
RexProgram mergedProgram = RexProgramBuilder.mergePrograms(topProgram, bottomProgram, rexBuilder);
final LogicalCalc newCalc = LogicalCalc.create(calc.getInput(), mergedProgram);
call.transformTo(newCalc);
}
use of org.apache.calcite.rel.logical.LogicalFilter in project calcite by apache.
the class FilterMultiJoinMergeRule method onMatch.
// ~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
LogicalFilter filter = call.rel(0);
MultiJoin multiJoin = call.rel(1);
MultiJoin newMultiJoin = new MultiJoin(multiJoin.getCluster(), multiJoin.getInputs(), multiJoin.getJoinFilter(), multiJoin.getRowType(), multiJoin.isFullOuterJoin(), multiJoin.getOuterJoinConditions(), multiJoin.getJoinTypes(), multiJoin.getProjFields(), multiJoin.getJoinFieldRefCountsMap(), filter.getCondition());
call.transformTo(newMultiJoin);
}
use of org.apache.calcite.rel.logical.LogicalFilter in project calcite by apache.
the class FrameworksTest method testOptimize.
@Test
public void testOptimize() {
RelNode x = Frameworks.withPlanner(new Frameworks.PlannerAction<RelNode>() {
public RelNode apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema) {
final RelDataTypeFactory typeFactory = cluster.getTypeFactory();
final Table table = new AbstractTable() {
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
final RelDataType stringType = typeFactory.createJavaType(String.class);
final RelDataType integerType = typeFactory.createJavaType(Integer.class);
return typeFactory.builder().add("s", stringType).add("i", integerType).build();
}
};
// "SELECT * FROM myTable"
final RelOptAbstractTable relOptTable = new RelOptAbstractTable(relOptSchema, "myTable", table.getRowType(typeFactory)) {
};
final EnumerableTableScan tableRel = EnumerableTableScan.create(cluster, relOptTable);
// "WHERE i > 1"
final RexBuilder rexBuilder = cluster.getRexBuilder();
final RexNode condition = rexBuilder.makeCall(SqlStdOperatorTable.GREATER_THAN, rexBuilder.makeFieldAccess(rexBuilder.makeRangeReference(tableRel), "i", true), rexBuilder.makeExactLiteral(BigDecimal.ONE));
final LogicalFilter filter = LogicalFilter.create(tableRel, condition);
// Specify that the result should be in Enumerable convention.
final RelNode rootRel = filter;
final RelOptPlanner planner = cluster.getPlanner();
RelTraitSet desiredTraits = cluster.traitSet().replace(EnumerableConvention.INSTANCE);
final RelNode rootRel2 = planner.changeTraits(rootRel, desiredTraits);
planner.setRoot(rootRel2);
// Now, plan.
return planner.findBestExp();
}
});
String s = RelOptUtil.dumpPlan("", x, SqlExplainFormat.TEXT, SqlExplainLevel.DIGEST_ATTRIBUTES);
assertThat(Util.toLinux(s), equalTo("EnumerableFilter(condition=[>($1, 1)])\n" + " EnumerableTableScan(table=[[myTable]])\n"));
}
use of org.apache.calcite.rel.logical.LogicalFilter in project calcite by apache.
the class SemiJoinFilterTransposeRule method onMatch.
// ~ Methods ----------------------------------------------------------------
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
SemiJoin semiJoin = call.rel(0);
LogicalFilter filter = call.rel(1);
RelNode newSemiJoin = SemiJoin.create(filter.getInput(), semiJoin.getRight(), semiJoin.getCondition(), semiJoin.getLeftKeys(), semiJoin.getRightKeys());
final RelFactories.FilterFactory factory = RelFactories.DEFAULT_FILTER_FACTORY;
RelNode newFilter = factory.createFilter(newSemiJoin, filter.getCondition());
call.transformTo(newFilter);
}
Aggregations