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