Search in sources :

Example 61 with MinorType

use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by axbaretto.

the class ColumnReaderFactory method buildColumnReader.

public static AbstractObjectReader buildColumnReader(MajorType majorType, VectorAccessor va) {
    MinorType type = majorType.getMinorType();
    DataMode mode = majorType.getMode();
    switch(type) {
        case GENERIC_OBJECT:
        case LATE:
        case NULL:
        case LIST:
        case MAP:
            throw new UnsupportedOperationException(type.toString());
        default:
            switch(mode) {
                case OPTIONAL:
                    return BaseScalarReader.build(majorType, va, newAccessor(type, nullableReaders));
                case REQUIRED:
                    return BaseScalarReader.build(majorType, va, newAccessor(type, requiredReaders));
                case REPEATED:
                    return ScalarArrayReader.build(majorType, va, newAccessor(type, elementReaders));
                default:
                    throw new UnsupportedOperationException(mode.toString());
            }
    }
}
Also used : DataMode(org.apache.drill.common.types.TypeProtos.DataMode) MinorType(org.apache.drill.common.types.TypeProtos.MinorType)

Example 62 with MinorType

use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by axbaretto.

the class ColumnWriterFactory method newWriter.

public static BaseScalarWriter newWriter(ValueVector vector) {
    MajorType major = vector.getField().getType();
    MinorType type = major.getMinorType();
    try {
        Class<? extends BaseScalarWriter> accessorClass = requiredWriters[type.ordinal()];
        if (accessorClass == null) {
            throw new UnsupportedOperationException(type.toString());
        }
        Constructor<? extends BaseScalarWriter> ctor = accessorClass.getConstructor(ValueVector.class);
        return ctor.newInstance(vector);
    } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException e) {
        throw new IllegalStateException(e);
    }
}
Also used : MajorType(org.apache.drill.common.types.TypeProtos.MajorType) InvocationTargetException(java.lang.reflect.InvocationTargetException) MinorType(org.apache.drill.common.types.TypeProtos.MinorType)

Example 63 with MinorType

use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by axbaretto.

the class IfExpression method getMajorType.

@Override
public MajorType getMajorType() {
    if (outputType != null) {
        return outputType;
    }
    MajorType elseType = elseExpression.getMajorType();
    MajorType ifType = ifCondition.expression.getMajorType();
    if (elseType.getMinorType() == MinorType.UNION) {
        Set<MinorType> subtypes = Sets.newHashSet();
        for (MinorType subtype : elseType.getSubTypeList()) {
            subtypes.add(subtype);
        }
        for (MinorType subtype : ifType.getSubTypeList()) {
            subtypes.add(subtype);
        }
        MajorType.Builder builder = MajorType.newBuilder().setMinorType(MinorType.UNION).setMode(DataMode.OPTIONAL);
        for (MinorType subtype : subtypes) {
            builder.addSubType(subtype);
        }
        return builder.build();
    }
    MajorType.Builder builder = MajorType.newBuilder().setMinorType(ifType.getMinorType());
    builder.setMode(elseType.getMode() == DataMode.OPTIONAL || ifType.getMode() == DataMode.OPTIONAL ? DataMode.OPTIONAL : elseType.getMode());
    builder = Types.calculateTypePrecisionAndScale(ifType, elseType, builder);
    return builder.build();
}
Also used : MajorType(org.apache.drill.common.types.TypeProtos.MajorType) MinorType(org.apache.drill.common.types.TypeProtos.MinorType)

Example 64 with MinorType

use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by apache.

the class VariantSchema method addType.

public ColumnMetadata addType(MaterializedField field) {
    Preconditions.checkState(!isSimple);
    MinorType type = field.getType().getMinorType();
    checkType(type);
    ColumnMetadata col;
    switch(type) {
        case LIST:
            col = new VariantColumnMetadata(field);
            break;
        case MAP:
            col = new MapColumnMetadata(field);
            break;
        case UNION:
            throw new IllegalArgumentException("Cannot add a union to a union");
        default:
            col = new PrimitiveColumnMetadata(field);
            break;
    }
    types.put(type, col);
    return col;
}
Also used : MinorType(org.apache.drill.common.types.TypeProtos.MinorType)

Example 65 with MinorType

use of org.apache.drill.common.types.TypeProtos.MinorType in project drill by apache.

the class UnionVectorShim method addMemberWriter.

/**
 * Performs just the work of adding a vector to the list of existing
 * variants. Called when adding a type via the writer, but also when
 * the result set loader promotes a list from single type to a union,
 * and provides this shim with the writer from the single-list shim.
 * In the latter case, the writer is already initialized and is already
 * part of the metadata for this list; so we don't want to call the
 * list's {@code addMember()} and repeat those operations.
 *
 * @param colWriter the column (type) writer to add
 */
public void addMemberWriter(AbstractObjectWriter colWriter) {
    final MinorType type = colWriter.schema().type();
    assert variants[type.ordinal()] == null;
    variants[type.ordinal()] = colWriter;
}
Also used : MinorType(org.apache.drill.common.types.TypeProtos.MinorType)

Aggregations

MinorType (org.apache.drill.common.types.TypeProtos.MinorType)86 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)32 MaterializedField (org.apache.drill.exec.record.MaterializedField)17 ValueVector (org.apache.drill.exec.vector.ValueVector)11 DataMode (org.apache.drill.common.types.TypeProtos.DataMode)10 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)8 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)7 SubOperatorTest (org.apache.drill.test.SubOperatorTest)6 Test (org.junit.Test)6 ImmutableList (com.google.common.collect.ImmutableList)5 SchemaPath (org.apache.drill.common.expression.SchemaPath)5 ValueHolder (org.apache.drill.exec.expr.holders.ValueHolder)5 IOException (java.io.IOException)4 UserException (org.apache.drill.common.exceptions.UserException)4 OriginalType (org.apache.parquet.schema.OriginalType)4 PrimitiveType (org.apache.parquet.schema.PrimitiveType)4 SQLException (java.sql.SQLException)3 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)3 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)3 ExtendableRowSet (org.apache.drill.exec.physical.rowSet.RowSet.ExtendableRowSet)3