use of datawave.query.exceptions.DatawaveFatalQueryException 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;
}
use of datawave.query.exceptions.DatawaveFatalQueryException 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.exceptions.DatawaveFatalQueryException in project datawave by NationalSecurityAgency.
the class IteratorBuildingVisitor method ivarateRegex.
/**
* 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 ivarateRegex(JexlNode rootNode, JexlNode sourceNode, Object data) throws IOException {
IndexRegexIteratorBuilder builder = new IndexRegexIteratorBuilder();
if (sourceNode instanceof ASTERNode || sourceNode instanceof ASTNRNode) {
builder.setNegated(sourceNode instanceof ASTNRNode);
builder.setField(JexlASTHelper.getIdentifier(sourceNode));
builder.setValue(String.valueOf(JexlASTHelper.getLiteralValue(sourceNode)));
} else {
QueryException qe = new QueryException(DatawaveErrorCode.UNEXPECTED_SOURCE_NODE, MessageFormat.format("{0}", "ExceededValueThresholdMarkerJexlNode"));
throw new DatawaveFatalQueryException(qe);
}
builder.negateAsNeeded(data);
builder.forceDocumentBuild(!limitLookup && this.isQueryFullySatisfied);
ivarate(builder, rootNode, sourceNode, data);
}
use of datawave.query.exceptions.DatawaveFatalQueryException in project datawave by NationalSecurityAgency.
the class JexlStringBuildingVisitor method buildQuery.
/**
* Build a String that is the equivalent JEXL query.
*
* @param script
* An ASTJexlScript
* @param sortDedupeChildren
* Whether or not to sort the child nodes, and dedupe them. Note: Only siblings (children with the same parent node) will be deduped. Flatten
* beforehand for maximum 'dedupeage'.
* @return
*/
public static String buildQuery(JexlNode script, boolean sortDedupeChildren) {
JexlStringBuildingVisitor visitor = new JexlStringBuildingVisitor(sortDedupeChildren);
String s = null;
try {
StringBuilder sb = (StringBuilder) script.jjtAccept(visitor, new StringBuilder());
s = sb.toString();
try {
JexlASTHelper.parseJexlQuery(s);
} catch (ParseException e) {
log.error("Could not parse JEXL AST after performing transformations to run the query", e);
for (String line : PrintingVisitor.formattedQueryStringList(script)) {
log.error(line);
}
log.error("");
QueryException qe = new QueryException(DatawaveErrorCode.QUERY_EXECUTION_ERROR, e);
throw new DatawaveFatalQueryException(qe);
}
} catch (StackOverflowError e) {
throw e;
}
return s;
}
use of datawave.query.exceptions.DatawaveFatalQueryException in project datawave by NationalSecurityAgency.
the class ExpandCompositeTerms method expandTerms.
/**
* Expand all nodes which have multiple dataTypes for the field.
*
* @param config
* Configuration parameters relevant to our query
* @param script
* The jexl node representing the query
* @return An expanded version of the passed-in script containing composite nodes
*/
@SuppressWarnings("unchecked")
public static <T extends JexlNode> T expandTerms(ShardQueryConfiguration config, T script) {
ExpandCompositeTerms visitor = new ExpandCompositeTerms(config);
// need to flatten the tree so i get all and nodes at the same level
script = TreeFlatteningRebuildingVisitor.flatten(script);
if (null == visitor.config.getCompositeToFieldMap()) {
QueryException qe = new QueryException(DatawaveErrorCode.DATATYPESFORINDEXFIELDS_MULTIMAP_MISSING);
throw new DatawaveFatalQueryException(qe);
}
return (T) script.jjtAccept(visitor, new ExpandData());
}
Aggregations