Search in sources :

Example 11 with MinorType

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

the class PcapRecordReader method initCols.

private ImmutableList<ProjectedColumnInfo> initCols(final Schema schema) {
    ImmutableList.Builder<ProjectedColumnInfo> pciBuilder = ImmutableList.builder();
    ColumnDto column;
    for (int i = 0; i < schema.getNumberOfColumns(); i++) {
        column = schema.getColumnByIndex(i);
        final String name = column.getColumnName().toLowerCase();
        final PcapTypes type = column.getColumnType();
        TypeProtos.MinorType minorType = TYPES.get(type);
        ProjectedColumnInfo pci = getProjectedColumnInfo(column, name, minorType);
        pciBuilder.add(pci);
    }
    return pciBuilder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) PcapTypes(org.apache.drill.exec.store.pcap.schema.PcapTypes) TypeProtos(org.apache.drill.common.types.TypeProtos) ColumnDto(org.apache.drill.exec.store.pcap.dto.ColumnDto)

Example 12 with MinorType

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

the class ParquetToDrillTypeConverter method toMajorType.

public static TypeProtos.MajorType toMajorType(PrimitiveType.PrimitiveTypeName primitiveTypeName, int length, TypeProtos.DataMode mode, ConvertedType convertedType, int precision, int scale, OptionManager options) {
    MinorType minorType = getMinorType(primitiveTypeName, length, convertedType, precision, options);
    TypeProtos.MajorType.Builder typeBuilder = TypeProtos.MajorType.newBuilder().setMinorType(minorType).setMode(mode);
    if (CoreDecimalUtility.isDecimalType(minorType)) {
        typeBuilder.setPrecision(precision).setScale(scale);
    }
    return typeBuilder.build();
}
Also used : MinorType(org.apache.drill.common.types.TypeProtos.MinorType)

Example 13 with MinorType

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

the class ColumnDef method makeDefaultGenerator.

private void makeDefaultGenerator() {
    MinorType minorType = mockCol.getMinorType();
    switch(minorType) {
        case BIGINT:
            break;
        case BIT:
            generator = new BooleanGen();
            break;
        case DATE:
            break;
        case DECIMAL18:
            break;
        case DECIMAL28DENSE:
            break;
        case DECIMAL28SPARSE:
            break;
        case DECIMAL38DENSE:
            break;
        case DECIMAL38SPARSE:
            break;
        case DECIMAL9:
            break;
        case FIXED16CHAR:
            break;
        case FIXEDBINARY:
            break;
        case FIXEDCHAR:
            break;
        case FLOAT4:
            break;
        case FLOAT8:
            generator = new DoubleGen();
            break;
        case GENERIC_OBJECT:
            break;
        case INT:
            generator = new IntGen();
            break;
        case INTERVAL:
            break;
        case INTERVALDAY:
            break;
        case INTERVALYEAR:
            break;
        case LATE:
            break;
        case LIST:
            break;
        case MAP:
            break;
        case MONEY:
            break;
        case NULL:
            break;
        case SMALLINT:
            break;
        case TIME:
            break;
        case TIMESTAMP:
            break;
        case TIMESTAMPTZ:
            break;
        case TIMETZ:
            break;
        case TINYINT:
            break;
        case UINT1:
            break;
        case UINT2:
            break;
        case UINT4:
            break;
        case UINT8:
            break;
        case UNION:
            break;
        case VAR16CHAR:
            break;
        case VARBINARY:
            break;
        case VARCHAR:
            generator = new StringGen();
            break;
        default:
            break;
    }
    if (generator == null) {
        throw new IllegalArgumentException("No default column generator for column " + name + " of type " + minorType);
    }
    generator.setup(this);
}
Also used : MinorType(org.apache.drill.common.types.TypeProtos.MinorType)

Example 14 with MinorType

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

the class MockGroupScanPOP method clone.

