Search in sources :

Example 31 with Pair

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.Pair in project calcite by apache.

the class IdentifierNamespace method validateImpl.

public RelDataType validateImpl(RelDataType targetRowType) {
    resolvedNamespace = Preconditions.checkNotNull(resolveImpl(id));
    if (resolvedNamespace instanceof TableNamespace) {
        SqlValidatorTable table = resolvedNamespace.getTable();
        if (validator.shouldExpandIdentifiers()) {
            // TODO:  expand qualifiers for column references also
            List<String> qualifiedNames = table.getQualifiedName();
            if (qualifiedNames != null) {
                // Assign positions to the components of the fully-qualified
                // identifier, as best we can. We assume that qualification
                // adds names to the front, e.g. FOO.BAR becomes BAZ.FOO.BAR.
                List<SqlParserPos> poses = new ArrayList<>(Collections.nCopies(qualifiedNames.size(), id.getParserPosition()));
                int offset = qualifiedNames.size() - id.names.size();
                // reader.
                if (offset >= 0) {
                    for (int i = 0; i < id.names.size(); i++) {
                        poses.set(i + offset, id.getComponentParserPosition(i));
                    }
                }
                id.setNames(qualifiedNames, poses);
            }
        }
    }
    RelDataType rowType = resolvedNamespace.getRowType();
    if (extendList != null) {
        if (!(resolvedNamespace instanceof TableNamespace)) {
            throw new RuntimeException("cannot convert");
        }
        resolvedNamespace = ((TableNamespace) resolvedNamespace).extend(extendList);
        rowType = resolvedNamespace.getRowType();
    }
    // Build a list of monotonic expressions.
    final ImmutableList.Builder<Pair<SqlNode, SqlMonotonicity>> builder = ImmutableList.builder();
    List<RelDataTypeField> fields = rowType.getFieldList();
    for (RelDataTypeField field : fields) {
        final String fieldName = field.getName();
        final SqlMonotonicity monotonicity = resolvedNamespace.getMonotonicity(fieldName);
        if (monotonicity != SqlMonotonicity.NOT_MONOTONIC) {
            builder.add(Pair.of((SqlNode) new SqlIdentifier(fieldName, SqlParserPos.ZERO), monotonicity));
        }
    }
    monotonicExprs = builder.build();
    // Validation successful.
    return rowType;
}
Also used : SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) Pair(org.apache.calcite.util.Pair) SqlNode(org.apache.calcite.sql.SqlNode)

Example 32 with Pair

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.Pair in project calcite by apache.

the class DelegatingScope method resolveInNamespace.

/**
 * If a record type allows implicit references to fields, recursively looks
 * into the fields. Otherwise returns immediately.
 */
void resolveInNamespace(SqlValidatorNamespace ns, boolean nullable, List<String> names, SqlNameMatcher nameMatcher, Path path, Resolved resolved) {
    if (names.isEmpty()) {
        resolved.found(ns, nullable, this, path, null);
        return;
    }
    final RelDataType rowType = ns.getRowType();
    if (rowType.isStruct()) {
        SqlValidatorTable validatorTable = ns.getTable();
        if (validatorTable instanceof Prepare.PreparingTable) {
            Table t = ((Prepare.PreparingTable) validatorTable).unwrap(Table.class);
            if (t instanceof CustomColumnResolvingTable) {
                final List<Pair<RelDataTypeField, List<String>>> entries = ((CustomColumnResolvingTable) t).resolveColumn(rowType, validator.getTypeFactory(), names);
                for (Pair<RelDataTypeField, List<String>> entry : entries) {
                    final RelDataTypeField field = entry.getKey();
                    final List<String> remainder = entry.getValue();
                    final SqlValidatorNamespace ns2 = new FieldNamespace(validator, field.getType());
                    final Step path2 = path.plus(rowType, field.getIndex(), field.getName(), StructKind.FULLY_QUALIFIED);
                    resolveInNamespace(ns2, nullable, remainder, nameMatcher, path2, resolved);
                }
                return;
            }
        }
        final String name = names.get(0);
        final RelDataTypeField field0 = nameMatcher.field(rowType, name);
        if (field0 != null) {
            final SqlValidatorNamespace ns2 = ns.lookupChild(field0.getName());
            final Step path2 = path.plus(rowType, field0.getIndex(), field0.getName(), StructKind.FULLY_QUALIFIED);
            resolveInNamespace(ns2, nullable, names.subList(1, names.size()), nameMatcher, path2, resolved);
        } else {
            for (RelDataTypeField field : rowType.getFieldList()) {
                switch(field.getType().getStructKind()) {
                    case PEEK_FIELDS:
                    case PEEK_FIELDS_DEFAULT:
                    case PEEK_FIELDS_NO_EXPAND:
                        final Step path2 = path.plus(rowType, field.getIndex(), field.getName(), field.getType().getStructKind());
                        final SqlValidatorNamespace ns2 = ns.lookupChild(field.getName());
                        resolveInNamespace(ns2, nullable, names, nameMatcher, path2, resolved);
                }
            }
        }
    }
}
Also used : Table(org.apache.calcite.schema.Table) CustomColumnResolvingTable(org.apache.calcite.schema.CustomColumnResolvingTable) RelDataType(org.apache.calcite.rel.type.RelDataType) CustomColumnResolvingTable(org.apache.calcite.schema.CustomColumnResolvingTable) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SqlNodeList(org.apache.calcite.sql.SqlNodeList) Pair(org.apache.calcite.util.Pair)

