Search in sources :

Example 16 with LiteralRange

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);
    }
}
Also used : DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) JavaRegexParseException(datawave.query.parser.JavaRegexAnalyzer.JavaRegexParseException) JavaRegexAnalyzer(datawave.query.parser.JavaRegexAnalyzer) LiteralRange(datawave.query.jexl.LiteralRange) NoSuchElementException(java.util.NoSuchElementException)

Example 17 with LiteralRange

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);
}
Also used : Path(org.apache.hadoop.fs.Path) FST(org.apache.lucene.util.fst.FST) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) LiteralRange(datawave.query.jexl.LiteralRange) Range(org.apache.accumulo.core.data.Range) IvaratorBuilder(datawave.query.iterator.builder.IvaratorBuilder) URI(java.net.URI) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) QueryException(datawave.webservice.query.exception.QueryException) TreeSet(java.util.TreeSet) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) ExceededOrThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode) IndexListIteratorBuilder(datawave.query.iterator.builder.IndexListIteratorBuilder) IndexRangeIteratorBuilder(datawave.query.iterator.builder.IndexRangeIteratorBuilder) LiteralRange(datawave.query.jexl.LiteralRange)

Example 18 with LiteralRange

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);
    }
}
Also used : DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) JavaRegexParseException(datawave.query.parser.JavaRegexAnalyzer.JavaRegexParseException) JavaRegexAnalyzer(datawave.query.parser.JavaRegexAnalyzer) LiteralRange(datawave.query.jexl.LiteralRange) NoSuchElementException(java.util.NoSuchElementException)

Example 19 with LiteralRange

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

Example 20 with LiteralRange

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

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