use of datawave.query.iterator.builder.IndexRangeIteratorBuilder in project datawave by NationalSecurityAgency.
the class IteratorBuildingVisitor method visit.
@Override
public Object visit(ASTAndNode and, Object data) {
QueryPropertyMarker.Instance instance = QueryPropertyMarker.findInstance(and);
if (instance.isType(ExceededOrThresholdMarkerJexlNode.class)) {
JexlNode source = instance.getSource();
// Ivarator to get the job done
if (source instanceof ASTAndNode) {
try {
ivarateList(and, source, data);
} catch (IOException ioe) {
throw new DatawaveFatalQueryException(ioe);
}
} else {
QueryException qe = new QueryException(DatawaveErrorCode.UNEXPECTED_SOURCE_NODE, MessageFormat.format("{0}", "Limited ExceededOrThresholdMarkerJexlNode"));
throw new DatawaveFatalQueryException(qe);
}
} else if (data instanceof IndexRangeIteratorBuilder) {
// index checking has already been done, otherwise we would not have
// an "ExceededValueThresholdMarker"
// hence the "IndexAgnostic" method can be used here
LiteralRange range = JexlASTHelper.findRange().recursively().getRange(and);
if (range == null) {
QueryException qe = new QueryException(DatawaveErrorCode.MULTIPLE_RANGES_IN_EXPRESSION);
throw new DatawaveFatalQueryException(qe);
}
((IndexRangeIteratorBuilder) data).setRange(range);
} else if (instance.isType(ExceededValueThresholdMarkerJexlNode.class)) {
// if the parent is our ExceededValueThreshold marker, then use an
// Ivarator to get the job done unless we don't have to
JexlNode source = instance.getSource();
String identifier = null;
LiteralRange<?> range = null;
boolean negatedLocal = false;
if (source instanceof ASTAndNode) {
range = buildLiteralRange(source, null);
identifier = range.getFieldName();
} else {
if (source instanceof ASTNRNode || source instanceof ASTNotNode)
negatedLocal = true;
range = buildLiteralRange(source);
identifier = JexlASTHelper.getIdentifier(source);
}
boolean negatedOverall = negatedLocal;
if (data instanceof AbstractIteratorBuilder) {
AbstractIteratorBuilder oib = (AbstractIteratorBuilder) data;
if (oib.isInANot()) {
negatedOverall = !negatedOverall;
}
}
// or the field is index only but not in the term frequencies, then we must ivarate
if (!limitLookup || !allowTermFrequencyLookup || (indexOnlyFields.contains(identifier) && !termFrequencyFields.contains(identifier))) {
if (source instanceof ASTAndNode) {
try {
List<ASTFunctionNode> functionNodes = JexlASTHelper.getFunctionNodes(source).stream().filter(node -> JexlFunctionArgumentDescriptorFactory.F.getArgumentDescriptor(node).allowIvaratorFiltering()).collect(Collectors.toList());
if (functionNodes.isEmpty()) {
ivarateRange(and, source, data);
} else {
ivarateFilter(and, source, data, functionNodes);
}
} catch (IOException ioe) {
throw new DatawaveFatalQueryException("Unable to ivarate", ioe);
}
} else if (source instanceof ASTERNode || source instanceof ASTNRNode) {
try {
ivarateRegex(and, source, data);
} catch (IOException ioe) {
throw new DatawaveFatalQueryException("Unable to ivarate", ioe);
}
} else {
QueryException qe = new QueryException(DatawaveErrorCode.UNEXPECTED_SOURCE_NODE, MessageFormat.format("{0}", "ExceededValueThresholdMarkerJexlNode"));
throw new DatawaveFatalQueryException(qe);
}
} else {
NestedIterator<Key> nested = null;
if (termFrequencyFields.contains(identifier)) {
nested = buildExceededFromTermFrequency(identifier, and, source, range, data);
} else {
/**
* This is okay since 1) We are doc specific 2) We are not index only or tf 3) Therefore, we must evaluate against the document for this
* expression 4) Return a stubbed range in case we have a disjunction that breaks the current doc.
*/
if (!limitOverride && !negatedOverall)
nested = createExceededCheck(identifier, range, and);
}
if (null != nested && null != data && data instanceof AbstractIteratorBuilder) {
AbstractIteratorBuilder iterators = (AbstractIteratorBuilder) data;
if (negatedLocal) {
iterators.addExclude(nested);
} else {
iterators.addInclude(nested);
}
} else {
if (isQueryFullySatisfied == true) {
log.warn("Determined that isQueryFullySatisfied should be false, but it was not preset to false in the SatisfactionVisitor");
}
return nested;
}
}
} else if (null != data && data instanceof AndIteratorBuilder) {
and.childrenAccept(this, data);
} else {
// Create an AndIterator and recursively add the children
AbstractIteratorBuilder andItr = new AndIteratorBuilder();
andItr.negateAsNeeded(data);
and.childrenAccept(this, andItr);
// If there is no parent
if (data == null) {
// Make this AndIterator the root node
if (!andItr.includes().isEmpty()) {
root = andItr.build();
}
} else {
// Otherwise, add this AndIterator to its parent
AbstractIteratorBuilder parent = (AbstractIteratorBuilder) data;
if (!andItr.includes().isEmpty()) {
parent.addInclude(andItr.build());
}
}
if (log.isTraceEnabled()) {
log.trace("ASTAndNode visit: pretty formatting of:\nparent.includes:" + formatIncludesOrExcludes(andItr.includes()) + "\nparent.excludes:" + formatIncludesOrExcludes(andItr.excludes()));
}
}
return null;
}
use of datawave.query.iterator.builder.IndexRangeIteratorBuilder in project datawave by NationalSecurityAgency.
the class IteratorBuildingVisitor method ivarateRange.
/**
* Build the iterator stack using the regex ivarator (field index caching regex iterator)
*
* @param rootNode
* the node that was processed to generated this builder
* @param sourceNode
* the source node derived from the root
* @param data
*/
public void ivarateRange(JexlNode rootNode, JexlNode sourceNode, Object data) throws IOException {
IndexRangeIteratorBuilder builder = new IndexRangeIteratorBuilder();
builder.negateAsNeeded(data);
// hence the "IndexAgnostic" method can be used here
if (sourceNode instanceof ASTAndNode) {
LiteralRange range = JexlASTHelper.findRange().recursively().getRange(sourceNode);
if (range == null) {
QueryException qe = new QueryException(DatawaveErrorCode.MULTIPLE_RANGES_IN_EXPRESSION);
throw new DatawaveFatalQueryException(qe);
}
builder.setRange(range);
} else {
QueryException qe = new QueryException(DatawaveErrorCode.UNEXPECTED_SOURCE_NODE, MessageFormat.format("{0}", "ExceededValueThresholdMarkerJexlNode"));
throw new DatawaveFatalQueryException(qe);
}
builder.forceDocumentBuild(!limitLookup && this.isQueryFullySatisfied);
ivarate(builder, rootNode, sourceNode, data);
}
use of datawave.query.iterator.builder.IndexRangeIteratorBuilder in project datawave by NationalSecurityAgency.
the class IteratorBuildingVisitor method ivarateList.
/**
* Build the iterator stack using the regex ivarator (field index caching regex iterator)
*
* @param rootNode
* the node that was processed to generated this builder
* @param sourceNode
* the source node derived from the root
* @param data
*/
public void ivarateList(JexlNode rootNode, JexlNode sourceNode, Object data) throws IOException {
IvaratorBuilder builder = null;
try {
String id = ExceededOrThresholdMarkerJexlNode.getId(sourceNode);
String field = JexlASTHelper.deconstructIdentifier(ExceededOrThresholdMarkerJexlNode.getField(sourceNode));
ExceededOrThresholdMarkerJexlNode.ExceededOrParams params = ExceededOrThresholdMarkerJexlNode.getParameters(sourceNode);
if (params.getRanges() != null && !params.getRanges().isEmpty()) {
IndexRangeIteratorBuilder rangeIterBuilder = new IndexRangeIteratorBuilder();
builder = rangeIterBuilder;
SortedSet<Range> ranges = params.getSortedAccumuloRanges();
rangeIterBuilder.setSubRanges(params.getSortedAccumuloRanges());
// cache these ranges for use during Jexl Evaluation
if (exceededOrEvaluationCache != null)
exceededOrEvaluationCache.put(id, ranges);
LiteralRange<?> fullRange = new LiteralRange<>(String.valueOf(ranges.first().getStartKey().getRow()), ranges.first().isStartKeyInclusive(), String.valueOf(ranges.last().getEndKey().getRow()), ranges.last().isEndKeyInclusive(), field, NodeOperand.AND);
rangeIterBuilder.setRange(fullRange);
} else {
IndexListIteratorBuilder listIterBuilder = new IndexListIteratorBuilder();
builder = listIterBuilder;
if (params.getValues() != null && !params.getValues().isEmpty()) {
Set<String> values = new TreeSet<>(params.getValues());
listIterBuilder.setValues(values);
// cache these values for use during Jexl Evaluation
if (exceededOrEvaluationCache != null)
exceededOrEvaluationCache.put(id, values);
} else if (params.getFstURI() != null) {
URI fstUri = new URI(params.getFstURI());
FST fst;
// only recompute this if not already set since this is potentially expensive
if (exceededOrEvaluationCache.containsKey(id)) {
fst = (FST) exceededOrEvaluationCache.get(id);
} else {
fst = DatawaveFieldIndexListIteratorJexl.FSTManager.get(new Path(fstUri), hdfsFileCompressionCodec, hdfsFileSystem.getFileSystem(fstUri));
}
listIterBuilder.setFst(fst);
// cache this fst for use during JexlEvaluation.
if (exceededOrEvaluationCache != null)
exceededOrEvaluationCache.put(id, fst);
}
// If this is actually negated, then this will be added to excludes. Do not negate in the ivarator
listIterBuilder.setNegated(false);
}
builder.setField(field);
} catch (IOException | URISyntaxException | NullPointerException e) {
QueryException qe = new QueryException(DatawaveErrorCode.UNPARSEABLE_EXCEEDED_OR_PARAMS, e, MessageFormat.format("Class: {0}", ExceededOrThresholdMarkerJexlNode.class.getSimpleName()));
throw new DatawaveFatalQueryException(qe);
}
builder.negateAsNeeded(data);
builder.forceDocumentBuild(!limitLookup && this.isQueryFullySatisfied);
ivarate(builder, rootNode, sourceNode, data);
}
Aggregations