Search in sources :

Example 11 with LiteralRange

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);
}
Also used : Text(org.apache.hadoop.io.Text) LongRange(org.apache.commons.lang.math.LongRange) LiteralRange(datawave.query.jexl.LiteralRange) Range(org.apache.accumulo.core.data.Range) ShardIndexQueryTableStaticMethods(datawave.query.jexl.lookups.ShardIndexQueryTableStaticMethods) JavaRegexParseException(datawave.query.parser.JavaRegexAnalyzer.JavaRegexParseException) LiteralRange(datawave.query.jexl.LiteralRange) HashSet(java.util.HashSet) IllegalRangeArgumentException(datawave.query.exceptions.IllegalRangeArgumentException)

Example 12 with LiteralRange

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;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) Collection(java.util.Collection) LiteralRange(datawave.query.jexl.LiteralRange)

Example 13 with LiteralRange

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;
}
Also used : ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) LiteralRange(datawave.query.jexl.LiteralRange)

Example 14 with LiteralRange

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);
    }
}
Also used : ASTReferenceExpression(org.apache.commons.jexl2.parser.ASTReferenceExpression) ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) QueryPropertyMarker(datawave.query.jexl.nodes.QueryPropertyMarker) ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) LiteralRange(datawave.query.jexl.LiteralRange) ASTReference(org.apache.commons.jexl2.parser.ASTReference) ASTAndNode(org.apache.commons.jexl2.parser.ASTAndNode)

Example 15 with LiteralRange

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;
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) LiteralRange(datawave.query.jexl.LiteralRange) ASTAndNode(org.apache.commons.jexl2.parser.ASTAndNode)

Aggregations

LiteralRange (datawave.query.jexl.LiteralRange)23 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)9 Range (org.apache.accumulo.core.data.Range)7 QueryException (datawave.webservice.query.exception.QueryException)6 Key (org.apache.accumulo.core.data.Key)6 ASTAndNode (org.apache.commons.jexl2.parser.ASTAndNode)6 JexlNode (org.apache.commons.jexl2.parser.JexlNode)6 PartialKey (org.apache.accumulo.core.data.PartialKey)5 ASTEQNode (org.apache.commons.jexl2.parser.ASTEQNode)5 Text (org.apache.hadoop.io.Text)5 IndexRangeIteratorBuilder (datawave.query.iterator.builder.IndexRangeIteratorBuilder)3 JavaRegexParseException (datawave.query.parser.JavaRegexAnalyzer.JavaRegexParseException)3 JsonObject (com.google.gson.JsonObject)2 AttributeFactory (datawave.query.attributes.AttributeFactory)2 IllegalRangeArgumentException (datawave.query.exceptions.IllegalRangeArgumentException)2 EventFieldIterator (datawave.query.iterator.EventFieldIterator)2 IndexFilterIteratorBuilder (datawave.query.iterator.builder.IndexFilterIteratorBuilder)2 TermFrequencyIndexBuilder (datawave.query.iterator.builder.TermFrequencyIndexBuilder)2 OrIterator (datawave.query.iterator.logic.OrIterator)2 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)2