Search in sources :

Example 76 with MinorType

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

the class FunctionImplementationRegistry method functionReplacement.

/**
 * Checks if this function replacement is needed.
 *
 * @param functionCall function call
 * @return new function name is replacement took place, otherwise original function name
 */
private String functionReplacement(FunctionCall functionCall) {
    String funcName = functionCall.getName();
    if (functionCall.argCount() == 0) {
        return funcName;
    }
    boolean castEmptyStringToNull = optionManager != null && optionManager.getOption(ExecConstants.CAST_EMPTY_STRING_TO_NULL_OPTION);
    if (!castEmptyStringToNull) {
        return funcName;
    }
    MajorType majorType = functionCall.arg(0).getMajorType();
    DataMode dataMode = majorType.getMode();
    MinorType minorType = majorType.getMinorType();
    if (FunctionReplacementUtils.isReplacementNeeded(funcName, minorType)) {
        funcName = FunctionReplacementUtils.getReplacingFunction(funcName, dataMode, minorType);
    }
    return funcName;
}
Also used : MajorType(org.apache.drill.common.types.TypeProtos.MajorType) DataMode(org.apache.drill.common.types.TypeProtos.DataMode) MinorType(org.apache.drill.common.types.TypeProtos.MinorType)

Example 77 with MinorType

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

the class SimpleReaderBuilder method buildUnion.

private AbstractObjectReader buildUnion(UnionVector vector, VectorAccessor unionAccessor, VectorDescrip descrip) {
    final MetadataProvider provider = descrip.childProvider();
    final AbstractObjectReader[] variants = new AbstractObjectReader[MinorType.values().length];
    int i = 0;
    for (final MinorType type : vector.getField().getType().getSubTypeList()) {
        // This call will create the vector if it does not yet exist.
        // Will throw an exception for unsupported types.
        // so call this only if the MajorType reports that the type
        // already exists.
        final ValueVector memberVector = vector.getMember(type);
        final VectorDescrip memberDescrip = new VectorDescrip(provider, i++, memberVector.getField());
        variants[type.ordinal()] = buildVectorReader(memberVector, memberDescrip);
    }
    return UnionReaderImpl.build(descrip.metadata, unionAccessor, variants);
}
Also used : RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) ValueVector(org.apache.drill.exec.vector.ValueVector) AbstractObjectReader(org.apache.drill.exec.vector.accessor.reader.AbstractObjectReader) MetadataProvider(org.apache.drill.exec.physical.resultSet.model.MetadataProvider) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) VectorDescrip(org.apache.drill.exec.physical.resultSet.model.MetadataProvider.VectorDescrip)

Example 78 with MinorType

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

the class ContainerVisitor method apply.

protected R apply(ValueVector vector, A arg) {
    final MaterializedField schema = vector.getField();
    final MajorType majorType = schema.getType();
    final MinorType type = majorType.getMinorType();
    final DataMode mode = majorType.getMode();
    switch(type) {
        case MAP:
            if (mode == DataMode.REPEATED) {
                return visitRepeatedMap((RepeatedMapVector) vector, arg);
            } else {
                return visitMap((AbstractMapVector) vector, arg);
            }
        case LIST:
            if (mode == DataMode.REPEATED) {
                return visitRepeatedList((RepeatedListVector) vector, arg);
            } else {
                return visitList((ListVector) vector, arg);
            }
        default:
            if (mode == DataMode.REPEATED) {
                return visitRepeatedPrimitive((BaseRepeatedValueVector) vector, arg);
            } else {
                return visitPrimitive(vector, arg);
            }
    }
}
Also used : MajorType(org.apache.drill.common.types.TypeProtos.MajorType) DataMode(org.apache.drill.common.types.TypeProtos.DataMode) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) MaterializedField(org.apache.drill.exec.record.MaterializedField)

Example 79 with MinorType

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

the class SchemaUtil method coerceVector.

private static ValueVector coerceVector(ValueVector v, VectorContainer c, MaterializedField field, int recordCount, BufferAllocator allocator) {
    if (v != null) {
        int valueCount = v.getAccessor().getValueCount();
        TransferPair tp = v.getTransferPair(allocator);
        tp.transfer();
        if (v.getField().getType().getMinorType().equals(field.getType().getMinorType())) {
            if (field.getType().getMinorType() == MinorType.UNION) {
                UnionVector u = (UnionVector) tp.getTo();
                for (MinorType t : field.getType().getSubTypeList()) {
                    u.addSubType(t);
                }
            }
            return tp.getTo();
        } else {
            ValueVector newVector = TypeHelper.getNewVector(field, allocator);
            Preconditions.checkState(field.getType().getMinorType() == MinorType.UNION, "Can only convert vector to Union vector");
            UnionVector u = (UnionVector) newVector;
            u.setFirstType(tp.getTo(), valueCount);
            return u;
        }
    } else {
        v = TypeHelper.getNewVector(field, allocator);
        v.allocateNew();
        v.getMutator().setValueCount(recordCount);
        return v;
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) UnionVector(org.apache.drill.exec.vector.complex.UnionVector)

Example 80 with MinorType

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

the class SasBatchReader method buildWriterList.

private void buildWriterList(TupleMetadata schema) {
    int colIndex = 0;
    for (MaterializedField field : schema.toFieldList()) {
        String fieldName = field.getName();
        MinorType type = field.getType().getMinorType();
        if (type == MinorType.FLOAT8) {
            writerList.add(new DoubleSasColumnWriter(colIndex, fieldName, rowWriter));
        } else if (type == MinorType.DATE) {
            writerList.add(new DateSasColumnWriter(colIndex, fieldName, rowWriter));
        } else if (type == MinorType.TIME) {
            writerList.add(new TimeSasColumnWriter(colIndex, fieldName, rowWriter));
        } else if (type == MinorType.VARCHAR) {
            writerList.add(new StringSasColumnWriter(colIndex, fieldName, rowWriter));
        } else if (type == MinorType.TIMESTAMP) {
            writerList.add(new TimestampSasColumnWriter(colIndex, fieldName, rowWriter));
        } else {
            throw UserException.dataReadError().message(fieldName + " is an unparsable data type: " + type.name() + ".  The SAS reader does not support this data type.").addContext(errorContext).build(logger);
        }
        colIndex++;
    }
}
Also used : MinorType(org.apache.drill.common.types.TypeProtos.MinorType) MaterializedField(org.apache.drill.exec.record.MaterializedField)

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