Search in sources :

Example 1 with ValueVectorHashHelper

use of org.apache.drill.exec.expr.fn.impl.ValueVectorHashHelper in project drill by apache.

the class HashJoinBatch method setupHash64.

private void setupHash64(HashTableConfig htConfig) {
    LogicalExpression[] keyExprsBuild = new LogicalExpression[htConfig.getKeyExprsBuild().size()];
    ErrorCollector collector = new ErrorCollectorImpl();
    int i = 0;
    for (NamedExpression ne : htConfig.getKeyExprsBuild()) {
        LogicalExpression expr = ExpressionTreeMaterializer.materialize(ne.getExpr(), buildBatch, collector, context.getFunctionRegistry());
        collector.reportErrors(logger);
        if (expr == null) {
            continue;
        }
        keyExprsBuild[i] = expr;
        i++;
    }
    i = 0;
    boolean missingField = false;
    TypedFieldId[] buildSideTypeFieldIds = new TypedFieldId[keyExprsBuild.length];
    for (NamedExpression ne : htConfig.getKeyExprsBuild()) {
        SchemaPath schemaPath = (SchemaPath) ne.getExpr();
        TypedFieldId typedFieldId = buildBatch.getValueVectorId(schemaPath);
        if (typedFieldId == null) {
            missingField = true;
            break;
        }
        buildSideTypeFieldIds[i] = typedFieldId;
        i++;
    }
    if (missingField) {
        logger.info("As some build side key fields not found, runtime filter was disabled");
        enableRuntimeFilter = false;
        return;
    }
    RuntimeFilterDef runtimeFilterDef = popConfig.getRuntimeFilterDef();
    List<BloomFilterDef> bloomFilterDefs = runtimeFilterDef.getBloomFilterDefs();
    for (BloomFilterDef bloomFilterDef : bloomFilterDefs) {
        String buildField = bloomFilterDef.getBuildField();
        SchemaPath schemaPath = new SchemaPath(new PathSegment.NameSegment(buildField), ExpressionPosition.UNKNOWN);
        TypedFieldId typedFieldId = buildBatch.getValueVectorId(schemaPath);
        if (typedFieldId == null) {
            missingField = true;
            break;
        }
        int fieldId = typedFieldId.getFieldIds()[0];
        bloomFilterDef2buildId.put(bloomFilterDef, fieldId);
    }
    if (missingField) {
        logger.info("As some build side join key fields not found, runtime filter was disabled");
        enableRuntimeFilter = false;
        return;
    }
    ValueVectorHashHelper hashHelper = new ValueVectorHashHelper(buildBatch, context);
    try {
        hash64 = hashHelper.getHash64(keyExprsBuild, buildSideTypeFieldIds);
    } catch (Exception e) {
        throw UserException.internalError(e).message("Failed to construct a field's hash64 dynamic codes").build(logger);
    }
}
Also used : ErrorCollector(org.apache.drill.common.expression.ErrorCollector) PathSegment(org.apache.drill.common.expression.PathSegment) ValueVectorHashHelper(org.apache.drill.exec.expr.fn.impl.ValueVectorHashHelper) UserException(org.apache.drill.common.exceptions.UserException) OutOfMemoryException(org.apache.drill.exec.exception.OutOfMemoryException) IOException(java.io.IOException) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) ErrorCollectorImpl(org.apache.drill.common.expression.ErrorCollectorImpl) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) SchemaPath(org.apache.drill.common.expression.SchemaPath) NamedExpression(org.apache.drill.common.logical.data.NamedExpression) TypedFieldId(org.apache.drill.exec.record.TypedFieldId) BloomFilterDef(org.apache.drill.exec.work.filter.BloomFilterDef) RuntimeFilterDef(org.apache.drill.exec.work.filter.RuntimeFilterDef)

Example 2 with ValueVectorHashHelper

use of org.apache.drill.exec.expr.fn.impl.ValueVectorHashHelper in project drill by apache.

the class RuntimeFilterRecordBatch method setupHashHelper.

/**
 * Takes care of setting up HashHelper if RuntimeFilter is received and the
 * HashHelper is not already setup. For each schema change hash64 should be
 * reset and this method needs to be called again.
 */
