Java Code Examples for org.apache.calcite.rex.RexBuilder#makeCorrel()
The following examples show how to use
org.apache.calcite.rex.RexBuilder#makeCorrel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdjustOperatorsSchemaVisitor.java From Bats with Apache License 2.0 | 6 votes |
@Override public Prel visitUnnest(UnnestPrel prel, Void value) throws RuntimeException { Preconditions.checkArgument(registeredPrel != null && registeredPrel instanceof LateralJoinPrel); Preconditions.checkArgument(prel.getRowType().getFieldCount() == 1); RexBuilder builder = prel.getCluster().getRexBuilder(); LateralJoinPrel lateralJoinPrel = (LateralJoinPrel) getRegisteredPrel(); int correlationIndex = lateralJoinPrel.getRequiredColumns().nextSetBit(0); String correlationColumnName = lateralJoinPrel.getLeft().getRowType().getFieldNames().get(correlationIndex); RexNode corrRef = builder.makeCorrel(lateralJoinPrel.getLeft().getRowType(), lateralJoinPrel.getCorrelationId()); RexNode fieldAccess = builder.makeFieldAccess(corrRef, correlationColumnName, false); List<String> fieldNames = new ArrayList<>(); List<RelDataType> fieldTypes = new ArrayList<>(); for (RelDataTypeField field : prel.getRowType().getFieldList()) { fieldNames.add(correlationColumnName); fieldTypes.add(field.getType()); } UnnestPrel unnestPrel = new UnnestPrel(prel.getCluster(), prel.getTraitSet(), prel.getCluster().getTypeFactory().createStructType(fieldTypes, fieldNames), fieldAccess); return unnestPrel; }
Example 2
Source File: RelBuilder.java From Bats with Apache License 2.0 | 5 votes |
@Override public RexNode visitInputRef(RexInputRef inputRef) { final RelDataType leftRowType = left.getRowType(); final RexBuilder rexBuilder = getRexBuilder(); final int leftCount = leftRowType.getFieldCount(); if (inputRef.getIndex() < leftCount) { final RexNode v = rexBuilder.makeCorrel(leftRowType, id); return rexBuilder.makeFieldAccess(v, inputRef.getIndex()); } else { return rexBuilder.makeInputRef(right, inputRef.getIndex() - leftCount); } }
Example 3
Source File: RelBuilder.java From calcite with Apache License 2.0 | 5 votes |
public RexNode visitInputRef(RexInputRef inputRef) { final RelDataType leftRowType = left.getRowType(); final RexBuilder rexBuilder = getRexBuilder(); final int leftCount = leftRowType.getFieldCount(); if (inputRef.getIndex() < leftCount) { final RexNode v = rexBuilder.makeCorrel(leftRowType, id); return rexBuilder.makeFieldAccess(v, inputRef.getIndex()); } else { return rexBuilder.makeInputRef(right, inputRef.getIndex() - leftCount); } }
Example 4
Source File: ProjectCorrelateTransposeRule.java From Bats with Apache License 2.0 | 4 votes |
@Override public void onMatch(RelOptRuleCall call) { Project origProj = call.rel(0); final Correlate corr = call.rel(1); // locate all fields referenced in the projection // determine which inputs are referenced in the projection; // if all fields are being referenced and there are no // special expressions, no point in proceeding any further PushProjector pushProject = new PushProjector(origProj, call.builder().literal(true), corr, preserveExprCondition, call.builder()); if (pushProject.locateAllRefs()) { return; } // create left and right projections, projecting only those // fields referenced on each side RelNode leftProjRel = pushProject.createProjectRefsAndExprs(corr.getLeft(), true, false); RelNode rightProjRel = pushProject.createProjectRefsAndExprs(corr.getRight(), true, true); Map<Integer, Integer> requiredColsMap = new HashMap<>(); // adjust requiredColumns that reference the projected columns int[] adjustments = pushProject.getAdjustments(); BitSet updatedBits = new BitSet(); for (Integer col : corr.getRequiredColumns()) { int newCol = col + adjustments[col]; updatedBits.set(newCol); requiredColsMap.put(col, newCol); } RexBuilder rexBuilder = call.builder().getRexBuilder(); CorrelationId correlationId = corr.getCluster().createCorrel(); RexCorrelVariable rexCorrel = (RexCorrelVariable) rexBuilder.makeCorrel(leftProjRel.getRowType(), correlationId); // updates RexCorrelVariable and sets actual RelDataType for RexFieldAccess rightProjRel = rightProjRel.accept(new RelNodesExprsHandler( new RexFieldAccessReplacer(corr.getCorrelationId(), rexCorrel, rexBuilder, requiredColsMap))); // create a new correlate with the projected children Correlate newCorrRel = corr.copy(corr.getTraitSet(), leftProjRel, rightProjRel, correlationId, ImmutableBitSet.of(BitSets.toIter(updatedBits)), corr.getJoinType()); // put the original project on top of the correlate, converting it to // reference the modified projection list RelNode topProject = pushProject.createNewProject(newCorrRel, adjustments); call.transformTo(topProject); }
Example 5
Source File: ProjectCorrelateTransposeRule.java From calcite with Apache License 2.0 | 4 votes |
public void onMatch(RelOptRuleCall call) { Project origProj = call.rel(0); final Correlate corr = call.rel(1); // locate all fields referenced in the projection // determine which inputs are referenced in the projection; // if all fields are being referenced and there are no // special expressions, no point in proceeding any further PushProjector pushProject = new PushProjector( origProj, call.builder().literal(true), corr, preserveExprCondition, call.builder()); if (pushProject.locateAllRefs()) { return; } // create left and right projections, projecting only those // fields referenced on each side RelNode leftProjRel = pushProject.createProjectRefsAndExprs( corr.getLeft(), true, false); RelNode rightProjRel = pushProject.createProjectRefsAndExprs( corr.getRight(), true, true); Map<Integer, Integer> requiredColsMap = new HashMap<>(); // adjust requiredColumns that reference the projected columns int[] adjustments = pushProject.getAdjustments(); BitSet updatedBits = new BitSet(); for (Integer col : corr.getRequiredColumns()) { int newCol = col + adjustments[col]; updatedBits.set(newCol); requiredColsMap.put(col, newCol); } RexBuilder rexBuilder = call.builder().getRexBuilder(); CorrelationId correlationId = corr.getCluster().createCorrel(); RexCorrelVariable rexCorrel = (RexCorrelVariable) rexBuilder.makeCorrel( leftProjRel.getRowType(), correlationId); // updates RexCorrelVariable and sets actual RelDataType for RexFieldAccess rightProjRel = rightProjRel.accept( new RelNodesExprsHandler( new RexFieldAccessReplacer(corr.getCorrelationId(), rexCorrel, rexBuilder, requiredColsMap))); // create a new correlate with the projected children Correlate newCorrRel = corr.copy( corr.getTraitSet(), leftProjRel, rightProjRel, correlationId, ImmutableBitSet.of(BitSets.toIter(updatedBits)), corr.getJoinType()); // put the original project on top of the correlate, converting it to // reference the modified projection list RelNode topProject = pushProject.createNewProject(newCorrRel, adjustments); call.transformTo(topProject); }