Search in sources :

Example 16 with CorrelationId

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);
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) CorrelationId(org.apache.calcite.rel.core.CorrelationId) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) CalciteSubquerySemanticException(org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSubquerySemanticException) CalciteSemanticException(org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException) RexNode(org.apache.calcite.rex.RexNode)

Example 17 with CorrelationId

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;
        }
    };
}
Also used : HiveRelNode(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRelNode) RelNode(org.apache.calcite.rel.RelNode) Function2(org.apache.calcite.linq4j.function.Function2) LogicalCorrelate(org.apache.calcite.rel.logical.LogicalCorrelate) CorrelationId(org.apache.calcite.rel.core.CorrelationId)

Example 18 with CorrelationId

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);
}
Also used : RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) RexInputRef(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef) CorrelationId(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.CorrelationId) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)

Example 19 with CorrelationId

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);
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) CorrelationId(org.apache.calcite.rel.core.CorrelationId) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) RexNode(org.apache.calcite.rex.RexNode)

Example 20 with CorrelationId

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));
}
Also used : JsonNode(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode) RelDataType(org.apache.calcite.rel.type.RelDataType) DateString(org.apache.calcite.util.DateString) ByteString(org.apache.calcite.avatica.util.ByteString) TimestampString(org.apache.calcite.util.TimestampString) TimeString(org.apache.calcite.util.TimeString) CorrelationId(org.apache.calcite.rel.core.CorrelationId)

Aggregations

CorrelationId (org.apache.calcite.rel.core.CorrelationId)29 RelNode (org.apache.calcite.rel.RelNode)18 RexNode (org.apache.calcite.rex.RexNode)15 ArrayList (java.util.ArrayList)11 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)10 RelDataType (org.apache.calcite.rel.type.RelDataType)7 RexBuilder (org.apache.calcite.rex.RexBuilder)7 LogicalCorrelate (org.apache.calcite.rel.logical.LogicalCorrelate)6 RexFieldAccess (org.apache.calcite.rex.RexFieldAccess)6 ImmutableList (com.google.common.collect.ImmutableList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)5 RexCorrelVariable (org.apache.calcite.rex.RexCorrelVariable)5 RelOptCluster (org.apache.calcite.plan.RelOptCluster)4 RelBuilder (org.apache.calcite.tools.RelBuilder)4 Function2 (org.apache.calcite.linq4j.function.Function2)3 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)3 NlsString (org.apache.calcite.util.NlsString)3 Map (java.util.Map)2