protected RexNode convert(ExprNodeColumnDesc col) throws SemanticException { //if this is co-rrelated we need to make RexCorrelVariable(with id and type) // id and type should be retrieved from outerRR InputCtx ic = getInputCtx(col); if(ic == null) { // we have correlated column, build data type from outer rr RelDataType rowType = TypeConverter.getType(cluster, this.outerRR, null); if (this.outerNameToPosMap.get(col.getColumn()) == null) { throw new SemanticException(ErrorMsg.INVALID_COLUMN_NAME.getMsg(col.getColumn())); } int pos = this.outerNameToPosMap.get(col.getColumn()); CorrelationId colCorr = new CorrelationId(this.correlatedId); RexNode corExpr = cluster.getRexBuilder().makeCorrel(rowType, colCorr); return cluster.getRexBuilder().makeFieldAccess(corExpr, pos); } int pos = ic.hiveNameToPosMap.get(col.getColumn()); return cluster.getRexBuilder().makeInputRef( ic.calciteInpDataType.getFieldList().get(pos).getType(), pos + ic.offsetInCalciteSchema); }
protected RexNode convert(ExprNodeColumnDesc col) throws SemanticException { //if this is co-rrelated we need to make RexCorrelVariable(with id and type) // id and type should be retrieved from outerRR InputCtx ic = getInputCtx(col); if(ic == null) { // we have correlated column, build data type from outer rr RelDataType rowType = TypeConverter.getType(cluster, this.outerRR, null); if (this.outerNameToPosMap.get(col.getColumn()) == null) { throw new SemanticException(ErrorMsg.INVALID_COLUMN_NAME.getMsg(col.getColumn())); } int pos = this.outerNameToPosMap.get(col.getColumn()); CorrelationId colCorr = new CorrelationId(this.correlatedId); RexNode corExpr = cluster.getRexBuilder().makeCorrel(rowType, colCorr); return cluster.getRexBuilder().makeFieldAccess(corExpr, pos); } int pos = ic.hiveNameToPosMap.get(col.getColumn()); return cluster.getRexBuilder().makeInputRef( ic.calciteInpDataType.getFieldList().get(pos).getType(), pos + ic.offsetInCalciteSchema); }
/** * Constructs a new id for a correlating variable. It is unique within the * whole query. */ public CorrelationId createCorrel() { return new CorrelationId(nextCorrel.getAndIncrement()); }
/** * Constructs a new id for a correlating variable. It is unique within the * whole query. */ public CorrelationId createCorrel() { return new CorrelationId(nextCorrel.getAndIncrement()); }
/** Converts a set of correlation ids to a set of names. */ public static ImmutableSet<CorrelationId> setOf(Set<String> set) { if (set.isEmpty()) { return ImmutableSet.of(); } final ImmutableSet.Builder<CorrelationId> builder = ImmutableSet.builder(); for (String s : set) { builder.add(new CorrelationId(s)); } return builder.build(); }
/** Converts a set of correlation ids to a set of names. */ public static ImmutableSet<CorrelationId> setOf(Set<String> set) { if (set.isEmpty()) { return ImmutableSet.of(); } final ImmutableSet.Builder<CorrelationId> builder = ImmutableSet.builder(); for (String s : set) { builder.add(new CorrelationId(s)); } return builder.build(); }
/** * Creates a LogicalCorrelate by parsing serialized output. */ public LogicalCorrelate(RelInput input) { this(input.getCluster(), input.getTraitSet(), input.getInputs().get(0), input.getInputs().get(1), new CorrelationId((Integer) input.get("correlationId")), input.getBitSet("requiredColumns"), input.getEnum("joinType", SemiJoinType.class)); }
/** * Creates a LogicalCorrelate by parsing serialized output. */ public LogicalCorrelate(RelInput input) { this(input.getCluster(), input.getTraitSet(), input.getInputs().get(0), input.getInputs().get(1), new CorrelationId((Integer) input.get("correlationId")), input.getBitSet("requiredColumns"), input.getEnum("joinType", SemiJoinType.class)); }
/** * Creates a Correlate by parsing serialized output. * * @param input Input representation */ public Correlate(RelInput input) { this( input.getCluster(), input.getTraitSet(), input.getInputs().get(0), input.getInputs().get(1), new CorrelationId((Integer) input.get("correlationId")), input.getBitSet("requiredColumns"), input.getEnum("joinType", SemiJoinType.class)); }
/** * Creates a Correlate by parsing serialized output. * * @param input Input representation */ public Correlate(RelInput input) { this( input.getCluster(), input.getTraitSet(), input.getInputs().get(0), input.getInputs().get(1), new CorrelationId((Integer) input.get("correlationId")), input.getBitSet("requiredColumns"), input.getEnum("joinType", SemiJoinType.class)); }
final Object jsonType = map.get("type"); RelDataType type = toType(typeFactory, jsonType); return rexBuilder.makeCorrel(type, new CorrelationId(correl));
final Object jsonType = map.get("type"); RelDataType type = toType(typeFactory, jsonType); return rexBuilder.makeCorrel(type, new CorrelationId(correl));
@Test public void testProjectCorrelateTransposeRuleAntiCorrelate() { RelBuilder relBuilder = RelBuilder.create(RelBuilderTest.config().build()); RelNode left = relBuilder .values(new String[]{"f", "f2"}, "1", "2").build(); CorrelationId correlationId = new CorrelationId(0); RexNode rexCorrel = relBuilder.getRexBuilder().makeCorrel( left.getRowType(), correlationId); RelNode right = relBuilder .values(new String[]{"f3", "f4"}, "1", "2") .project(relBuilder.field(0), relBuilder.getRexBuilder().makeFieldAccess(rexCorrel, 0)).build(); LogicalCorrelate correlate = new LogicalCorrelate(left.getCluster(), left.getTraitSet(), left, right, correlationId, ImmutableBitSet.of(0), SemiJoinType.ANTI); relBuilder.push(correlate); RelNode relNode = relBuilder.project(relBuilder.field(0)) .build(); HepProgram program = new HepProgramBuilder() .addRuleInstance(ProjectCorrelateTransposeRule.INSTANCE) .build(); HepPlanner hepPlanner = new HepPlanner(program); hepPlanner.setRoot(relNode); RelNode output = hepPlanner.findBestExp(); final String planAfter = NL + RelOptUtil.toString(output); final DiffRepository diffRepos = getDiffRepos(); diffRepos.assertEquals("planAfter", "${planAfter}", planAfter); SqlToRelTestBase.assertValid(output); }
@Test public void testProjectCorrelateTransposeRuleAntiCorrelate() { RelBuilder relBuilder = RelBuilder.create(RelBuilderTest.config().build()); RelNode left = relBuilder .values(new String[]{"f", "f2"}, "1", "2").build(); CorrelationId correlationId = new CorrelationId(0); RexNode rexCorrel = relBuilder.getRexBuilder().makeCorrel( left.getRowType(), correlationId); RelNode right = relBuilder .values(new String[]{"f3", "f4"}, "1", "2") .project(relBuilder.field(0), relBuilder.getRexBuilder().makeFieldAccess(rexCorrel, 0)).build(); LogicalCorrelate correlate = new LogicalCorrelate(left.getCluster(), left.getTraitSet(), left, right, correlationId, ImmutableBitSet.of(0), SemiJoinType.ANTI); relBuilder.push(correlate); RelNode relNode = relBuilder.project(relBuilder.field(0)) .build(); HepProgram program = new HepProgramBuilder() .addRuleInstance(ProjectCorrelateTransposeRule.INSTANCE) .build(); HepPlanner hepPlanner = new HepPlanner(program); hepPlanner.setRoot(relNode); RelNode output = hepPlanner.findBestExp(); final String planAfter = NL + RelOptUtil.toString(output); final DiffRepository diffRepos = getDiffRepos(); diffRepos.assertEquals("planAfter", "${planAfter}", planAfter); SqlToRelTestBase.assertValid(output); }
.values(new String[]{"f", "f2"}, "1", "2").build(); CorrelationId correlationId = new CorrelationId(0); RexNode rexCorrel = relBuilder.getRexBuilder().makeCorrel(
.values(new String[]{"f", "f2"}, "1", "2").build(); CorrelationId correlationId = new CorrelationId(0); RexNode rexCorrel = relBuilder.getRexBuilder().makeCorrel(