Search in sources :

Example 1 with JexlNode

use of org.apache.commons.jexl3.parser.JexlNode in project datawave by NationalSecurityAgency.

the class CompositeRange method addComponent.

@Override
public void addComponent(JexlNode node) {
    List<JexlNode> nodes = new ArrayList<>();
    LiteralRange range = JexlASTHelper.findRange().getRange(node);
    if (range != null) {
        nodes.add(range.getLowerNode());
        nodes.add(range.getUpperNode());
    } else if (node instanceof ASTEQNode) {
        String fieldName = JexlASTHelper.getIdentifier(node);
        String expression = JexlASTHelper.getLiteralValue(node).toString();
        nodes.add(JexlNodeFactory.buildNode((ASTGENode) null, fieldName, expression));
        nodes.add(JexlNodeFactory.buildNode((ASTLENode) null, fieldName, expression));
    } else {
        nodes.add(node);
    }
    jexlNodeList.add(node);
    fieldNameList.add(JexlASTHelper.getIdentifier(nodes.get(0)));
    for (JexlNode boundNode : nodes) {
        String expression = JexlASTHelper.getLiteralValue(boundNode).toString();
        if (boundNode instanceof ASTGENode || boundNode instanceof ASTGTNode) {
            jexlNodeListLowerBound.add(boundNode);
            expressionListLowerBound.add(expression);
            if (nodes.size() < 2) {
                jexlNodeListUpperBound.add(null);
                expressionListUpperBound.add(null);
            }
        } else if (boundNode instanceof ASTLENode || boundNode instanceof ASTLTNode) {
            jexlNodeListUpperBound.add(boundNode);
            expressionListUpperBound.add(expression);
            if (nodes.size() < 2) {
                jexlNodeListLowerBound.add(null);
                expressionListLowerBound.add(null);
            }
        }
    }
}
Also used : ASTLENode(org.apache.commons.jexl2.parser.ASTLENode) ASTGENode(org.apache.commons.jexl2.parser.ASTGENode) ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) ArrayList(java.util.ArrayList) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ASTGTNode(org.apache.commons.jexl2.parser.ASTGTNode) LiteralRange(datawave.query.jexl.LiteralRange) ASTLTNode(org.apache.commons.jexl2.parser.ASTLTNode)

Example 2 with JexlNode

use of org.apache.commons.jexl3.parser.JexlNode in project datawave by NationalSecurityAgency.

the class CompositeRange method getUpperBoundExpression.

private String getUpperBoundExpression(Map<String, DiscreteIndexType<?>> discreteIndexTypeMap) {
    StringBuilder buf = new StringBuilder();
    boolean lastNode = false;
    for (int i = 0; i < expressionListUpperBound.size(); i++) {
        String expression = expressionListUpperBound.get(i);
        JexlNode node = jexlNodeListUpperBound.get(i);
        if (expression != null && node != null) {
            if (i != (expressionListUpperBound.size() - 1)) {
                // Convert LE node to LT node if it is the last valid node in the list
                if (node instanceof ASTLENode && expressionListUpperBound.get(i + 1) == null) {
                    String exclusiveUpperBound = CompositeUtils.getExclusiveUpperBound(expression, discreteIndexTypeMap.get(fieldNameList.get(i)));
                    // bound, and signal that this is the last expression
                    if (exclusiveUpperBound.length() != expression.length())
                        lastNode = true;
                    else
                        expression = exclusiveUpperBound;
                } else // Convert LT nodes to inclusive LE nodes if they are not the last valid node in the list
                if (node instanceof ASTLTNode && expressionListUpperBound.get(i + 1) != null) {
                    String inclusiveUpperBound = CompositeUtils.getInclusiveUpperBound(expression, discreteIndexTypeMap.get(fieldNameList.get(i)));
                    // bound, and signal that this is the last expression
                    if (inclusiveUpperBound.length() != expression.length())
                        lastNode = true;
                    else
                        expression = inclusiveUpperBound;
                }
            }
            if (i > 0)
                buf.append(separator);
            buf.append(expression);
        } else {
            break;
        }
        if (lastNode)
            break;
    }
    return buf.toString();
}
Also used : ASTLENode(org.apache.commons.jexl2.parser.ASTLENode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ASTLTNode(org.apache.commons.jexl2.parser.ASTLTNode)

Example 3 with JexlNode

use of org.apache.commons.jexl3.parser.JexlNode in project datawave by NationalSecurityAgency.

the class IndexInfo method applyNode.

public void applyNode(JexlNode node) {
    JexlNode copy = RebuildingVisitor.copy(node);
    copy.jjtSetParent(null);
    myNode = copy;
    for (IndexMatch match : uids) {
        match.add(node);
    }
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) ExceededTermThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode) ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) ExceededOrThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode) IndexHoleMarkerJexlNode(datawave.query.jexl.nodes.IndexHoleMarkerJexlNode)

