Search in sources :

Example 11 with MajorType

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;
    }
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) TransferPair(org.apache.drill.exec.record.TransferPair) BatchSchema(org.apache.drill.exec.record.BatchSchema) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) MaterializedField(org.apache.drill.exec.record.MaterializedField) VectorContainer(org.apache.drill.exec.record.VectorContainer)

Example 12 with MajorType

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);
    }
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) MaterializedField(org.apache.drill.exec.record.MaterializedField)

Example 13 with MajorType

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);
}
Also used : MajorType(org.apache.drill.common.types.TypeProtos.MajorType) DataMode(org.apache.drill.common.types.TypeProtos.DataMode)

Example 14 with MajorType

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);
    }
}
Also used : HoldingContainer(org.apache.drill.exec.expr.ClassGenerator.HoldingContainer) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) JClass(com.sun.codemodel.JClass) JInvocation(com.sun.codemodel.JInvocation) JVar(com.sun.codemodel.JVar)

Example 15 with MajorType

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);
}
Also used : MajorType(org.apache.drill.common.types.TypeProtos.MajorType)

Aggregations

MajorType (org.apache.drill.common.types.TypeProtos.MajorType)34 MaterializedField (org.apache.drill.exec.record.MaterializedField)13 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)8 ValueVector (org.apache.drill.exec.vector.ValueVector)8 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)7 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)5 JVar (com.sun.codemodel.JVar)4 HoldingContainer (org.apache.drill.exec.expr.ClassGenerator.HoldingContainer)4 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)4 ArrayList (java.util.ArrayList)3 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)3 ErrorCollector (org.apache.drill.common.expression.ErrorCollector)3 FunctionCall (org.apache.drill.common.expression.FunctionCall)3 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 ImmutableList (com.google.common.collect.ImmutableList)2 JClass (com.sun.codemodel.JClass)2 JExpression (com.sun.codemodel.JExpression)2 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)2 ErrorCollectorImpl (org.apache.drill.common.expression.ErrorCollectorImpl)2 IfCondition (org.apache.drill.common.expression.IfExpression.IfCondition)2