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());
}
}
}
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);
}
}
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();
}
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;
}
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;
}
Aggregations