Example 4 with JexlNode

use of org.apache.commons.jexl3.parser.JexlNode in project datawave by NationalSecurityAgency.

the class IndexInfo method buildNodeList.

protected Set<IndexMatch> buildNodeList(HashMultimap<String, JexlNode> ids, IndexMatchType type, boolean allowsDelayed, List<JexlNode> delayedNodes) {
    Set<IndexMatch> matches = Sets.newHashSet();
    for (String uid : ids.keySet()) {
        Set<JexlNode> nodes = ids.get(uid);
        // make sure that we have nodes, otherwise we are pruned to nothing
        if (nodes.size() > 1 || (allowsDelayed && (nodes.size() + delayedNodes.size()) > 1)) {
            JexlNodeSet nodeSet = new JexlNodeSet();
            nodeSet.addAll(nodes);
            nodeSet.addAll(delayedNodes);
            IndexMatch currentMatch = new IndexMatch(Sets.newHashSet(nodeSet.getNodes()), uid, type);
            matches.add(currentMatch);
        }
    }
    return matches;
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) ExceededTermThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode) ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) ExceededOrThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode) IndexHoleMarkerJexlNode(datawave.query.jexl.nodes.IndexHoleMarkerJexlNode) JexlNodeSet(datawave.query.language.parser.jexl.JexlNodeSet)

Example 5 with JexlNode

use of org.apache.commons.jexl3.parser.JexlNode in project datawave by NationalSecurityAgency.

the class ExecutableDeterminationVisitor method getState.

public static STATE getState(JexlNode node, ShardQueryConfiguration config, MetadataHelper helper, boolean forFieldIndex, List<String> debugOutput) {
    ExecutableDeterminationVisitor visitor = new ExecutableDeterminationVisitor(config, helper, forFieldIndex, debugOutput);
    // push down any negations to ensure the state is accurate
    JexlNode pushedDownTree = PushdownNegationVisitor.pushdownNegations(node);
    return (STATE) pushedDownTree.jjtAccept(visitor, "");
}
Also used : ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) ExceededOrThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode) IndexHoleMarkerJexlNode(datawave.query.jexl.nodes.IndexHoleMarkerJexlNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ExceededTermThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode)

Aggregations

JexlNode (org.apache.commons.jexl2.parser.JexlNode)327 Test (org.junit.Test)124 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)63 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)56 ArrayList (java.util.ArrayList)50 JexlNode (org.apache.commons.jexl3.parser.JexlNode)38 ExceededTermThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode)34 ASTAndNode (org.apache.commons.jexl2.parser.ASTAndNode)33 ASTOrNode (org.apache.commons.jexl2.parser.ASTOrNode)28 ExceededOrThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode)25 ASTEQNode (org.apache.commons.jexl2.parser.ASTEQNode)25 JexlException (org.apache.commons.jexl3.JexlException)24 HashSet (java.util.HashSet)22 ASTReference (org.apache.commons.jexl2.parser.ASTReference)19 ASTIdentifier (org.apache.commons.jexl2.parser.ASTIdentifier)18 ASTReferenceExpression (org.apache.commons.jexl2.parser.ASTReferenceExpression)16 IndexHoleMarkerJexlNode (datawave.query.jexl.nodes.IndexHoleMarkerJexlNode)15 ASTFunctionNode (org.apache.commons.jexl2.parser.ASTFunctionNode)15 ASTERNode (org.apache.commons.jexl2.parser.ASTERNode)14 JexlArgumentDescriptor (datawave.query.jexl.functions.arguments.JexlArgumentDescriptor)12