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