// implement RelOptRule public void onMatch(RelOptRuleCall call) { CalcRel calcRel = (CalcRel) call.rels[0]; RexProgram program = calcRel.getProgram(); // check the projection List<Integer> projOrdinals = new ArrayList<Integer>(); RelDataType outputRowType = isProjectSimple(calcRel, projOrdinals); if (outputRowType == null) { return; } RexLocalRef condition = program.getCondition(); CompOperatorEnum compOp = CompOperatorEnum.COMP_NOOP; Integer[] filterOrdinals = {}; List<RexLiteral> filterLiterals = new ArrayList<RexLiteral>(); // check the condition if (condition != null) { RexNode filterExprs = program.expandLocalRef(condition); List<Integer> filterList = new ArrayList<Integer>(); List<CompOperatorEnum> op = new ArrayList<CompOperatorEnum>(); if (!isConditionSimple(calcRel, filterExprs, filterList, filterLiterals, op)) { return; } compOp = op.get(0); filterOrdinals = filterList.toArray(new Integer[filterList.size()]); } RelNode fennelInput = mergeTraitsAndConvert( calcRel.getTraits(), FennelRel.FENNEL_EXEC_CONVENTION, calcRel.getChild()); if (fennelInput == null) { return; } Integer[] projection = projOrdinals.toArray(new Integer[projOrdinals.size()]); FennelReshapeRel reshapeRel = new FennelReshapeRel( calcRel.getCluster(), fennelInput, projection, outputRowType, compOp, filterOrdinals, filterLiterals, new FennelRelParamId[] {}, new Integer[] {}, null); call.transformTo(reshapeRel); }
private SqlOperator toOp(String name, TableFunction fun) { List<RelDataType> argTypes = new ArrayList<RelDataType>(); List<SqlTypeFamily> typeFamilies = new ArrayList<SqlTypeFamily>(); Parameter p; for (net.hydromatic.optiq.Parameter o : (List<net.hydromatic.optiq.Parameter>) fun.getParameters()) { argTypes.add(o.getType()); typeFamilies.add(SqlTypeFamily.ANY); } return new SqlFunction( name, SqlKind.OTHER_FUNCTION, new ExplicitReturnTypeInference(typeFactory.createType(fun.getElementType())), new ExplicitOperandTypeInference(argTypes.toArray(new RelDataType[argTypes.size()])), new FamilyOperandTypeChecker( typeFamilies.toArray(new SqlTypeFamily[typeFamilies.size()])), null); }
public void onMatch(RelOptRuleCall call) { JoinRel origJoinRel = (JoinRel) call.rels[0]; RelNode left = call.rels[1]; RelNode right = call.rels[2]; // combine the children MultiJoinRel inputs into an array of inputs // for the new MultiJoinRel List<BitSet> projFieldsList = new ArrayList<BitSet>(); List<int[]> joinFieldRefCountsList = new ArrayList<int[]>(); RelNode[] newInputs = combineInputs(origJoinRel, left, right, projFieldsList, joinFieldRefCountsList); // combine the outer join information from the left and right // inputs, and include the outer join information from the current // join, if it's a left/right outer join RexNode[] newOuterJoinConds = new RexNode[newInputs.length]; JoinRelType[] joinTypes = new JoinRelType[newInputs.length]; combineOuterJoins(origJoinRel, newInputs, left, right, newOuterJoinConds, joinTypes); // pull up the join filters from the children MultiJoinRels and // combine them with the join filter associated with this JoinRel to // form the join filter for the new MultiJoinRel RexNode newJoinFilter = combineJoinFilters(origJoinRel, left, right); // add on the join field reference counts for the join condition // associated with this JoinRel Map<Integer, int[]> newJoinFieldRefCountsMap = new HashMap<Integer, int[]>(); addOnJoinFieldRefCounts( newInputs, origJoinRel.getRowType().getFieldCount(), origJoinRel.getCondition(), joinFieldRefCountsList, newJoinFieldRefCountsMap); RexNode newPostJoinFilter = combinePostJoinFilters(origJoinRel, left, right); RelNode multiJoin = new MultiJoinRel( origJoinRel.getCluster(), newInputs, newJoinFilter, origJoinRel.getRowType(), (origJoinRel.getJoinType() == JoinRelType.FULL), newOuterJoinConds, joinTypes, projFieldsList.toArray(new BitSet[projFieldsList.size()]), newJoinFieldRefCountsMap, newPostJoinFilter); call.transformTo(multiJoin); }
public void onMatch(RelOptRuleCall call) { ProjectRel project = (ProjectRel) call.rels[0]; List<RexNode> expList = new ArrayList<RexNode>(Arrays.asList(project.getChildExps())); if (reduceExpressions(project, expList)) { call.transformTo( new ProjectRel( project.getCluster(), project.getChild(), expList.toArray(new RexNode[expList.size()]), project.getRowType(), ProjectRel.Flags.Boxed, Collections.<RelCollation>emptyList())); // New plan is absolutely better than old plan. call.getPlanner().setImportance(project, 0.0); } }