private static List<RexNode> transformRex( List<RexNode> nodes, final List<RelDataTypeField> oldFields, final List<RelDataTypeField> newFields) { RexShuttle shuttle = new RexShuttle() { @Override public RexNode visitInputRef(RexInputRef ref) { RelDataTypeField f = oldFields.get(ref.getIndex()); for (int index = 0; index < newFields.size(); index++) { RelDataTypeField newf = newFields.get(index); if (f.getKey().equals(newf.getKey()) && f.getValue() == newf.getValue()) { return new RexInputRef(index, f.getValue()); } } throw MatchFailed.INSTANCE; } }; return shuttle.apply(nodes); } }
@Override public RelNode accept(RexShuttle shuttle) { RexNode joinFilter = shuttle.apply(this.condition); if (joinFilter == this.condition) { return this; } return new HiveMultiJoin( getCluster(), inputs, joinFilter, rowType, joinInputs, joinTypes, filters); }
@Override public RelNode accept(RexShuttle shuttle) { RexNode joinFilter = shuttle.apply(this.condition); if (joinFilter == this.condition) { return this; } return new HiveMultiJoin( getCluster(), inputs, joinFilter, rowType, joinInputs, joinTypes, filters); }
public UnifyResult apply(UnifyRuleCall call) { final MutableProject target = (MutableProject) call.target; final MutableProject query = (MutableProject) call.query; final RexShuttle shuttle = getRexShuttle(target); final List<RexNode> newProjects; try { newProjects = shuttle.apply(query.getProjects()); } catch (MatchFailed e) { return null; } final MutableProject newProject = MutableProject.of( query.getRowType(), target, newProjects); final MutableRel newProject2 = MutableRels.strip(newProject); return call.result(newProject2); } }
public UnifyResult apply(UnifyRuleCall call) { final MutableProject target = (MutableProject) call.target; final MutableScan query = (MutableScan) call.query; // We do not need to check query's parent type to avoid duplication // of ProjectToProjectUnifyRule or FilterToProjectUnifyRule, since // SubstitutionVisitor performs a top-down match. if (!query.equals(target.getInput())) { return null; } final RexShuttle shuttle = getRexShuttle(target); final RexBuilder rexBuilder = target.cluster.getRexBuilder(); final List<RexNode> newProjects; try { newProjects = (List<RexNode>) shuttle.apply(rexBuilder.identityProjects(query.getRowType())); } catch (MatchFailed e) { return null; } final MutableProject newProject = MutableProject.of( query.getRowType(), target, newProjects); final MutableRel newProject2 = MutableRels.strip(newProject); return call.result(newProject2); } }
builder, 1, fieldCount, isCorrScalarQuery, hasNoWindowingAndNoGby); final RexShuttle shuttle = new ReplaceSubQueryShuttle(e, target); builder.filter(shuttle.apply(filter.getCondition())); builder.project(fields(builder, filter.getRowType().getFieldCount())); call.transformTo(builder.build()); logic, builder, 1, fieldCount, isCorrScalarQuery, hasNoWindowingAndNoGby); final RexShuttle shuttle = new ReplaceSubQueryShuttle(e, target); builder.project(shuttle.apply(project.getProjects()), project.getRowType().getFieldNames()); call.transformTo(builder.build());
public void onMatch(RelOptRuleCall call) { final Filter filter = call.rel(0); //final RelBuilder builder = call.builder(); //TODO: replace HiveSubQRemoveRelBuilder with calcite's once calcite 1.11.0 is released final HiveSubQRemoveRelBuilder builder = new HiveSubQRemoveRelBuilder(null, call.rel(0).getCluster(), null); final RexSubQuery e = RexUtil.SubQueryFinder.find(filter.getCondition()); assert e != null; final RelOptUtil.Logic logic = LogicVisitor.find(RelOptUtil.Logic.TRUE, ImmutableList.of(filter.getCondition()), e); builder.push(filter.getInput()); final int fieldCount = builder.peek().getRowType().getFieldCount(); assert(filter instanceof HiveFilter); Set<RelNode> corrScalarQueries = filter.getCluster().getPlanner().getContext().unwrap(Set.class); boolean isCorrScalarQuery = corrScalarQueries.contains(e.rel); final RexNode target = apply(e, HiveFilter.getVariablesSet(e), logic, builder, 1, fieldCount, isCorrScalarQuery); final RexShuttle shuttle = new ReplaceSubQueryShuttle(e, target); builder.filter(shuttle.apply(filter.getCondition())); builder.project(fields(builder, filter.getRowType().getFieldCount())); call.transformTo(builder.build()); } };
public void onMatch(RelOptRuleCall call) { final Project project = call.rel(0); //TODO: replace HiveSubQRemoveRelBuilder with calcite's once calcite 1.11.0 is released final HiveSubQRemoveRelBuilder builder = new HiveSubQRemoveRelBuilder(null, call.rel(0).getCluster(), null); final RexSubQuery e = RexUtil.SubQueryFinder.find(project.getProjects()); assert e != null; final RelOptUtil.Logic logic = LogicVisitor.find(RelOptUtil.Logic.TRUE_FALSE_UNKNOWN, project.getProjects(), e); builder.push(project.getInput()); final int fieldCount = builder.peek().getRowType().getFieldCount(); final RexNode target = apply(e, HiveFilter.getVariablesSet(e), logic, builder, 1, fieldCount, false); final RexShuttle shuttle = new ReplaceSubQueryShuttle(e, target); builder.project(shuttle.apply(project.getProjects()), project.getRowType().getFieldNames()); call.transformTo(builder.build()); } };
public RelNode accept(RexShuttle shuttle) { RexNode offset = shuttle.apply(this.offset); RexNode fetch = shuttle.apply(this.fetch); List<RexNode> fieldExps = shuttle.apply(this.fieldExps); assert fieldExps == this.fieldExps : "Sort node does not support modification of input field expressions." + " Old expressions: " + this.fieldExps + ", new ones: " + fieldExps; if (offset == this.offset && fetch == this.fetch) { return this; } return copy(traitSet, getInput(), collation, offset, fetch); }
public RelNode accept(RexShuttle shuttle) { RexNode offset = shuttle.apply(this.offset); RexNode fetch = shuttle.apply(this.fetch); List<RexNode> fieldExps = shuttle.apply(this.fieldExps); assert fieldExps == this.fieldExps : "Sort node does not support modification of input field expressions." + " Old expressions: " + this.fieldExps + ", new ones: " + fieldExps; if (offset == this.offset && fetch == this.fetch) { return this; } return copy(traitSet, getInput(), collation, offset, fetch); }
public RelNode accept(RexShuttle shuttle) { RexNode rexCall = shuttle.apply(this.rexCall); if (rexCall == this.rexCall) { return this; } return copy(traitSet, inputs, rexCall, elementType, rowType, columnMappings); }
public RelNode accept(RexShuttle shuttle) { RexNode rexCall = shuttle.apply(this.rexCall); if (rexCall == this.rexCall) { return this; } return copy(traitSet, inputs, rexCall, elementType, rowType, columnMappings); }
public RelNode accept(RexShuttle shuttle) { RexNode condition = shuttle.apply(this.condition); if (this.condition == condition) { return this; } return copy(traitSet, getInput(), condition); }
@Override public RelNode accept(RexShuttle shuttle) { RexNode condition = shuttle.apply(this.condition); if (this.condition == condition) { return this; } return copy(traitSet, condition, left, right, joinType, isSemiJoinDone()); }
public RelNode accept(RexShuttle shuttle) { List<RexNode> exps = shuttle.apply(this.exps); if (this.exps == exps) { return this; } return copy(traitSet, getInput(), exps, rowType); }
public RelNode accept(RexShuttle shuttle) { List<RexNode> exps = shuttle.apply(this.exps); if (this.exps == exps) { return this; } return copy(traitSet, getInput(), exps, rowType); }
@Override public RelNode accept(RexShuttle shuttle) { RexNode ref = shuttle.apply(this.ref); if (this.ref == ref) { return this; } return new UnnestPrel(getCluster(), traitSet, rowType, ref); }
@Override public RelNode accept(RexShuttle shuttle) { RexNode condition = shuttle.apply(this.condition); if (this.condition == condition) { return this; } return copy(traitSet, condition, left, right, joinType, isSemiJoinDone()); }
public RelNode accept(RexShuttle shuttle) { RexNode condition = shuttle.apply(this.condition); if (this.condition == condition) { return this; } return copy(traitSet, getInput(), condition); }
public UnifyResult apply(UnifyRuleCall call) { final MutableProject target = (MutableProject) call.target; final MutableProject query = (MutableProject) call.query; final RexShuttle shuttle = getRexShuttle(target); final List<RexNode> newProjects; try { newProjects = shuttle.apply(query.projects); } catch (MatchFailed e) { return null; } final MutableProject newProject = MutableProject.of(query.rowType, target, newProjects); final MutableRel newProject2 = MutableRels.strip(newProject); return call.result(newProject2); } }