use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class IteratorBuildingVisitor method buildLiteralRange.
public static LiteralRange<?> buildLiteralRange(ASTERNode node) {
JavaRegexAnalyzer analyzer;
try {
analyzer = new JavaRegexAnalyzer(String.valueOf(JexlASTHelper.getLiteralValue(node)));
LiteralRange<String> range = new LiteralRange<>(JexlASTHelper.getIdentifier(node), NodeOperand.AND);
if (!analyzer.isLeadingLiteral()) {
// if the range is a leading wildcard we have to seek over the whole range since it's forward indexed only
range.updateLower(Constants.NULL_BYTE_STRING, true, node);
range.updateUpper(Constants.MAX_UNICODE_STRING, true, node);
} else {
range.updateLower(analyzer.getLeadingLiteral(), true, node);
if (analyzer.hasWildCard()) {
range.updateUpper(analyzer.getLeadingLiteral() + Constants.MAX_UNICODE_STRING, true, node);
} else {
range.updateUpper(analyzer.getLeadingLiteral(), true, node);
}
}
return range;
} catch (JavaRegexParseException | NoSuchElementException e) {
throw new DatawaveFatalQueryException(e);
}
}
use of datawave.query.jexl.LiteralRange 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);
}
use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class IteratorBuildingVisitor method buildLiteralRange.
LiteralRange<?> buildLiteralRange(ASTNRNode node) {
JavaRegexAnalyzer analyzer;
try {
analyzer = new JavaRegexAnalyzer(String.valueOf(JexlASTHelper.getLiteralValue(node)));
LiteralRange<String> range = new LiteralRange<>(JexlASTHelper.getIdentifier(node), NodeOperand.AND);
range.updateLower(analyzer.getLeadingOrTrailingLiteral(), true, node);
range.updateUpper(analyzer.getLeadingOrTrailingLiteral() + Constants.MAX_UNICODE_STRING, true, node);
return range;
} catch (JavaRegexParseException | NoSuchElementException e) {
throw new DatawaveFatalQueryException(e);
}
}
use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class IteratorBuildingVisitor method ivarateFilter.
/**
* Build the iterator stack using the filter ivarator (field index caching filter 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 ivarateFilter(JexlNode rootNode, JexlNode sourceNode, Object data, List<ASTFunctionNode> functionNodes) throws IOException {
IndexFilterIteratorBuilder builder = new IndexFilterIteratorBuilder();
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.setRangeAndFunction(range, new FunctionFilter(functionNodes));
} else {
QueryException qe = new QueryException(DatawaveErrorCode.UNEXPECTED_SOURCE_NODE, MessageFormat.format("{0}", "ASTFunctionNode"));
throw new DatawaveFatalQueryException(qe);
}
ivarate(builder, rootNode, sourceNode, data);
}
use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class PushdownMissingIndexRangeNodesVisitor method visit.
@Override
public Object visit(ASTAndNode node, Object data) {
LiteralRange range = JexlASTHelper.findRange().indexedOnly(this.dataTypeFilter, this.helper).notDelayed().getRange(node);
if (range != null) {
return delayBoundedIndexHole(range, node, data);
} else {
JexlNode andNode = JexlNodes.newInstanceOfType(node);
andNode.image = node.image;
andNode.jjtSetParent(node.jjtGetParent());
// We have no bounded range to replace, just proceed as normal
JexlNodes.ensureCapacity(andNode, node.jjtGetNumChildren());
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
JexlNode newChild = (JexlNode) node.jjtGetChild(i).jjtAccept(this, data);
andNode.jjtAddChild(newChild, i);
newChild.jjtSetParent(andNode);
}
return andNode;
}
}
Aggregations