use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.CorrelationId in project hive by apache.
the class RexNodeConverter method convert.
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);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.CorrelationId in project hive by apache.
the class HiveRelDecorrelator method createCopyHook.
private Function2<RelNode, RelNode, Void> createCopyHook() {
return new Function2<RelNode, RelNode, Void>() {
@Override
public Void apply(RelNode oldNode, RelNode newNode) {
if (cm.mapRefRelToCorRef.containsKey(oldNode)) {
final CorelMap corelMap = new CorelMapBuilder().build(newNode);
// to figure out new cor refs and put that into map
if (!corelMap.mapRefRelToCorRef.isEmpty()) {
cm.mapRefRelToCorRef.putAll(newNode, corelMap.mapRefRelToCorRef.get(newNode));
}
}
if (oldNode instanceof LogicalCorrelate && newNode instanceof LogicalCorrelate) {
LogicalCorrelate oldCor = (LogicalCorrelate) oldNode;
CorrelationId c = oldCor.getCorrelationId();
if (cm.mapCorToCorRel.get(c) == oldNode) {
cm.mapCorToCorRel.put(c, newNode);
}
if (generatedCorRels.contains(oldNode)) {
generatedCorRels.add((LogicalCorrelate) newNode);
}
}
return null;
}
};
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.CorrelationId in project beam by apache.
the class ArrayScanColumnRefToUncollect method convert.
@Override
public RelNode convert(ResolvedNodes.ResolvedArrayScan zetaNode, List<RelNode> inputs) {
assert inputs.size() == 1;
RelNode input = inputs.get(0);
RexInputRef columnRef = (RexInputRef) getExpressionConverter().convertRexNodeFromResolvedExpr(getColumnRef(zetaNode.getArrayExpr()), zetaNode.getInputScan().getColumnList(), input.getRowType().getFieldList(), ImmutableMap.of());
CorrelationId correlationId = new CorrelationId(0);
RexNode convertedColumnRef = getCluster().getRexBuilder().makeFieldAccess(getCluster().getRexBuilder().makeCorrel(input.getRowType(), correlationId), columnRef.getIndex());
String fieldName = String.format("%s%s", zetaNode.getElementColumn().getTableName(), zetaNode.getElementColumn().getName());
RelNode projectNode = LogicalProject.create(createOneRow(getCluster()), ImmutableList.of(), Collections.singletonList(convertArrayExpr(zetaNode.getArrayExpr(), getCluster().getRexBuilder(), convertedColumnRef)), ImmutableList.of(fieldName));
boolean ordinality = (zetaNode.getArrayOffsetColumn() != null);
RelNode uncollect = ZetaSqlUnnest.create(projectNode.getTraitSet(), projectNode, ordinality);
return LogicalCorrelate.create(input, uncollect, correlationId, ImmutableBitSet.of(columnRef.getIndex()), JoinRelType.INNER);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.CorrelationId in project flink by apache.
the class HiveParserRexNodeConverter method convertColumn.
private RexNode convertColumn(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 = HiveParserTypeConverter.getType(cluster, this.outerRR, null);
if (this.outerNameToPos.get(col.getColumn()) == null) {
throw new SemanticException("Invalid column name " + col.getColumn());
}
int pos = this.outerNameToPos.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);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.CorrelationId in project flink by apache.
the class RexNodeJsonDeserializer method deserializeCorrelVariable.
private static RexNode deserializeCorrelVariable(JsonNode jsonNode, SerdeContext serdeContext) {
final String correl = jsonNode.required(FIELD_NAME_CORREL).asText();
final JsonNode logicalTypeNode = jsonNode.required(FIELD_NAME_TYPE);
final RelDataType fieldType = RelDataTypeJsonDeserializer.deserialize(logicalTypeNode, serdeContext);
return serdeContext.getRexBuilder().makeCorrel(fieldType, new CorrelationId(correl));
}
Aggregations