Search in sources :

Example 6 with LiteralRange

use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.

the class IteratorBuildingVisitor method buildExceededFromTermFrequency.

/**
 * @param data
 */
private NestedIterator<Key> buildExceededFromTermFrequency(String identifier, JexlNode rootNode, JexlNode sourceNode, LiteralRange<?> range, Object data) {
    if (limitLookup) {
        ChainableEventDataQueryFilter wrapped = createWrappedTermFrequencyFilter(identifier, sourceNode, attrFilter);
        NestedIterator<Key> eventFieldIterator = new EventFieldIterator(rangeLimiter, source.deepCopy(env), identifier, new AttributeFactory(this.typeMetadata), getEventFieldAggregator(identifier, wrapped));
        TermFrequencyIndexBuilder builder = new TermFrequencyIndexBuilder();
        builder.setSource(source.deepCopy(env));
        builder.setTypeMetadata(typeMetadata);
        builder.setFieldsToAggregate(fieldsToAggregate);
        builder.setTimeFilter(timeFilter);
        builder.setAttrFilter(attrFilter);
        builder.setDatatypeFilter(datatypeFilter);
        builder.setEnv(env);
        builder.setTermFrequencyAggregator(getTermFrequencyAggregator(identifier, sourceNode, attrFilter, attrFilter != null ? attrFilter.getMaxNextCount() : -1));
        builder.setNode(rootNode);
        Range fiRange = getFiRangeForTF(range);
        builder.setRange(fiRange);
        builder.setField(identifier);
        NestedIterator<Key> tfIterator = builder.build();
        OrIterator tfMerge = new OrIterator(Arrays.asList(tfIterator, eventFieldIterator));
        return tfMerge;
    } else {
        QueryException qe = new QueryException(DatawaveErrorCode.UNEXPECTED_SOURCE_NODE, MessageFormat.format("{0}", "buildExceededFromTermFrequency"));
        throw new DatawaveFatalQueryException(qe);
    }
}
Also used : ChainableEventDataQueryFilter(datawave.query.predicate.ChainableEventDataQueryFilter) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) QueryException(datawave.webservice.query.exception.QueryException) EventFieldIterator(datawave.query.iterator.EventFieldIterator) TermFrequencyIndexBuilder(datawave.query.iterator.builder.TermFrequencyIndexBuilder) OrIterator(datawave.query.iterator.logic.OrIterator) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) AttributeFactory(datawave.query.attributes.AttributeFactory) LiteralRange(datawave.query.jexl.LiteralRange) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 7 with LiteralRange

use of datawave.query.jexl.LiteralRange 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);
}
Also used : DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) QueryException(datawave.webservice.query.exception.QueryException) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) IndexRangeIteratorBuilder(datawave.query.iterator.builder.IndexRangeIteratorBuilder) LiteralRange(datawave.query.jexl.LiteralRange) ASTAndNode(org.apache.commons.jexl2.parser.ASTAndNode)

Example 8 with LiteralRange

use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.

the class ExpandCompositeTerms method visitLeafNode.

/**
 * The default leaf node visitor, which uses the anded nodes to determine whether a composite can be formed with this leaf node.
 *
 * @param node
 *            A leaf node from the original script
 * @param eData
 *            ExpandData, containing ancestor anded nodes, used anded nodes, and a flag indicating whether composites were found
 * @return Returns a composite node if one can be made, otherwise returns the original node
 */
private JexlNode visitLeafNode(JexlNode node, ExpandData eData) {
    LiteralRange range = JexlASTHelper.findRange().getRange(node);
    String fieldName = (range != null) ? range.getFieldName() : JexlASTHelper.getIdentifier(node);
    Multimap<String, JexlNode> leafNodes = LinkedHashMultimap.create();
    leafNodes.put(fieldName, node);
    List<Composite> foundComposites = findComposites(leafNodes, eData.andedNodes, eData.usedAndedNodes);
    JexlNode resultNode = node;
    // if composites were found, create JexlNodes from them
    if (!foundComposites.isEmpty()) {
        List<JexlNode> compositeNodes = createCompositeNodes(foundComposites);
        if (!compositeNodes.isEmpty()) {
            eData.foundComposite = true;
            resultNode = createUnwrappedAndNode(compositeNodes);
        }
    }
    return resultNode;
}
Also used : Composite(datawave.query.composite.Composite) JexlNode(org.apache.commons.jexl2.parser.JexlNode) LiteralRange(datawave.query.jexl.LiteralRange)