Example 33 with Pair

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.Pair in project drill by axbaretto.

the class NumberingRelWriter method done.

public RelWriter done(RelNode node) {
    int i = 0;
    if (values.size() > 0 && values.get(0).left.equals("subset")) {
        ++i;
    }
    for (RelNode input : node.getInputs()) {
        assert values.get(i).right == input;
        ++i;
    }
    for (RexNode expr : node.getChildExps()) {
        assert values.get(i).right == expr;
        ++i;
    }
    final List<Pair<String, Object>> valuesCopy = ImmutableList.copyOf(values);
    values.clear();
    explain_(node, valuesCopy);
    pw.flush();
    return this;
}
Also used : RelNode(org.apache.calcite.rel.RelNode) RexNode(org.apache.calcite.rex.RexNode) Pair(org.apache.calcite.util.Pair)

Example 34 with Pair

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.Pair in project drill by apache.

the class NumberingRelWriter method done.

@SuppressWarnings("deprecation")
public RelWriter done(RelNode node) {
    int i = 0;
    if (values.size() > 0 && values.get(0).left.equals("subset")) {
        ++i;
    }
    for (RelNode input : node.getInputs()) {
        assert values.get(i).right == input;
        ++i;
    }
    for (RexNode expr : node.getChildExps()) {
        assert values.get(i).right == expr;
        ++i;
    }
    final List<Pair<String, Object>> valuesCopy = ImmutableList.copyOf(values);
    values.clear();
    explain_(node, valuesCopy);
    pw.flush();
    return this;
}
Also used : RelNode(org.apache.calcite.rel.RelNode) RexNode(org.apache.calcite.rex.RexNode) Pair(org.apache.calcite.util.Pair)

Example 35 with Pair

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.Pair in project drill by apache.

the class CodeGenMemberInjector method injectMembers.

/**
 * Generated code for a class may have several class members, they
 * are initialized by invoking this method when the instance created.
 *
 * @param cg       the class generator
 * @param instance the class instance created by the compiler
 * @param context  the fragment context
 */
public static void injectMembers(ClassGenerator<?> cg, Object instance, FragmentContext context) {
    Map<Integer, Object> cachedInstances = new HashMap<>();
    for (Map.Entry<Pair<Integer, JVar>, Function<DrillBuf, ? extends ValueHolder>> setter : cg.getConstantVars().entrySet()) {
        try {
            JVar var = setter.getKey().getValue();
            Integer depth = setter.getKey().getKey();
            Object varInstance = getFieldInstance(instance, depth, cachedInstances);
            Field field = varInstance.getClass().getDeclaredField(var.name());
            field.setAccessible(true);
            field.set(varInstance, setter.getValue().apply(context.getManagedBuffer()));
        } catch (ReflectiveOperationException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : HashMap(java.util.HashMap) ValueHolder(org.apache.drill.exec.expr.holders.ValueHolder) Function(org.apache.drill.shaded.guava.com.google.common.base.Function) Field(java.lang.reflect.Field) Map(java.util.Map) HashMap(java.util.HashMap) Pair(org.apache.calcite.util.Pair) JVar(com.sun.codemodel.JVar)

Aggregations

Pair (org.apache.calcite.util.Pair)112 RexNode (org.apache.calcite.rex.RexNode)72 ArrayList (java.util.ArrayList)70 RelNode (org.apache.calcite.rel.RelNode)59 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)55 RexInputRef (org.apache.calcite.rex.RexInputRef)29 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)29 HashMap (java.util.HashMap)26 RexBuilder (org.apache.calcite.rex.RexBuilder)23 Map (java.util.Map)21 AggregateCall (org.apache.calcite.rel.core.AggregateCall)20 List (java.util.List)19 RelDataType (org.apache.calcite.rel.type.RelDataType)19 ImmutableList (com.google.common.collect.ImmutableList)18 JoinRelType (org.apache.calcite.rel.core.JoinRelType)16 TreeMap (java.util.TreeMap)14 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)13 RelBuilder (org.apache.calcite.tools.RelBuilder)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)12