Refine search
private int[] getProjectFields(List<RexNode> exps) { final int[] fields = new int[exps.size()]; for (int i = 0; i < exps.size(); i++) { final RexNode exp = exps.get(i); if (exp instanceof RexInputRef) { fields[i] = ((RexInputRef) exp).getIndex(); } else { return null; // not a simple projection } } return fields; } }
private static void populateEquivalences(Map<Integer, BitSet> equivalence, RexNode predicate) { switch (predicate.getKind()) { case EQUALS: RexCall call = (RexCall) predicate; final List<RexNode> operands = call.getOperands(); if (operands.get(0) instanceof RexInputRef) { final RexInputRef ref0 = (RexInputRef) operands.get(0); if (operands.get(1) instanceof RexInputRef) { final RexInputRef ref1 = (RexInputRef) operands.get(1); populateEquivalence(equivalence, ref0.getIndex(), ref1.getIndex()); populateEquivalence(equivalence, ref1.getIndex(), ref0.getIndex()); } } } }
private static void populateEquivalences(Map<Integer, BitSet> equivalence, RexNode predicate) { switch (predicate.getKind()) { case EQUALS: RexCall call = (RexCall) predicate; final List<RexNode> operands = call.getOperands(); if (operands.get(0) instanceof RexInputRef) { final RexInputRef ref0 = (RexInputRef) operands.get(0); if (operands.get(1) instanceof RexInputRef) { final RexInputRef ref1 = (RexInputRef) operands.get(1); populateEquivalence(equivalence, ref0.getIndex(), ref1.getIndex()); populateEquivalence(equivalence, ref1.getIndex(), ref0.getIndex()); } } } }
private static Pair<ArrayList<ColumnInfo>, Set<Integer>> createColInfos( List<RexNode> calciteExprs, List<ExprNodeDesc> hiveExprs, List<String> projNames, OpAttr inpOpAf) { if (hiveExprs.size() != projNames.size()) { throw new RuntimeException("Column expressions list doesn't match Column Names list"); } RexNode rexN; ExprNodeDesc pe; ArrayList<ColumnInfo> colInfos = new ArrayList<ColumnInfo>(); boolean vc; Set<Integer> newVColSet = new HashSet<Integer>(); for (int i = 0; i < hiveExprs.size(); i++) { pe = hiveExprs.get(i); rexN = calciteExprs.get(i); vc = false; if (rexN instanceof RexInputRef) { if (inpOpAf.vcolsInCalcite.contains(((RexInputRef) rexN).getIndex())) { newVColSet.add(i); vc = true; } } colInfos .add(new ColumnInfo(projNames.get(i), pe.getTypeInfo(), inpOpAf.tabAlias, vc)); } return new Pair<ArrayList<ColumnInfo>, Set<Integer>>(colInfos, newVColSet); }
void translateJoinColumn(RexCall condition, Map<TblColRef, TblColRef> joinColumns) { SqlKind kind = condition.getOperator().getKind(); if (kind == SqlKind.AND) { for (RexNode operand : condition.getOperands()) { RexCall subCond = (RexCall) operand; translateJoinColumn(subCond, joinColumns); } } else if (kind == SqlKind.EQUALS) { List<RexNode> operands = condition.getOperands(); RexInputRef op0 = (RexInputRef) operands.get(0); TblColRef col0 = columnRowType.getColumnByIndex(op0.getIndex()); RexInputRef op1 = (RexInputRef) operands.get(1); TblColRef col1 = columnRowType.getColumnByIndex(op1.getIndex()); // map left => right if (op0.getIndex() < columnRowTypeLeftRightCut) joinColumns.put(col0, col1); else joinColumns.put(col1, col0); } }
private static Pair<ArrayList<ColumnInfo>, Set<Integer>> createColInfos( List<RexNode> calciteExprs, List<ExprNodeDesc> hiveExprs, List<String> projNames, OpAttr inpOpAf) { if (hiveExprs.size() != projNames.size()) { throw new RuntimeException("Column expressions list doesn't match Column Names list"); } RexNode rexN; ExprNodeDesc pe; ArrayList<ColumnInfo> colInfos = new ArrayList<ColumnInfo>(); boolean vc; Set<Integer> newVColSet = new HashSet<Integer>(); for (int i = 0; i < hiveExprs.size(); i++) { pe = hiveExprs.get(i); rexN = calciteExprs.get(i); vc = false; if (rexN instanceof RexInputRef) { if (inpOpAf.vcolsInCalcite.contains(((RexInputRef) rexN).getIndex())) { newVColSet.add(i); vc = true; } } colInfos .add(new ColumnInfo(projNames.get(i), pe.getTypeInfo(), inpOpAf.tabAlias, vc)); } return new Pair<ArrayList<ColumnInfo>, Set<Integer>>(colInfos, newVColSet); }
@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; } };
/** Finds a {@link RexInputRef} that is equivalent to a {@link CorRef}, * and if found, throws a {@link Util.FoundOne}. */ private void findCorrelationEquivalent(CorRef correlation, RexNode e) throws Util.FoundOne { switch (e.getKind()) { case EQUALS: final RexCall call = (RexCall) e; final List<RexNode> operands = call.getOperands(); if (references(operands.get(0), correlation) && operands.get(1) instanceof RexInputRef) { throw new Util.FoundOne(((RexInputRef) operands.get(1)).getIndex()); } if (references(operands.get(1), correlation) && operands.get(0) instanceof RexInputRef) { throw new Util.FoundOne(((RexInputRef) operands.get(0)).getIndex()); } break; case AND: for (RexNode operand : ((RexCall) e).getOperands()) { findCorrelationEquivalent(correlation, operand); } } }
@Override public Void visitCall(RexCall call) { if(AnnotationUtils.getAnnotation(GenericUDFOPNotNull.class, Description.class).name().equals(call.getOperator().getName())) { if(call.getOperands().get(0) instanceof RexInputRef && !types.get(((RexInputRef)call.getOperands().get(0)).getIndex()).getType().isNullable()) { // No need to add not null filter for a constant. throw new Util.FoundOne(call); } } return super.visitCall(call); }
if (!(equals.getOperands().get(0) instanceof RexInputRef) || !(equals.getOperands().get(1) instanceof RexInputRef)) { otherConjuncts.add(conj); continue; RexInputRef ref0 = (RexInputRef) equals.getOperands().get(0); RexInputRef ref1 = (RexInputRef) equals.getOperands().get(1); if ((ref0.getIndex() < nLeftColumns && ref1.getIndex() >= nLeftColumns) || (ref1.getIndex() < nLeftColumns && ref0.getIndex() >= nLeftColumns)) { idxToConjuncts.put(ref0.getIndex(), equals); idxToConjuncts.put(ref1.getIndex(), equals); refToRef.put(ref0.getIndex(), ref1.getIndex()); refToRef.put(ref1.getIndex(), ref0.getIndex()); } else { otherConjuncts.add(conj);
public RelNode align(Project rel, List<RelFieldCollation> collations) { // 1) We extract the collations indices boolean containsWindowing = false; for (RexNode childExp : rel.getChildExps()) { if (childExp instanceof RexOver) { // TODO: support propagation for partitioning/ordering in windowing containsWindowing = true; break; } } ImmutableList.Builder<RelFieldCollation> propagateCollations = ImmutableList.builder(); if (!containsWindowing) { for (RelFieldCollation c : collations) { RexNode rexNode = rel.getChildExps().get(c.getFieldIndex()); if (rexNode instanceof RexInputRef) { int newIdx = ((RexInputRef) rexNode).getIndex(); propagateCollations.add(c.copy((newIdx))); } } } // 2) We propagate final RelNode child = dispatchAlign(rel.getInput(), propagateCollations.build()); // 3) Return new Project return rel.copy(rel.getTraitSet(), ImmutableList.of(child)); }
@Override public Void visitCall(RexCall call) { if(AnnotationUtils.getAnnotation(GenericUDFOPNotNull.class, Description.class).name().equals(call.getOperator().getName())) { if(call.getOperands().get(0) instanceof RexInputRef && !types.get(((RexInputRef)call.getOperands().get(0)).getIndex()).getType().isNullable()) { // No need to add not null filter for a constant. throw new Util.FoundOne(call); } } return super.visitCall(call); } }