Search in sources :

Example 1 with UnionVectorWriter

use of org.apache.drill.exec.vector.complex.impl.UnionVectorWriter in project drill by apache.

the class MapUtility method writeToMapFromReader.

public static void writeToMapFromReader(FieldReader fieldReader, MapWriter mapWriter, String fieldName, String caller) {
    try {
        MajorType valueMajorType = fieldReader.getType();
        MinorType valueMinorType = valueMajorType.getMinorType();
        WriterExtractor extractor = new WriterExtractor(fieldName, valueMajorType, mapWriter, fieldReader instanceof UnionReader);
        switch(valueMinorType) {
            case TINYINT:
                fieldReader.copyAsValue(extractor.get(ListWriter::tinyInt, MapWriter::tinyInt, UnionVectorWriter::tinyInt));
                break;
            case SMALLINT:
                fieldReader.copyAsValue(extractor.get(ListWriter::smallInt, MapWriter::smallInt, UnionVectorWriter::smallInt));
                break;
            case BIGINT:
                fieldReader.copyAsValue(extractor.get(ListWriter::bigInt, MapWriter::bigInt, UnionVectorWriter::bigInt));
                break;
            case INT:
                fieldReader.copyAsValue(extractor.get(ListWriter::integer, MapWriter::integer, UnionVectorWriter::integer));
                break;
            case UINT1:
                fieldReader.copyAsValue(extractor.get(ListWriter::uInt1, MapWriter::uInt1, UnionVectorWriter::uInt1));
                break;
            case UINT2:
                fieldReader.copyAsValue(extractor.get(ListWriter::uInt2, MapWriter::uInt2, UnionVectorWriter::uInt2));
                break;
            case UINT4:
                fieldReader.copyAsValue(extractor.get(ListWriter::uInt4, MapWriter::uInt4, UnionVectorWriter::uInt4));
                break;
            case UINT8:
                fieldReader.copyAsValue(extractor.get(ListWriter::uInt8, MapWriter::uInt8, UnionVectorWriter::uInt8));
                break;
            case DECIMAL9:
                fieldReader.copyAsValue((Decimal9Writer) extractor.get(ListWriter::decimal9, MapWriter::decimal9, UnionVectorWriter::decimal9));
                break;
            case DECIMAL18:
                fieldReader.copyAsValue((Decimal18Writer) extractor.get(ListWriter::decimal18, MapWriter::decimal18, UnionVectorWriter::decimal18));
                break;
            case DECIMAL28SPARSE:
                fieldReader.copyAsValue((Decimal28SparseWriter) extractor.get(ListWriter::decimal28Sparse, MapWriter::decimal28Sparse, UnionVectorWriter::decimal28Sparse));
                break;
            case DECIMAL38SPARSE:
                fieldReader.copyAsValue((Decimal38SparseWriter) extractor.get(ListWriter::decimal38Sparse, MapWriter::decimal38Sparse, UnionVectorWriter::decimal38Sparse));
                break;
            case VARDECIMAL:
                fieldReader.copyAsValue((VarDecimalWriter) extractor.get(lw -> lw.varDecimal(valueMajorType.getPrecision(), valueMajorType.getScale()), (mw, fn) -> mw.varDecimal(fn, valueMajorType.getPrecision(), valueMajorType.getScale()), uw -> uw.varDecimal(valueMajorType.getPrecision(), valueMajorType.getScale())));
                break;
            case DATE:
                fieldReader.copyAsValue(extractor.get(ListWriter::date, MapWriter::date, UnionVectorWriter::date));
                break;
            case TIME:
                fieldReader.copyAsValue(extractor.get(ListWriter::time, MapWriter::time, UnionVectorWriter::time));
                break;
            case TIMESTAMP:
                fieldReader.copyAsValue(extractor.get(ListWriter::timeStamp, MapWriter::timeStamp, UnionVectorWriter::timeStamp));
                break;
            case INTERVAL:
                fieldReader.copyAsValue(extractor.get(ListWriter::interval, MapWriter::interval, UnionVectorWriter::interval));
                break;
            case INTERVALDAY:
                fieldReader.copyAsValue(extractor.get(ListWriter::intervalDay, MapWriter::intervalDay, UnionVectorWriter::intervalDay));
                break;
            case INTERVALYEAR:
                fieldReader.copyAsValue(extractor.get(ListWriter::intervalYear, MapWriter::intervalYear, UnionVectorWriter::intervalYear));
                break;
            case FLOAT4:
                fieldReader.copyAsValue(extractor.get(ListWriter::float4, MapWriter::float4, UnionVectorWriter::float4));
                break;
            case FLOAT8:
                fieldReader.copyAsValue(extractor.get(ListWriter::float8, MapWriter::float8, UnionVectorWriter::float8));
                break;
            case BIT:
                fieldReader.copyAsValue(extractor.get(ListWriter::bit, MapWriter::bit, UnionVectorWriter::bit));
                break;
            case VARCHAR:
                fieldReader.copyAsValue(extractor.get(ListWriter::varChar, MapWriter::varChar, UnionVectorWriter::varChar));
                break;
            case VARBINARY:
                fieldReader.copyAsValue(extractor.get(ListWriter::varBinary, MapWriter::varBinary, UnionVectorWriter::varBinary));
                break;
            case MAP:
                fieldReader.copyAsValue(extractor.get(ListWriter::map, MapWriter::map, UnionVectorWriter::map));
                break;
            case LIST:
                fieldReader.copyAsValue(mapWriter.list(fieldName).list());
                break;
            case DICT:
                fieldReader.copyAsValue(extractor.get(ListWriter::dict, MapWriter::dict, UnionVectorWriter::dict));
                break;
            default:
                throw new DrillRuntimeException(String.format("%s does not support input of type: %s", caller, valueMinorType));
        }
    } catch (ClassCastException e) {
        final MaterializedField field = fieldReader.getField();
        throw new DrillRuntimeException(String.format(TYPE_MISMATCH_ERROR, caller, field.getName(), field.getType()));
    }
}
Also used : MapWriter(org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter) UnionVectorWriter(org.apache.drill.exec.vector.complex.impl.UnionVectorWriter) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) ListWriter(org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) MaterializedField(org.apache.drill.exec.record.MaterializedField) UnionReader(org.apache.drill.exec.vector.complex.impl.UnionReader) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Aggregations

DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)1 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)1 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)1 MaterializedField (org.apache.drill.exec.record.MaterializedField)1 UnionReader (org.apache.drill.exec.vector.complex.impl.UnionReader)1 UnionVectorWriter (org.apache.drill.exec.vector.complex.impl.UnionVectorWriter)1 ListWriter (org.apache.drill.exec.vector.complex.writer.BaseWriter.ListWriter)1 MapWriter (org.apache.drill.exec.vector.complex.writer.BaseWriter.MapWriter)1