Search in sources :

Example 41 with RelDataTypeField

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.

the class GeodeUtils method handleStructEntry.

private static Object handleStructEntry(List<RelDataTypeField> relDataTypeFields, Object obj) {
    Struct struct = (Struct) obj;
    Object[] values = new Object[relDataTypeFields.size()];
    int index = 0;
    for (RelDataTypeField relDataTypeField : relDataTypeFields) {
        Type javaType = JAVA_TYPE_FACTORY.getJavaClass(relDataTypeField.getType());
        Object rawValue;
        try {
            rawValue = struct.get(relDataTypeField.getName());
        } catch (IllegalArgumentException e) {
            rawValue = "<error>";
            System.err.println("Could find field : " + relDataTypeField.getName());
            e.printStackTrace();
        }
        values[index++] = convert(rawValue, (Class) javaType);
    }
    if (values.length == 1) {
        return values[0];
    }
    return values;
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataType(org.apache.calcite.rel.type.RelDataType) Type(java.lang.reflect.Type) Struct(org.apache.geode.cache.query.Struct)

Example 42 with RelDataTypeField

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.

the class JavaTypeFactoryExtImpl method createPdxType2.

// Experimental flattering the nested structures.
public RelDataType createPdxType2(PdxInstance pdxInstance) {
    final List<RelDataTypeField> list = new ArrayList<>();
    recursiveCreatePdxType(pdxInstance, list, "");
    return canonize(new RelRecordType(list));
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) ArrayList(java.util.ArrayList) RelRecordType(org.apache.calcite.rel.type.RelRecordType)

Example 43 with RelDataTypeField

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.

the class JavaTypeFactoryExtImpl method createStructType.

/**
 * See <a href="http://stackoverflow.com/questions/16966629/what-is-the-difference-between-getfields-and-getdeclaredfields-in-java-reflectio">
 *   the difference between fields and declared fields</a>.
 */
@Override
public RelDataType createStructType(Class type) {
    final List<RelDataTypeField> list = new ArrayList<>();
    for (Field field : type.getDeclaredFields()) {
        if (!Modifier.isStatic(field.getModifiers())) {
            // FIXME: watch out for recursion
            final Type fieldType = field.getType();
            list.add(new RelDataTypeFieldImpl(field.getName(), list.size(), createType(fieldType)));
        }
    }
    return canonize(new JavaRecordType(list, type));
}
Also used : Field(java.lang.reflect.Field) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataType(org.apache.calcite.rel.type.RelDataType) RelRecordType(org.apache.calcite.rel.type.RelRecordType) Type(java.lang.reflect.Type) JavaRecordType(org.apache.calcite.jdbc.JavaRecordType) JavaRecordType(org.apache.calcite.jdbc.JavaRecordType) ArrayList(java.util.ArrayList) RelDataTypeFieldImpl(org.apache.calcite.rel.type.RelDataTypeFieldImpl)

Example 44 with RelDataTypeField

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.

the class PhysTypeImpl method field.

public PhysType field(int ordinal) {
    final RelDataTypeField field = rowType.getFieldList().get(ordinal);
    final RelDataType type = field.getType();
    return PhysTypeImpl.of(typeFactory, toStruct(type), format, false);
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 45 with RelDataTypeField

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.

the class EnumerableUncollect method implement.

public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    final BlockBuilder builder = new BlockBuilder();
    final EnumerableRel child = (EnumerableRel) getInput();
    final Result result = implementor.visitChild(this, 0, child, pref);
    final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), JavaRowFormat.LIST);
    // final Enumerable<List<Employee>> child = <<child adapter>>;
    // return child.selectMany(FLAT_PRODUCT);
    final Expression child_ = builder.append("child", result.block);
    final List<Integer> fieldCounts = new ArrayList<>();
    final List<FlatProductInputType> inputTypes = new ArrayList<>();
    for (RelDataTypeField field : child.getRowType().getFieldList()) {
        final RelDataType type = field.getType();
        if (type instanceof MapSqlType) {
            fieldCounts.add(2);
            inputTypes.add(FlatProductInputType.MAP);
        } else {
            final RelDataType elementType = type.getComponentType();
            if (elementType.isStruct()) {
                fieldCounts.add(elementType.getFieldCount());
                inputTypes.add(FlatProductInputType.LIST);
            } else {
                fieldCounts.add(-1);
                inputTypes.add(FlatProductInputType.SCALAR);
            }
        }
    }
    final Expression lambda = Expressions.call(BuiltInMethod.FLAT_PRODUCT.method, Expressions.constant(Ints.toArray(fieldCounts)), Expressions.constant(withOrdinality), Expressions.constant(inputTypes.toArray(new FlatProductInputType[inputTypes.size()])));
    builder.add(Expressions.return_(null, Expressions.call(child_, BuiltInMethod.SELECT_MANY.method, lambda)));
    return implementor.result(physType, builder.toBlock());
}
Also used : ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) FlatProductInputType(org.apache.calcite.runtime.SqlFunctions.FlatProductInputType) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) Expression(org.apache.calcite.linq4j.tree.Expression) MapSqlType(org.apache.calcite.sql.type.MapSqlType) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder)

Aggregations

RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)388 RelDataType (org.apache.calcite.rel.type.RelDataType)210 RexNode (org.apache.calcite.rex.RexNode)185 ArrayList (java.util.ArrayList)179 RelNode (org.apache.calcite.rel.RelNode)130 RexBuilder (org.apache.calcite.rex.RexBuilder)76 RexInputRef (org.apache.calcite.rex.RexInputRef)72 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)65 Pair (org.apache.calcite.util.Pair)55 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)47 HashMap (java.util.HashMap)39 Map (java.util.Map)35 AggregateCall (org.apache.calcite.rel.core.AggregateCall)35 SqlNode (org.apache.calcite.sql.SqlNode)32 ImmutableList (com.google.common.collect.ImmutableList)31 RelBuilder (org.apache.calcite.tools.RelBuilder)29 RelDataTypeFieldImpl (org.apache.calcite.rel.type.RelDataTypeFieldImpl)26 List (java.util.List)23 LinkedHashSet (java.util.LinkedHashSet)22 RelOptUtil (org.apache.calcite.plan.RelOptUtil)22