private PrelWithDictionaryInfo visitFilter(FilterPrel filterPrel, Void value) { assert filterPrel.getInputs().size() == 1; PrelWithDictionaryInfo newInput = ((Prel)filterPrel.getInput()).accept(this, value); if (filterPrel.getInput() == newInput.getPrel()) { return new PrelWithDictionaryInfo(filterPrel); // none of fields are encoded } final Set<Integer> fieldsUsed = Sets.newHashSet(); final InputReferenceRexVisitor visitor = new InputReferenceRexVisitor(fieldsUsed); filterPrel.getCondition().accept(visitor); // decode used inputs by this filter newInput = newInput.decodeFields(fieldsUsed); return new PrelWithDictionaryInfo((Prel)filterPrel.copy(filterPrel.getTraitSet(), newInput.getPrel(), filterPrel.getCondition()), newInput.getFields()); }
@Override public org.apache.calcite.rel.core.Filter copy(RelTraitSet traitSet, RelNode input, RexNode condition) { return new FilterPrel(getCluster(), traitSet, input, condition); }
@Override public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException { Prel child = (Prel) this.getInput(); PhysicalOperator childPOP = child.getPhysicalOperator(creator); Filter p = new Filter(childPOP, getFilterExpression(new ParseContext(PrelUtil.getSettings(getCluster()))), 1.0f); return creator.addMetadata(this, p); }
protected void doMatch(RelOptRuleCall call, InfoSchemaScanPrel scan, ProjectPrel project, FilterPrel filter) { if(scan.hasFilter()) { return; } PushdownResult result = ExpressionConverter.pushdown(scan.getCluster().getRexBuilder(), scan.getRowType(), filter.getCondition()); if(result.getQuery() == null) { return; //no filter pushdown ==> No transformation. } RelNode input = new InfoSchemaScanPrel(scan.getCluster(), scan.getTraitSet(), scan.getTable(), scan.getTableMetadata(), result.getQuery(), scan.getProjectedColumns(), scan.getObservedRowcountAdjustment()); if (project != null) { input = project.copy(project.getTraitSet(), input, project.getProjects(), filter.getRowType()); } if (result.getRemainder() == null) { // Filter can be removed as all expressions in the filter are converted and pushed to scan call.transformTo(input); } else { call.transformTo(filter.copy(filter.getTraitSet(), ImmutableList.of(input))); } } }
protected void doPushFilterToScan(final RelOptRuleCall call, final FilterPrel filter, final ProjectPrel project, final HBaseScanPrel scan, final RexNode condition) { final LogicalExpression conditionExp = RexToExpr.toExpr(new ParseContext(PrelUtil.getPlannerSettings(call.getPlanner())), scan.getRowType(), scan.getCluster().getRexBuilder(), condition); final HBaseFilterBuilder hbaseFilterBuilder = new HBaseFilterBuilder(TableNameGetter.getTableName(scan.getTableMetadata().getName()), scan.getStartRow(), scan.getStopRow(), scan.getFilter(), conditionExp); final HBaseScanSpec newScanSpec = hbaseFilterBuilder.parseTree(); if (newScanSpec == null) { return; //no filter pushdown ==> No transformation. } Predicate<DatasetSplit> predicate = newScanSpec.getRowKeyPredicate(); TableMetadata metadata = scan.getTableMetadata(); if(predicate != null) { try { metadata = metadata.prune(predicate); } catch (NamespaceException ex) { throw Throwables.propagate(ex); } } final HBaseScanPrel newScanPrel = new HBaseScanPrel(scan.getCluster(), scan.getTraitSet(), scan.getTable(), metadata, scan.getProjectedColumns(), scan.getObservedRowcountAdjustment(), newScanSpec.getStartRow(), newScanSpec.getStopRow(), newScanSpec.getSerializedFilter()); // Depending on whether is a project in the middle, assign either scan or copy of project to childRel. final RelNode childRel = project == null ? newScanPrel : project.copy(project.getTraitSet(), ImmutableList.of((RelNode)newScanPrel));; if (hbaseFilterBuilder.isAllExpressionsConverted()) { /* * Since we could convert the entire filter condition expression into an HBase filter, * we can eliminate the filter operator altogether. */ call.transformTo(childRel); } else { call.transformTo(filter.copy(filter.getTraitSet(), ImmutableList.of(childRel))); } }
@Override public void onMatch(RelOptRuleCall call) { final FilterPrel filter = call.rel(0); final HBaseScanPrel scan = call.rel(1); final RexNode condition = filter.getCondition(); /* * The rule can get triggered again due to the transformed "scan => filter" sequence * created by the earlier execution of this rule when we could not do a complete * conversion of Calcite Filter's condition to HBase Filter. In such cases, we rely upon * this flag to not do a re-processing of the rule on the already transformed call. */ if(scan.isFilterPushed()) { return; } doPushFilterToScan(call, filter, null, scan, condition); }
@Override public RelNode convertChild(FilterRel filter, RelNode rel) { return new FilterPrel(filter.getCluster(), rel.getTraitSet(), rel, filter.getCondition()); }
@Override public Iterator<Prel> iterator() { return PrelUtil.iter(getInput()); }
@Override public void onMatch(RelOptRuleCall call) { final FilterPrel filter = call.rel(0); final ProjectPrel project = call.rel(1); final HBaseScanPrel scan = call.rel(2); /* * The rule can get triggered again due to the transformed "scan => filter" sequence * created by the earlier execution of this rule when we could not do a complete * conversion of Calcite Filter's condition to HBase Filter. In such cases, we rely upon * this flag to not do a re-processing of the rule on the already transformed call. */ if(scan.isFilterPushed()) { return; } // convert the filter to one that references the child of the project final RexNode condition = RelOptUtil.pushPastProject(filter.getCondition(), project); doPushFilterToScan(call, filter, project, scan, condition); }
@Override public void onMatch(RelOptRuleCall call) { final FilterRel filter = (FilterRel) call.rel(0); final RelNode input = filter.getInput(); RelTraitSet traits = input.getTraitSet().plus(Prel.PHYSICAL); RelNode convertedInput = convert(input, traits); boolean transform = new Subset(call).go(filter, convertedInput); if (!transform) { call.transformTo(new FilterPrel(filter.getCluster(), convertedInput.getTraitSet(), convertedInput, filter.getCondition())); } }
RexLiteral condition = builder.makeLiteral(true); // TRUE condition for the NLJ FilterPrel newFilterRel = new FilterPrel(join.getCluster(), convertedLeft.getTraitSet(), new NestedLoopJoinPrel(join.getCluster(), convertedLeft.getTraitSet(), convertedLeft, convertedRight, condition, join.getJoinType()),