@Override public RexNode visitInputRef(RexInputRef inputRef) { if (currentRel instanceof LogicalCorrelate) { // if this rel references corVar // and now it needs to be rewritten // it must have been pulled above the Correlator // replace the input ref to account for the LHS of the // Correlator final int leftInputFieldCount = ((LogicalCorrelate) currentRel).getLeft().getRowType() .getFieldCount(); RelDataType newType = inputRef.getType(); if (projectPulledAboveLeftCorrelator) { newType = typeFactory.createTypeWithNullability(newType, true); } int pos = inputRef.getIndex(); RexInputRef newInputRef = new RexInputRef(leftInputFieldCount + pos, newType); if ((isCount != null) && isCount.contains(pos)) { return createCaseExpression( newInputRef, rexBuilder.makeExactLiteral(BigDecimal.ZERO), newInputRef); } else { return newInputRef; } } return inputRef; }
@Override public RexNode visitInputRef(RexInputRef inputRef) { if (currentRel instanceof LogicalCorrelate) { // if this rel references corVar // and now it needs to be rewritten // it must have been pulled above the Correlator // replace the input ref to account for the LHS of the // Correlator final int leftInputFieldCount = ((LogicalCorrelate) currentRel).getLeft().getRowType() .getFieldCount(); RelDataType newType = inputRef.getType(); if (projectPulledAboveLeftCorrelator) { newType = typeFactory.createTypeWithNullability(newType, true); } int pos = inputRef.getIndex(); RexInputRef newInputRef = new RexInputRef(leftInputFieldCount + pos, newType); if ((isCount != null) && isCount.contains(pos)) { return createCaseExpression( newInputRef, rexBuilder.makeExactLiteral(BigDecimal.ZERO), newInputRef); } else { return newInputRef; } } return inputRef; }
public RelNode convert(RelNode rel) { final LogicalCorrelate c = (LogicalCorrelate) rel; final RelTraitSet traitSet = c.getTraitSet().replace(EnumerableConvention.INSTANCE); return new EnumerableCorrelate( rel.getCluster(), traitSet, convert(c.getLeft(), c.getLeft().getTraitSet() .replace(EnumerableConvention.INSTANCE)), convert(c.getRight(), c.getRight().getTraitSet() .replace(EnumerableConvention.INSTANCE)), c.getCorrelationId(), c.getRequiredColumns(), c.getJoinType()); } }
@Override public RexNode visitInputRef(RexInputRef inputRef) { if (currentRel instanceof LogicalCorrelate) { // if this rel references corVar // and now it needs to be rewritten // it must have been pulled above the Correlate // replace the input ref to account for the LHS of the // Correlate final int leftInputFieldCount = ((LogicalCorrelate) currentRel).getLeft().getRowType() .getFieldCount(); RelDataType newType = inputRef.getType(); if (projectPulledAboveLeftCorrelator) { newType = typeFactory.createTypeWithNullability(newType, true); } int pos = inputRef.getIndex(); RexInputRef newInputRef = new RexInputRef(leftInputFieldCount + pos, newType); if ((isCount != null) && isCount.contains(pos)) { return createCaseExpression( newInputRef, rexBuilder.makeExactLiteral(BigDecimal.ZERO), newInputRef); } else { return newInputRef; } } return inputRef; }
public RelNode convert(RelNode rel) { final LogicalCorrelate c = (LogicalCorrelate) rel; final RelTraitSet traitSet = c.getTraitSet().replace(EnumerableConvention.INSTANCE); return new EnumerableCorrelate( rel.getCluster(), traitSet, convert(c.getLeft(), c.getLeft().getTraitSet() .replace(EnumerableConvention.INSTANCE)), convert(c.getRight(), c.getRight().getTraitSet() .replace(EnumerableConvention.INSTANCE)), c.getCorrelationId(), c.getRequiredColumns(), c.getJoinType()); } }
@Override public RexNode visitInputRef(RexInputRef inputRef) { if (currentRel instanceof LogicalCorrelate) { // if this rel references corVar // and now it needs to be rewritten // it must have been pulled above the Correlate // replace the input ref to account for the LHS of the // Correlate final int leftInputFieldCount = ((LogicalCorrelate) currentRel).getLeft().getRowType() .getFieldCount(); RelDataType newType = inputRef.getType(); if (projectPulledAboveLeftCorrelator) { newType = typeFactory.createTypeWithNullability(newType, true); } int pos = inputRef.getIndex(); RexInputRef newInputRef = new RexInputRef(leftInputFieldCount + pos, newType); if ((isCount != null) && isCount.contains(pos)) { return createCaseExpression( newInputRef, rexBuilder.makeExactLiteral(BigDecimal.ZERO), newInputRef); } else { return newInputRef; } } return inputRef; }
public void rewriteRel(LogicalCorrelate rel) { ImmutableBitSet.Builder newPos = ImmutableBitSet.builder(); for (int pos : rel.getRequiredColumns()) { RelDataType corrFieldType = rel.getLeft().getRowType().getFieldList().get(pos) .getType(); if (corrFieldType.isStruct()) { throw Util.needToImplement("correlation on structured type"); } newPos.set(getNewForOldInput(pos)); } LogicalCorrelate newRel = LogicalCorrelate.create(getNewForOldRel(rel.getLeft()), getNewForOldRel(rel.getRight()), rel.getCorrelationId(), newPos.build(), rel.getJoinType()); setNewForOldRel(rel, newRel); }
public void rewriteRel(LogicalCorrelate rel) { ImmutableBitSet.Builder newPos = ImmutableBitSet.builder(); for (int pos : rel.getRequiredColumns()) { RelDataType corrFieldType = rel.getLeft().getRowType().getFieldList().get(pos) .getType(); if (corrFieldType.isStruct()) { throw Util.needToImplement("correlation on structured type"); } newPos.set(getNewForOldInput(pos)); } LogicalCorrelate newRel = LogicalCorrelate.create(getNewForOldRel(rel.getLeft()), getNewForOldRel(rel.getRight()), rel.getCorrelationId(), newPos.build(), rel.getJoinType()); setNewForOldRel(rel, newRel); }
@Override public RelNode visit(LogicalCorrelate correlate) { final RelNode left = correlate.getLeft().accept(this); final RelNode right = correlate.getRight().accept(this); return new LogicalCorrelate( cluster, copyOf(correlate.getTraitSet()), left, right, correlate.getCorrelationId(), correlate.getRequiredColumns(), correlate.getJoinType() ); }
@Override public RexNode visitInputRef(RexInputRef inputRef) { if (currentRel instanceof LogicalCorrelate) { // if this rel references corVar // and now it needs to be rewritten // it must have been pulled above the Correlate // replace the input ref to account for the LHS of the // Correlate final int leftInputFieldCount = ((LogicalCorrelate) currentRel).getLeft().getRowType() .getFieldCount(); RelDataType newType = inputRef.getType(); if (projectPulledAboveLeftCorrelator) { newType = typeFactory.createTypeWithNullability(newType, true); } int pos = inputRef.getIndex(); RexInputRef newInputRef = new RexInputRef(leftInputFieldCount + pos, newType); if ((isCount != null) && isCount.contains(pos)) { return createCaseExpression( newInputRef, rexBuilder.makeExactLiteral(BigDecimal.ZERO), newInputRef); } else { return newInputRef; } } return inputRef; }
@Override public void onMatch(RelOptRuleCall call) { final LogicalCorrelate correlate = call.rel(0); final RelNode left = correlate.getLeft(); final RelNode right = correlate.getRight(); final RelNode convertedLeft = convert(left, left.getTraitSet().plus(DrillRel.DRILL_LOGICAL).simplify()); final RelNode convertedRight = convert(right, right.getTraitSet().plus(DrillRel.DRILL_LOGICAL).simplify()); final RelTraitSet traits = correlate.getTraitSet().plus(DrillRel.DRILL_LOGICAL); DrillLateralJoinRel lateralJoinRel = new DrillLateralJoinRel(correlate.getCluster(), traits, convertedLeft, convertedRight, false, correlate.getCorrelationId(), correlate.getRequiredColumns(), correlate.getJoinType()); call.transformTo(lateralJoinRel); } }