@Override
public GroupScan clone(List<SchemaPath> columns) {
    if (columns.isEmpty()) {
        throw new IllegalArgumentException("No columns for mock scan");
    }
    List<MockColumn> mockCols = new ArrayList<>();
    Pattern p = Pattern.compile("(\\w+)_([isdb])(\\d*)");
    for (SchemaPath path : columns) {
        String col = path.getLastSegment().getNameSegment().getPath();
        if (SchemaPath.DYNAMIC_STAR.equals(col)) {
            return this;
        }
        Matcher m = p.matcher(col);
        if (!m.matches()) {
            throw new IllegalArgumentException("Badly formatted mock column name: " + col);
        }
        @SuppressWarnings("unused") String name = m.group(1);
        String type = m.group(2);
        String length = m.group(3);
        int width = 10;
        if (!length.isEmpty()) {
            width = Integer.parseInt(length);
        }
        MinorType minorType;
        switch(type) {
            case "i":
                minorType = MinorType.INT;
                break;
            case "s":
                minorType = MinorType.VARCHAR;
                break;
            case "d":
                minorType = MinorType.FLOAT8;
                break;
            case "b":
                minorType = MinorType.BIT;
                break;
            default:
                throw new IllegalArgumentException("Unsupported field type " + type + " for mock column " + col);
        }
        MockTableDef.MockColumn mockCol = new MockColumn(col, minorType, DataMode.REQUIRED, width, 0, 0, null, 1, null);
        mockCols.add(mockCol);
    }
    MockScanEntry entry = readEntries.get(0);
    MockColumn[] types = new MockColumn[mockCols.size()];
    mockCols.toArray(types);
    MockScanEntry newEntry = new MockScanEntry(entry.records, true, 0, 1, types);
    List<MockScanEntry> newEntries = new ArrayList<>();
    newEntries.add(newEntry);
    return new MockGroupScanPOP(url, newEntries);
}
Also used : Pattern(java.util.regex.Pattern) MockScanEntry(org.apache.drill.exec.store.mock.MockTableDef.MockScanEntry) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) SchemaPath(org.apache.drill.common.expression.SchemaPath) MockColumn(org.apache.drill.exec.store.mock.MockTableDef.MockColumn) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) MockColumn(org.apache.drill.exec.store.mock.MockTableDef.MockColumn)

Example 15 with MinorType

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

the class FieldIdUtil method getFieldId.

public static TypedFieldId getFieldId(ValueVector vector, int id, SchemaPath expectedPath, boolean hyper) {
    if (!expectedPath.getRootSegment().getPath().equalsIgnoreCase(vector.getField().getName())) {
        return null;
    }
    PathSegment seg = expectedPath.getRootSegment();
    TypedFieldId.Builder builder = TypedFieldId.newBuilder();
    if (hyper) {
        builder.hyper();
    }
    if (vector instanceof UnionVector) {
        builder.addId(id).remainder(expectedPath.getRootSegment().getChild());
        List<MinorType> minorTypes = ((UnionVector) vector).getSubTypes();
        MajorType.Builder majorTypeBuilder = MajorType.newBuilder().setMinorType(MinorType.UNION);
        for (MinorType type : minorTypes) {
            majorTypeBuilder.addSubType(type);
        }
        MajorType majorType = majorTypeBuilder.build();
        builder.intermediateType(majorType);
        if (seg.isLastPath()) {
            builder.finalType(majorType);
            return builder.build();
        } else {
            return getFieldIdIfMatchesUnion((UnionVector) vector, builder, false, seg.getChild());
        }
    } else if (vector instanceof ListVector) {
        ListVector list = (ListVector) vector;
        builder.intermediateType(vector.getField().getType());
        builder.addId(id);
        return getFieldIdIfMatches(list, builder, true, expectedPath.getRootSegment().getChild());
    } else if (vector instanceof AbstractContainerVector) {
        // we're looking for a multi path.
        AbstractContainerVector c = (AbstractContainerVector) vector;
        builder.intermediateType(vector.getField().getType());
        builder.addId(id);
        return getFieldIdIfMatches(c, builder, true, expectedPath.getRootSegment().getChild());
    } else {
        builder.intermediateType(vector.getField().getType());
        builder.addId(id);
        builder.finalType(vector.getField().getType());
        if (seg.isLastPath()) {
            return builder.build();
        } else {
            PathSegment child = seg.getChild();
            if (child.isArray() && child.isLastPath()) {
                builder.remainder(child);
                builder.withIndex();
                builder.finalType(vector.getField().getType().toBuilder().setMode(DataMode.OPTIONAL).build());
                return builder.build();
            } else {
                return null;
            }
        }
    }
}
Also used : TypedFieldId(org.apache.drill.exec.record.TypedFieldId) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) PathSegment(org.apache.drill.common.expression.PathSegment)

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