use of org.apache.drill.common.types.TypeProtos.MajorType in project drill by apache.
the class ProducerConsumerBatch method load.
private boolean load(final RecordBatchData batch) {
final VectorContainer newContainer = batch.getContainer();
if (schema != null && newContainer.getSchema().equals(schema)) {
container.zeroVectors();
final BatchSchema schema = container.getSchema();
for (int i = 0; i < container.getNumberOfColumns(); i++) {
final MaterializedField field = schema.getColumn(i);
final MajorType type = field.getType();
final ValueVector vOut = container.getValueAccessorById(TypeHelper.getValueVectorClass(type.getMinorType(), type.getMode()), container.getValueVectorId(SchemaPath.getSimplePath(field.getPath())).getFieldIds()).getValueVector();
final ValueVector vIn = newContainer.getValueAccessorById(TypeHelper.getValueVectorClass(type.getMinorType(), type.getMode()), newContainer.getValueVectorId(SchemaPath.getSimplePath(field.getPath())).getFieldIds()).getValueVector();
final TransferPair tp = vIn.makeTransferPair(vOut);
tp.transfer();
}
return false;
} else {
container.clear();
for (final VectorWrapper<?> w : newContainer) {
container.add(w.getValueVector());
}
container.buildSchema(SelectionVectorMode.NONE);
schema = container.getSchema();
return true;
}
}
use of org.apache.drill.common.types.TypeProtos.MajorType in project drill by apache.
the class MockRecordReader method setup.
@Override
public void setup(OperatorContext context, OutputMutator output) throws ExecutionSetupException {
try {
final int estimateRowSize = getEstimatedRecordSize(config.getTypes());
valueVectors = new ValueVector[config.getTypes().length];
batchRecordCount = 250000 / estimateRowSize;
for (int i = 0; i < config.getTypes().length; i++) {
final MajorType type = config.getTypes()[i].getMajorType();
final MaterializedField field = getVector(config.getTypes()[i].getName(), type, batchRecordCount);
final Class<? extends ValueVector> vvClass = TypeHelper.getValueVectorClass(field.getType().getMinorType(), field.getDataMode());
valueVectors[i] = output.addField(field, vvClass);
}
} catch (SchemaChangeException e) {
throw new ExecutionSetupException("Failure while setting up fields", e);
}
}
use of org.apache.drill.common.types.TypeProtos.MajorType in project drill by apache.
the class MaterializedField method getOtherNullableVersion.
public MaterializedField getOtherNullableVersion() {
MajorType mt = type;
DataMode newDataMode;
switch(mt.getMode()) {
case OPTIONAL:
newDataMode = DataMode.REQUIRED;
break;
case REQUIRED:
newDataMode = DataMode.OPTIONAL;
break;
default:
throw new UnsupportedOperationException();
}
return new MaterializedField(name, mt.toBuilder().setMode(newDataMode).build(), children);
}
use of org.apache.drill.common.types.TypeProtos.MajorType in project drill by apache.
the class DrillAggFuncHolder method addProtectedBlockHA.
/*
* This is customized version of "addProtectedBlock" for hash aggregation. It take one additional parameter "wsIndexVariable".
*/
private void addProtectedBlockHA(ClassGenerator<?> g, JBlock sub, String body, HoldingContainer[] inputVariables, JVar[] workspaceJVars, JExpression wsIndexVariable) {
if (inputVariables != null) {
for (int i = 0; i < inputVariables.length; i++) {
ValueReference parameter = getParameters()[i];
HoldingContainer inputVariable = inputVariables[i];
sub.decl(inputVariable.getHolder().type(), parameter.getName(), inputVariable.getHolder());
}
}
JVar[] internalVars = new JVar[workspaceJVars.length];
for (int i = 0; i < workspaceJVars.length; i++) {
if (getWorkspaceVars()[i].isInject()) {
internalVars[i] = sub.decl(g.getModel()._ref(getWorkspaceVars()[i].getType()), getWorkspaceVars()[i].getName(), workspaceJVars[i]);
continue;
}
//sub.assign(workspaceJVars[i], JExpr._new(g.getHolderType(workspaceVars[i].majorType)));
//Access workspaceVar through workspace vector.
JInvocation getValueAccessor = g.getWorkspaceVectors().get(getWorkspaceVars()[i]).invoke("getAccessor").invoke("get");
if (Types.usesHolderForGet(getWorkspaceVars()[i].getMajorType())) {
sub.add(getValueAccessor.arg(wsIndexVariable).arg(workspaceJVars[i]));
} else {
sub.assign(workspaceJVars[i].ref("value"), getValueAccessor.arg(wsIndexVariable));
}
internalVars[i] = sub.decl(g.getHolderType(getWorkspaceVars()[i].getMajorType()), getWorkspaceVars()[i].getName(), workspaceJVars[i]);
}
Preconditions.checkNotNull(body);
sub.directStatement(body);
// reassign workspace variables back.
for (int i = 0; i < workspaceJVars.length; i++) {
sub.assign(workspaceJVars[i], internalVars[i]);
// Injected buffers are not stored as vectors skip storing them in vectors
if (getWorkspaceVars()[i].isInject()) {
continue;
}
//Change workspaceVar through workspace vector.
JInvocation setMeth;
MajorType type = getWorkspaceVars()[i].getMajorType();
if (Types.usesHolderForGet(type)) {
setMeth = g.getWorkspaceVectors().get(getWorkspaceVars()[i]).invoke("getMutator").invoke("setSafe").arg(wsIndexVariable).arg(workspaceJVars[i]);
} else {
if (!Types.isFixedWidthType(type) || Types.isRepeated(type)) {
setMeth = g.getWorkspaceVectors().get(getWorkspaceVars()[i]).invoke("getMutator").invoke("setSafe").arg(wsIndexVariable).arg(workspaceJVars[i].ref("value"));
} else {
setMeth = g.getWorkspaceVectors().get(getWorkspaceVars()[i]).invoke("getMutator").invoke("set").arg(wsIndexVariable).arg(workspaceJVars[i].ref("value"));
}
}
sub.add(setMeth);
JClass drillRunTimeException = g.getModel().ref(DrillRuntimeException.class);
}
}
use of org.apache.drill.common.types.TypeProtos.MajorType in project drill by apache.
the class DrillFuncHolder method getInputParameters.
/**
* Generates string representation of function input parameters:
* PARAMETER_TYPE_1-PARAMETER_MODE_1,PARAMETER_TYPE_2-PARAMETER_MODE_2
* Example: VARCHAR-REQUIRED,VARCHAR-OPTIONAL
* Returns empty string if function has no input parameters.
*
* @return string representation of function input parameters
*/
public String getInputParameters() {
StringBuilder builder = new StringBuilder();
builder.append("");
for (ValueReference ref : attributes.getParameters()) {
final MajorType type = ref.getType();
builder.append(",");
builder.append(type.getMinorType().toString());
builder.append("-");
builder.append(type.getMode().toString());
}
return builder.length() == 0 ? builder.toString() : builder.substring(1);
}
Aggregations