use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project hive by apache.
the class HivePointLookupOptimizerRule method onMatch.
public void onMatch(RelOptRuleCall call) {
final Filter filter = call.rel(0);
final RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
final RexNode condition = RexUtil.pullFactors(rexBuilder, filter.getCondition());
// 1. We try to transform possible candidates
RexTransformIntoInClause transformIntoInClause = new RexTransformIntoInClause(rexBuilder, filter, minNumORClauses);
RexNode newCondition = transformIntoInClause.apply(condition);
// 2. We merge IN expressions
RexMergeInClause mergeInClause = new RexMergeInClause(rexBuilder);
newCondition = mergeInClause.apply(newCondition);
// 3. If we could not transform anything, we bail out
if (newCondition.toString().equals(condition.toString())) {
return;
}
// 4. We create the filter with the new condition
RelNode newFilter = filter.copy(filter.getTraitSet(), filter.getInput(), newCondition);
call.transformTo(newFilter);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project druid by druid-io.
the class DruidFilterRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
final Filter filter = call.rel(0);
final DruidRel druidRel = call.rel(1);
if (druidRel.getQueryBuilder().getFilter() != null || druidRel.getQueryBuilder().getSelectProjection() != null || druidRel.getQueryBuilder().getGrouping() != null) {
return;
}
final DimFilter dimFilter = Expressions.toFilter(operatorTable, druidRel.getPlannerContext(), druidRel.getSourceRowSignature(), filter.getCondition());
if (dimFilter != null) {
call.transformTo(druidRel.withQueryBuilder(druidRel.getQueryBuilder().withFilter(dimFilter)));
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project calcite by apache.
the class FilterAggregateTransposeRule method onMatch.
// ~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
final Filter filterRel = call.rel(0);
final Aggregate aggRel = call.rel(1);
final List<RexNode> conditions = RelOptUtil.conjunctions(filterRel.getCondition());
final RexBuilder rexBuilder = filterRel.getCluster().getRexBuilder();
final List<RelDataTypeField> origFields = aggRel.getRowType().getFieldList();
final int[] adjustments = new int[origFields.size()];
int j = 0;
for (int i : aggRel.getGroupSet()) {
adjustments[j] = i - j;
j++;
}
final List<RexNode> pushedConditions = Lists.newArrayList();
final List<RexNode> remainingConditions = Lists.newArrayList();
for (RexNode condition : conditions) {
ImmutableBitSet rCols = RelOptUtil.InputFinder.bits(condition);
if (canPush(aggRel, rCols)) {
pushedConditions.add(condition.accept(new RelOptUtil.RexInputConverter(rexBuilder, origFields, aggRel.getInput(0).getRowType().getFieldList(), adjustments)));
} else {
remainingConditions.add(condition);
}
}
final RelBuilder builder = call.builder();
RelNode rel = builder.push(aggRel.getInput()).filter(pushedConditions).build();
if (rel == aggRel.getInput(0)) {
return;
}
rel = aggRel.copy(aggRel.getTraitSet(), ImmutableList.of(rel));
rel = builder.push(rel).filter(remainingConditions).build();
call.transformTo(rel);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project calcite by apache.
the class FilterMergeRule method onMatch.
// ~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
final Filter topFilter = call.rel(0);
final Filter bottomFilter = call.rel(1);
// use RexPrograms to merge the two FilterRels into a single program
// so we can convert the two LogicalFilter conditions to directly
// reference the bottom LogicalFilter's child
RexBuilder rexBuilder = topFilter.getCluster().getRexBuilder();
RexProgram bottomProgram = createProgram(bottomFilter);
RexProgram topProgram = createProgram(topFilter);
RexProgram mergedProgram = RexProgramBuilder.mergePrograms(topProgram, bottomProgram, rexBuilder);
RexNode newCondition = mergedProgram.expandLocalRef(mergedProgram.getCondition());
final RelBuilder relBuilder = call.builder();
relBuilder.push(bottomFilter.getInput()).filter(newCondition);
call.transformTo(relBuilder.build());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project calcite by apache.
the class FilterProjectTransposeRule method onMatch.
// ~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
final Filter filter = call.rel(0);
final Project project = call.rel(1);
if (RexOver.containsOver(project.getProjects(), null)) {
// it can be pushed down. For now we don't support this.
return;
}
if (RexUtil.containsCorrelation(filter.getCondition())) {
// Correlate from being de-correlated.
return;
}
// convert the filter to one that references the child of the project
RexNode newCondition = RelOptUtil.pushPastProject(filter.getCondition(), project);
final RelBuilder relBuilder = call.builder();
RelNode newFilterRel;
if (copyFilter) {
newFilterRel = filter.copy(filter.getTraitSet(), project.getInput(), RexUtil.removeNullabilityCast(relBuilder.getTypeFactory(), newCondition));
} else {
newFilterRel = relBuilder.push(project.getInput()).filter(newCondition).build();
}
RelNode newProjRel = copyProject ? project.copy(project.getTraitSet(), newFilterRel, project.getProjects(), project.getRowType()) : relBuilder.push(newFilterRel).project(project.getProjects(), project.getRowType().getFieldNames()).build();
call.transformTo(newProjRel);
}
Aggregations