Search in sources :

Example 1 with EmptyContext

use of datawave.query.util.EmptyContext in project datawave by NationalSecurityAgency.

the class QueryIterator method getEvaluation.

protected Iterator<Entry<Key, Document>> getEvaluation(NestedQueryIterator<Key> documentSource, SortedKeyValueIterator<Key, Value> sourceDeepCopy, Iterator<Entry<Key, Document>> documents, CompositeMetadata compositeMetadata, TypeMetadata typeMetadataForEval, Collection<ByteSequence> columnFamilies, boolean inclusive) {
    // Filter the Documents by testing them against the JEXL query
    if (!this.disableEvaluation) {
        JexlEvaluation jexlEvaluationFunction = getJexlEvaluation(documentSource);
        Collection<String> variables = null;
        if (null != documentSource && null != documentSource.getQuery()) {
            variables = VariableNameVisitor.parseQuery(jexlEvaluationFunction.parse(documentSource.getQuery()));
        } else {
            variables = VariableNameVisitor.parseQuery(jexlEvaluationFunction.parse(query));
        }
        final Iterator<Tuple2<Key, Document>> tupleItr = Iterators.transform(documents, new EntryToTuple<>());
        // get the function we use for the tf functionality. Note we are
        // getting an additional source deep copy for this function
        final Iterator<Tuple3<Key, Document, Map<String, Object>>> itrWithContext;
        if (this.isTermFrequenciesRequired()) {
            // The TFFunction can only prune non index-only fields
            Set<String> tfIndexOnlyFields = Sets.intersection(getTermFrequencyFields(), getIndexOnlyFields());
            Function<Tuple2<Key, Document>, Tuple3<Key, Document, Map<String, Object>>> tfFunction;
            tfFunction = TFFactory.getFunction(getScript(documentSource), getContentExpansionFields(), getTermFrequencyFields(), this.getTypeMetadata(), super.equality, getEvaluationFilter(), sourceDeepCopy.deepCopy(myEnvironment), tfIndexOnlyFields);
            itrWithContext = TraceIterators.transform(tupleItr, tfFunction, "Term Frequency Lookup");
        } else {
            itrWithContext = Iterators.transform(tupleItr, new EmptyContext<>());
        }
        try {
            IteratorBuildingVisitor iteratorBuildingVisitor = createIteratorBuildingVisitor(getDocumentRange(documentSource), false, this.sortedUIDs);
            Multimap<String, JexlNode> delayedNonEventFieldMap = DelayedNonEventSubTreeVisitor.getDelayedNonEventFieldMap(iteratorBuildingVisitor, script, getNonEventFields());
            IndexOnlyContextCreatorBuilder contextCreatorBuilder = new IndexOnlyContextCreatorBuilder().setSource(sourceDeepCopy).setRange(getDocumentRange(documentSource)).setTypeMetadata(typeMetadataForEval).setCompositeMetadata(compositeMetadata).setOptions(this).setVariables(variables).setIteratorBuildingVisitor(iteratorBuildingVisitor).setDelayedNonEventFieldMap(delayedNonEventFieldMap).setEquality(equality).setColumnFamilies(columnFamilies).setInclusive(inclusive).setComparatorFactory(this);
            final IndexOnlyContextCreator contextCreator = contextCreatorBuilder.build();
            if (exceededOrEvaluationCache != null) {
                contextCreator.addAdditionalEntries(exceededOrEvaluationCache);
            }
            final Iterator<Tuple3<Key, Document, DatawaveJexlContext>> itrWithDatawaveJexlContext = Iterators.transform(itrWithContext, contextCreator);
            Iterator<Tuple3<Key, Document, DatawaveJexlContext>> matchedDocuments = statelessFilter(itrWithDatawaveJexlContext, jexlEvaluationFunction);
            if (log.isTraceEnabled()) {
                log.trace("arithmetic:" + arithmetic + " range:" + getDocumentRange(documentSource) + ", thread:" + Thread.currentThread());
            }
            return Iterators.transform(matchedDocuments, new TupleToEntry<>());
        } catch (InstantiationException | MalformedURLException | IllegalAccessException | ConfigException e) {
            throw new IllegalStateException("Could not perform delayed index only evaluation", e);
        }
    } else if (log.isTraceEnabled()) {
        log.trace("Evaluation is disabled, not instantiating Jexl evaluation logic");
    }
    return documents;
}
Also used : EmptyContext(datawave.query.util.EmptyContext) MalformedURLException(java.net.MalformedURLException) ConfigException(org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException) IndexOnlyContextCreator(datawave.query.function.IndexOnlyContextCreator) JexlEvaluation(datawave.query.function.JexlEvaluation) IteratorBuildingVisitor(datawave.query.jexl.visitors.IteratorBuildingVisitor) IndexOnlyContextCreatorBuilder(datawave.query.function.IndexOnlyContextCreatorBuilder) Tuple2(datawave.query.util.Tuple2) Tuple3(datawave.query.util.Tuple3) JexlNode(org.apache.commons.jexl2.parser.JexlNode)

Aggregations

IndexOnlyContextCreator (datawave.query.function.IndexOnlyContextCreator)1 IndexOnlyContextCreatorBuilder (datawave.query.function.IndexOnlyContextCreatorBuilder)1 JexlEvaluation (datawave.query.function.JexlEvaluation)1 IteratorBuildingVisitor (datawave.query.jexl.visitors.IteratorBuildingVisitor)1 EmptyContext (datawave.query.util.EmptyContext)1 Tuple2 (datawave.query.util.Tuple2)1 Tuple3 (datawave.query.util.Tuple3)1 MalformedURLException (java.net.MalformedURLException)1 JexlNode (org.apache.commons.jexl2.parser.JexlNode)1 ConfigException (org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException)1