Example 9 with LiteralRange

use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.

the class ShardIndexQueryTableStaticMethods method getBoundedRangeRange.

/**
 * Get the accumulo range for a literal query range. Note that it is assumed that the column family set will include the fieldname.
 *
 * @param literalRange
 * @return
 * @throws IllegalRangeArgumentException
 */
public static Range getBoundedRangeRange(LiteralRange<?> literalRange) throws IllegalRangeArgumentException {
    String lower = literalRange.getLower().toString(), upper = literalRange.getUpper().toString();
    Key startKey = new Key(new Text(lower));
    Key endKey = new Key(new Text(literalRange.isUpperInclusive() ? upper + Constants.MAX_UNICODE_STRING : upper));
    Range range = null;
    try {
        range = new Range(startKey, literalRange.isLowerInclusive(), endKey, literalRange.isUpperInclusive());
    } catch (IllegalArgumentException e) {
        QueryException qe = new QueryException(DatawaveErrorCode.RANGE_CREATE_ERROR, e, MessageFormat.format("{0}", literalRange));
        log.debug(qe);
        throw new IllegalRangeArgumentException(qe);
    }
    return range;
}
Also used : DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) DoNotPerformOptimizedQueryException(datawave.query.exceptions.DoNotPerformOptimizedQueryException) QueryException(datawave.webservice.query.exception.QueryException) 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) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) IllegalRangeArgumentException(datawave.query.exceptions.IllegalRangeArgumentException)

Example 10 with LiteralRange

use of datawave.query.jexl.LiteralRange in project datawave by NationalSecurityAgency.

the class EventDataQueryExpressionVisitorTest method testNormalizedValuesMatching.

@Test
public void testNormalizedValuesMatching() {
    ExpressionFilter f = new ExpressionFilter(attrFactory, "FOO");
    f.addFieldValue("BAR");
    f.addFieldPattern("BA[YZ]");
    f.addFieldRange(new LiteralRange("Y", true, "Z", true, "FOO", LiteralRange.NodeOperand.OR));
    f.addFieldRange(new LiteralRange("R", false, "S", false, "FOO", LiteralRange.NodeOperand.OR));
    Key k1 = createKey("FOO", "BaR");
    Key k2 = createKey("FOO", "baz");
    Key k3 = createKey("FOO", "baY");
    Key k4 = createKey("FOO", "y");
    Key k5 = createKey("FOO", "Y");
    Key k6 = createKey("FOO", "yap");
    Key k7 = createKey("FOO", "YAP");
    Key k8 = createKey("FOO", "z");
    Key k9 = createKey("FOO", "Z");
    Key k10 = createKey("FOO", "r");
    Key k11 = createKey("FOO", "R");
    Key k12 = createKey("FOO", "rat");
    Key k13 = createKey("FOO", "RAT");
    Key k14 = createKey("FOO", "s");
    Key k15 = createKey("FOO", "S");
    assertTrue(f.apply(k1));
    assertTrue(f.apply(k2));
    assertTrue(f.apply(k3));
    assertTrue(f.apply(k4));
    assertTrue(f.apply(k5));
    assertTrue(f.apply(k6));
    assertTrue(f.apply(k7));
    assertTrue(f.apply(k8));
    assertTrue(f.apply(k9));
    assertFalse(f.apply(k10));
    assertFalse(f.apply(k11));
    assertTrue(f.apply(k12));
    assertTrue(f.apply(k13));
    assertFalse(f.apply(k14));
    assertFalse(f.apply(k15));
}
Also used : ExpressionFilter(datawave.query.jexl.visitors.EventDataQueryExpressionVisitor.ExpressionFilter) LiteralRange(datawave.query.jexl.LiteralRange) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

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