use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class DiscoveryLogic method makeRanges.
/**
* Makes two collections of ranges: one for the forward index (value0) and one for the reverse index (value1).
*
* If a literal has a field name, then the Range for that term will include the column family. If there are multiple fields, then multiple ranges are
* created.
*
* @param config
* @return
* @throws TableNotFoundException
* @throws ExecutionException
*/
@SuppressWarnings("unchecked")
public static Pair<Set<Range>, Set<Range>> makeRanges(DiscoveryQueryConfiguration config, Set<Text> familiesToSeek, MetadataHelper metadataHelper) throws TableNotFoundException, ExecutionException {
Set<Range> forwardRanges = new HashSet<>();
for (Entry<String, String> literalAndField : config.getLiterals().entries()) {
String literal = literalAndField.getKey(), field = literalAndField.getValue();
// if we're _ANYFIELD_, then use null when making the literal range
field = Constants.ANY_FIELD.equals(field) ? null : field;
if (field != null) {
familiesToSeek.add(new Text(field));
}
forwardRanges.add(ShardIndexQueryTableStaticMethods.getLiteralRange(field, literal));
}
for (Entry<String, LiteralRange<String>> rangeEntry : config.getRanges().entries()) {
LiteralRange<String> range = rangeEntry.getValue();
String field = rangeEntry.getKey();
// if we're _ANYFIELD_, then use null when making the literal range
field = Constants.ANY_FIELD.equals(field) ? null : field;
if (field != null) {
familiesToSeek.add(new Text(field));
}
try {
forwardRanges.add(ShardIndexQueryTableStaticMethods.getBoundedRangeRange(range));
} catch (IllegalRangeArgumentException e) {
log.error("Error using range [" + range + "]", e);
continue;
}
}
Set<Range> reverseRanges = new HashSet<>();
for (Entry<String, String> patternAndField : config.getPatterns().entries()) {
String pattern = patternAndField.getKey(), field = patternAndField.getValue();
// if we're _ANYFIELD_, then use null when making the literal range
field = Constants.ANY_FIELD.equals(field) ? null : field;
ShardIndexQueryTableStaticMethods.RefactoredRangeDescription description;
try {
if (field != null) {
familiesToSeek.add(new Text(field));
}
description = ShardIndexQueryTableStaticMethods.getRegexRange(field, pattern, false, metadataHelper, config);
} catch (JavaRegexParseException e) {
log.error("Error parsing pattern [" + pattern + "]", e);
continue;
}
if (description.isForReverseIndex) {
reverseRanges.add(description.range);
} else {
forwardRanges.add(description.range);
}
}
return Pair.with(forwardRanges, reverseRanges);
}
use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class LiteralRangeMultimapSerializer method serialize.
@Override
public JsonElement serialize(Multimap<String, LiteralRange<String>> src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject mm = new JsonObject();
for (Entry<String, Collection<LiteralRange<String>>> e : src.asMap().entrySet()) {
JsonArray values = new JsonArray();
Collection<LiteralRange<String>> filtered = Collections2.filter(e.getValue(), Predicates.notNull());
for (LiteralRange<String> value : filtered) values.add(lrSerializer.serialize(value, typeOfSrc, context));
mm.add(e.getKey(), values);
}
return mm;
}
use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class CompositeRange method contains.
public boolean contains(JexlNode node) {
boolean success;
LiteralRange range = JexlASTHelper.findRange().getRange(node);
if (range != null)
success = this.jexlNodeListLowerBound.contains(range.getLowerNode()) && this.jexlNodeListUpperBound.contains(range.getUpperNode());
else if (node instanceof ASTEQNode)
success = this.jexlNodeList.contains(node);
else
success = this.jexlNodeListLowerBound.contains(node) || this.jexlNodeListUpperBound.contains(node);
return success;
}
use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class PushdownLargeFieldedListsVisitor method assignNodeByField.
protected void assignNodeByField(JexlNode origNode, JexlNode subNode, Multimap<String, JexlNode> eqNodes, Multimap<String, JexlNode> rangeNodes, List<JexlNode> otherNodes) {
QueryPropertyMarker.Instance instance = QueryPropertyMarker.findInstance(subNode);
if (subNode instanceof ASTEQNode) {
String identifier = JexlASTHelper.getIdentifier(subNode, false);
if (identifier != null) {
eqNodes.put(JexlASTHelper.getIdentifier(subNode, false), origNode);
} else {
otherNodes.add(origNode);
}
} else if (instance.isType(ExceededValueThresholdMarkerJexlNode.class)) {
assignNodeByField(origNode, instance.getSource(), eqNodes, rangeNodes, otherNodes);
} else if (instance.isType(BoundedRange.class)) {
LiteralRange range = JexlASTHelper.findRange().getRange(subNode);
rangeNodes.put(JexlASTHelper.rebuildIdentifier(range.getFieldName()), origNode);
} else if ((subNode.jjtGetNumChildren() == 1) && (subNode instanceof ASTReferenceExpression || subNode instanceof ASTReference || subNode instanceof ASTAndNode)) {
assignNodeByField(origNode, subNode.jjtGetChild(0), eqNodes, rangeNodes, otherNodes);
} else {
otherNodes.add(origNode);
}
}
use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.
the class ExpandCompositeTerms method getLeafNodes.
/**
* This method checks each of the child nodes, and returns those which are leaf nodes. Range nodes are also considered leaf nodes for our purposes. If the
* root node is a range node, then that node will be returned. Reference, ReferenceExpression, and 'and' or 'or' nodes with a single child are passed
* through in search of the actual leaf node.
*
* @param rootNode
* The node whose children we will check
* @param otherNodes
* Non-leaf child nodes of the root node
* @return A multimap of field name to leaf node
*/
private Multimap<String, JexlNode> getLeafNodes(JexlNode rootNode, Collection<JexlNode> otherNodes) {
Multimap<String, JexlNode> childrenLeafNodes = ArrayListMultimap.create();
if (rootNode instanceof ASTAndNode) {
// check to see if this node is a range node, if so, this is our leaf node
JexlNode leafKid = getLeafNode(rootNode);
if (leafKid != null) {
String kidFieldName;
LiteralRange range = JexlASTHelper.findRange().getRange(leafKid);
kidFieldName = (range != null) ? range.getFieldName() : JexlASTHelper.getIdentifier(leafKid);
childrenLeafNodes.put(kidFieldName, rootNode);
}
}
if (childrenLeafNodes.isEmpty()) {
for (JexlNode child : children(rootNode)) {
JexlNode leafKid = getLeafNode(child);
if (leafKid != null) {
String kidFieldName;
LiteralRange range = JexlASTHelper.findRange().getRange(leafKid);
kidFieldName = (range != null) ? range.getFieldName() : JexlASTHelper.getIdentifier(leafKid);
// note: we save the actual direct sibling of the and node, including
// any reference nodes. those will be trimmed off later
childrenLeafNodes.put(kidFieldName, child);
} else {
if (otherNodes != null)
otherNodes.add(child);
}
}
}
return childrenLeafNodes;
}
Aggregations