Search in sources :

Example 21 with LiteralRange

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

the class TLDIndexBuildingVisitor method getFiRangeForTF.

/**
 * Range should be build to encompass the entire TLD
 *
 * @param range
 *            non-null literal range to generate an FI range from
 * @return
 */
@Override
protected Range getFiRangeForTF(LiteralRange<?> range) {
    Key startKey = rangeLimiter.getStartKey();
    StringBuilder strBuilder = new StringBuilder("fi");
    strBuilder.append(NULL_DELIMETER).append(range.getFieldName());
    Text cf = new Text(strBuilder.toString());
    strBuilder = new StringBuilder(range.getLower().toString());
    strBuilder.append(NULL_DELIMETER).append(startKey.getColumnFamily());
    Text cq = new Text(strBuilder.toString());
    Key seekBeginKey = new Key(startKey.getRow(), cf, cq, startKey.getTimestamp());
    strBuilder = new StringBuilder(range.getUpper().toString());
    strBuilder.append(NULL_DELIMETER).append(startKey.getColumnFamily() + Constants.MAX_UNICODE_STRING);
    cq = new Text(strBuilder.toString());
    Key seekEndKey = new Key(startKey.getRow(), cf, cq, startKey.getTimestamp());
    return new Range(seekBeginKey, true, seekEndKey, true);
}
Also used : Text(org.apache.hadoop.io.Text) LiteralRange(datawave.query.jexl.LiteralRange) Range(org.apache.accumulo.core.data.Range) DatawaveKey(datawave.query.data.parsers.DatawaveKey) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 22 with LiteralRange

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

the class WhindexVisitor 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 : JexlNodes.children(rootNode)) {
            JexlNode leafKid = getLeafNode(child);
            if (leafKid != null) {
                Set<String> kidFieldNames = new LinkedHashSet<>();
                LiteralRange range = JexlASTHelper.findRange().getRange(leafKid);
                if (range != null) {
                    kidFieldNames.add(range.getFieldName());
                } else {
                    if (leafKid instanceof ASTEQNode) {
                        kidFieldNames.add(JexlASTHelper.getIdentifier(leafKid));
                    } else if (leafKid instanceof ASTFunctionNode) {
                        JexlArgumentDescriptor descriptor = JexlFunctionArgumentDescriptorFactory.F.getArgumentDescriptor((ASTFunctionNode) leafKid);
                        if (descriptor instanceof GeoWaveFunctionsDescriptor.GeoWaveJexlArgumentDescriptor || descriptor instanceof GeoFunctionsDescriptor.GeoJexlArgumentDescriptor) {
                            kidFieldNames.addAll(descriptor.fields(metadataHelper, Collections.emptySet()));
                        } else {
                            if (otherNodes != null) {
                                otherNodes.add(child);
                            }
                        }
                    }
                }
                for (String kidFieldName : kidFieldNames) {
                    // 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 : LinkedHashSet(java.util.LinkedHashSet) ASTFunctionNode(org.apache.commons.jexl2.parser.ASTFunctionNode) ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) JexlArgumentDescriptor(datawave.query.jexl.functions.arguments.JexlArgumentDescriptor) LiteralRange(datawave.query.jexl.LiteralRange) ASTAndNode(org.apache.commons.jexl2.parser.ASTAndNode)

Example 23 with LiteralRange

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

the class BoundedRangeDetectionVisitor method visit.

@Override
public Object visit(ASTReference node, Object data) {
    if (QueryPropertyMarker.findInstance(node).isType(BoundedRange.class)) {
        LiteralRange range = JexlASTHelper.findRange().getRange(node);
        try {
            if (helper.getNonEventFields(config.getDatatypeFilter()).contains(range.getFieldName())) {
                if (null != data) {
                    AtomicBoolean hasBounded = (AtomicBoolean) data;
                    hasBounded.set(true);
                }
            }
        } catch (TableNotFoundException e) {
            throw new DatawaveFatalQueryException("Cannot access metadata", e);
        }
        return false;
    } else {
        return super.visit(node, data);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) 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