use of datawave.query.iterator.builder.AbstractIteratorBuilder in project datawave by NationalSecurityAgency.
the class TLDIndexBuildingVisitor method visit.
@Override
public Object visit(ASTEQNode node, Object data) {
TLDIndexIteratorBuilder builder = new TLDIndexIteratorBuilder();
boolean isNegation = false;
if (data instanceof AbstractIteratorBuilder) {
AbstractIteratorBuilder oib = (AbstractIteratorBuilder) data;
isNegation = oib.isInANot();
}
builder.setSource(getSourceIterator(node, isNegation));
builder.setTimeFilter(getTimeFilter(node));
builder.setTypeMetadata(typeMetadata);
builder.setDatatypeFilter(datatypeFilter);
builder.setFieldsToAggregate(fieldsToAggregate);
builder.setKeyTransform(fiAggregator);
builder.forceDocumentBuild(!limitLookup && this.isQueryFullySatisfied);
builder.setNode(node);
node.childrenAccept(this, builder);
// handle this, so we should just not build an IndexIterator for it.
if (null == builder.getValue()) {
if (isQueryFullySatisfied == true) {
throw new RuntimeException("Determined that isQueryFullySatisfied should be false, but it was not preset to false by the SatisfactionVisitor");
}
return null;
}
// We have no parent already defined
if (data == null) {
// Make this EQNode the root
if (!includeReferences.contains(builder.getField()) && excludeReferences.contains(builder.getField())) {
throw new IllegalStateException(builder.getField() + " is a blacklisted reference.");
} else {
root = builder.build();
if (log.isTraceEnabled()) {
log.trace("Build IndexIterator: " + root);
}
}
} else {
AbstractIteratorBuilder iterators = (AbstractIteratorBuilder) data;
// Add this IndexIterator to the parent
if (!iterators.hasSeen(builder.getField(), builder.getValue()) && includeReferences.contains(builder.getField()) && !excludeReferences.contains(builder.getField())) {
iterators.addInclude(builder.build());
} else {
if (isQueryFullySatisfied == true) {
throw new RuntimeException("Determined that isQueryFullySatisfied should be false, but it was not preset to false by the SatisfactionVisitor");
}
}
}
return null;
}
use of datawave.query.iterator.builder.AbstractIteratorBuilder in project datawave by NationalSecurityAgency.
the class TLDIndexBuildingVisitor method visit.
@Override
public Object visit(ASTNENode node, Object data) {
// We have no parent already defined
if (data == null) {
// We don't support querying only on a negation
throw new IllegalStateException("Root node cannot be a negation");
}
TLDIndexIteratorBuilder builder = new TLDIndexIteratorBuilder();
builder.setSource(source.deepCopy(env));
builder.setTypeMetadata(typeMetadata);
builder.setDatatypeFilter(datatypeFilter);
builder.setFieldsToAggregate(fieldsToAggregate);
builder.setKeyTransform(fiAggregator);
builder.setTimeFilter(timeFilter);
builder.setNode(node);
node.childrenAccept(this, builder);
// handle this, so we should just not build an IndexIterator for it.
if (null == builder.getValue()) {
if (isQueryFullySatisfied == true) {
throw new RuntimeException("Determined that isQueryFullySatisfied should be false, but it was not preset to false by the SatisfactionVisitor");
}
return null;
}
AbstractIteratorBuilder iterators = (AbstractIteratorBuilder) data;
// Add the negated IndexIteratorBuilder to the parent as an *exclude*
if (!iterators.hasSeen(builder.getField(), builder.getValue()) && includeReferences.contains(builder.getField()) && !excludeReferences.contains(builder.getField())) {
iterators.addExclude(builder.build());
} else {
if (isQueryFullySatisfied == true) {
throw new RuntimeException("Determined that isQueryFullySatisfied should be false, but it was not preset to false by the SatisfactionVisitor");
}
}
return null;
}
use of datawave.query.iterator.builder.AbstractIteratorBuilder in project datawave by NationalSecurityAgency.
the class IteratorBuildingVisitor method visit.
@Override
public Object visit(ASTNotNode not, Object data) {
// We have no parent
if (root == null && data == null) {
// We don't support querying only on a negation
throw new IllegalStateException("Root node cannot be a negation!");
}
NegationBuilder stub = new NegationBuilder();
stub.negateAsNeeded(data);
// Add all of the children to this negation
not.childrenAccept(this, stub);
// Then add the children to the parent's children
AbstractIteratorBuilder parent = (AbstractIteratorBuilder) data;
/*
* because we're in a negation, the includes become excludes to the parent. conversely, the excludes in the child tree become includes to the parent.
*/
parent.excludes().addAll(stub.includes());
parent.includes().addAll(stub.excludes());
if (log.isTraceEnabled()) {
log.trace("pretty formatting of:\nparent.includes:" + formatIncludesOrExcludes(parent.includes()) + "\nparent.excludes:" + formatIncludesOrExcludes(parent.excludes()));
}
return null;
}
use of datawave.query.iterator.builder.AbstractIteratorBuilder 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.AbstractIteratorBuilder in project datawave by NationalSecurityAgency.
the class IteratorBuildingVisitor method visit.
@Override
public Object visit(ASTNENode node, Object data) {
// We have no parent already defined
if (data == null) {
// We don't support querying only on a negation
throw new IllegalStateException("Root node cannot be a negation");
}
IndexIteratorBuilder builder = null;
try {
builder = iteratorBuilderClass.asSubclass(IndexIteratorBuilder.class).newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
builder.setQueryId(queryId);
builder.setSource(source.deepCopy(env));
builder.setTypeMetadata(typeMetadata);
builder.setFieldsToAggregate(fieldsToAggregate);
builder.setTimeFilter(timeFilter);
builder.setDatatypeFilter(datatypeFilter);
builder.setKeyTransform(fiAggregator);
builder.setEnv(env);
builder.setNode(node);
node.childrenAccept(this, builder);
// handle this, so we should just not build an IndexIterator for it.
if (null == builder.getValue()) {
if (this.indexOnlyFields.contains(builder.getField())) {
QueryException qe = new QueryException(DatawaveErrorCode.INDEX_ONLY_FIELDS_RETRIEVAL_ERROR, MessageFormat.format("{0} {1} {2}", "Unable to compare index only field", builder.getField(), "against null"));
throw new DatawaveFatalQueryException(qe);
}
// SatisfactionVisitor should have already initialized this to false
if (isQueryFullySatisfied == true) {
log.warn("Determined that isQueryFullySatisfied should be false, but it was not preset to false in the SatisfactionVisitor");
}
return null;
}
AbstractIteratorBuilder iterators = (AbstractIteratorBuilder) data;
// Add the negated IndexIteratorBuilder to the parent as an *exclude*
if (!iterators.hasSeen(builder.getField(), builder.getValue()) && includeReferences.contains(builder.getField()) && !excludeReferences.contains(builder.getField())) {
iterators.addExclude(builder.build());
} else {
// SatisfactionVisitor should have already initialized this to false
if (isQueryFullySatisfied == true) {
log.warn("Determined that isQueryFullySatisfied should be false, but it was not preset to false in the SatisfactionVisitor");
}
}
return null;
}
Aggregations