private void setupHashHelper() {
    current = context.getRuntimeFilter(rfIdentifier);
    if (current == null) {
        return;
    }
    if (bloomFilters == null) {
        bloomFilters = current.unwrap();
    }
    // Check if HashHelper is initialized or not
    if (hash64 == null) {
        ValueVectorHashHelper hashHelper = new ValueVectorHashHelper(incoming, context);
        try {
            // generate hash helper
            this.toFilterFields = current.getRuntimeFilterBDef().getProbeFieldsList();
            List<LogicalExpression> hashFieldExps = new ArrayList<>();
            List<TypedFieldId> typedFieldIds = new ArrayList<>();
            for (String toFilterField : toFilterFields) {
                SchemaPath schemaPath = new SchemaPath(new PathSegment.NameSegment(toFilterField), ExpressionPosition.UNKNOWN);
                TypedFieldId typedFieldId = container.getValueVectorId(schemaPath);
                int[] fieldIds = typedFieldId.getFieldIds();
                this.field2id.put(toFilterField, fieldIds[0]);
                typedFieldIds.add(typedFieldId);
                ValueVectorReadExpression toHashFieldExp = new ValueVectorReadExpression(typedFieldId);
                hashFieldExps.add(toHashFieldExp);
            }
            hash64 = hashHelper.getHash64(hashFieldExps.toArray(new LogicalExpression[hashFieldExps.size()]), typedFieldIds.toArray(new TypedFieldId[typedFieldIds.size()]));
        } catch (Exception e) {
            throw UserException.internalError(e).build(logger);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) PathSegment(org.apache.drill.common.expression.PathSegment) ValueVectorHashHelper(org.apache.drill.exec.expr.fn.impl.ValueVectorHashHelper) UserException(org.apache.drill.common.exceptions.UserException) OutOfMemoryException(org.apache.drill.exec.exception.OutOfMemoryException) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) ValueVectorReadExpression(org.apache.drill.exec.expr.ValueVectorReadExpression) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) SchemaPath(org.apache.drill.common.expression.SchemaPath) TypedFieldId(org.apache.drill.exec.record.TypedFieldId)

Example 3 with ValueVectorHashHelper

use of org.apache.drill.exec.expr.fn.impl.ValueVectorHashHelper in project drill by apache.

the class BloomFilterTest method getHash64.

private static ValueVectorHashHelper.Hash64 getHash64(FragmentContext context, RowSet.SingleRowSet probeRowSet) throws ClassTransformationException, IOException, SchemaChangeException {
    RecordBatch probeRecordBatch = new TestRecordBatch(probeRowSet.container());
    TypedFieldId probeFieldId = probeRecordBatch.getValueVectorId(SchemaPath.getSimplePath("a"));
    ValueVectorReadExpression probExp = new ValueVectorReadExpression(probeFieldId);
    LogicalExpression[] probExpressions = new LogicalExpression[1];
    probExpressions[0] = probExp;
    TypedFieldId[] probeFieldIds = new TypedFieldId[1];
    probeFieldIds[0] = probeFieldId;
    ValueVectorHashHelper probeValueVectorHashHelper = new ValueVectorHashHelper(probeRecordBatch, context);
    return probeValueVectorHashHelper.getHash64(probExpressions, probeFieldIds);
}
Also used : ValueVectorReadExpression(org.apache.drill.exec.expr.ValueVectorReadExpression) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) RecordBatch(org.apache.drill.exec.record.RecordBatch) TypedFieldId(org.apache.drill.exec.record.TypedFieldId) ValueVectorHashHelper(org.apache.drill.exec.expr.fn.impl.ValueVectorHashHelper)

Aggregations

LogicalExpression (org.apache.drill.common.expression.LogicalExpression)3 ValueVectorHashHelper (org.apache.drill.exec.expr.fn.impl.ValueVectorHashHelper)3 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)3 UserException (org.apache.drill.common.exceptions.UserException)2 PathSegment (org.apache.drill.common.expression.PathSegment)2 SchemaPath (org.apache.drill.common.expression.SchemaPath)2 OutOfMemoryException (org.apache.drill.exec.exception.OutOfMemoryException)2 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)2 ValueVectorReadExpression (org.apache.drill.exec.expr.ValueVectorReadExpression)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ErrorCollector (org.apache.drill.common.expression.ErrorCollector)1 ErrorCollectorImpl (org.apache.drill.common.expression.ErrorCollectorImpl)1 NamedExpression (org.apache.drill.common.logical.data.NamedExpression)1 RecordBatch (org.apache.drill.exec.record.RecordBatch)1 BloomFilterDef (org.apache.drill.exec.work.filter.BloomFilterDef)1 RuntimeFilterDef (org.apache.drill.exec.work.filter.RuntimeFilterDef)1