Search in sources :

Example 1 with Node

use of org.apache.commons.jexl2.parser.Node 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 Node

use of org.apache.commons.jexl2.parser.Node 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 Node

use of org.apache.commons.jexl2.parser.Node 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 Node

use of org.apache.commons.jexl2.parser.Node 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)

Example 5 with Node

use of org.apache.commons.jexl2.parser.Node in project datawave by NationalSecurityAgency.

the class ExecutableExpansionVisitor method canExpand.

/**
 * Test if the current node should be expanded by this visitor. Update the tracker with the current andChild if expansion is possible
 *
 * @param node
 *            the node to test
 * @param tracker
 *            the tracker holding supplementary information about the expansion
 * @return true if the expansion should occur, false otherwise
 */
private boolean canExpand(JexlNode node, ExecutableDeterminationVisitor.STATE state, ExpansionTracker tracker) {
    // only process if state is ERROR or PARTIAL
    if (!(state == ExecutableDeterminationVisitor.STATE.ERROR || state == ExecutableDeterminationVisitor.STATE.PARTIAL)) {
        return false;
    }
    // if deeper down in the tree there was a failed expansion attempt, don't try again
    if (tracker.isFailedExpansion()) {
        return false;
    }
    // there must be an andNode further up the tree to distribute into the or
    ASTAndNode lastAnd = tracker.getLastAnd();
    // as long as there is a lastAnd there is work to do
    if (lastAnd == null) {
        return false;
    }
    // verify there is nothing but compatible nodes between the andNode and the orNode
    JexlNode current = node.jjtGetParent();
    JexlNode last = node;
    while (current != lastAnd) {
        if (!(current instanceof ASTReference || current instanceof ASTReferenceExpression)) {
            return false;
        }
        last = current;
        current = current.jjtGetParent();
    }
    // if we got here the expansion is good and we should track the andChild for later use
    tracker.setAndChild(last);
    return true;
}
Also used : ASTReferenceExpression(org.apache.commons.jexl2.parser.ASTReferenceExpression) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ASTReference(org.apache.commons.jexl2.parser.ASTReference) ASTAndNode(org.apache.commons.jexl2.parser.ASTAndNode)

Aggregations

JexlNode (org.apache.commons.jexl2.parser.JexlNode)213 Test (org.junit.Test)59 ArrayList (java.util.ArrayList)46 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)44 ASTAndNode (org.apache.commons.jexl2.parser.ASTAndNode)35 ASTOrNode (org.apache.commons.jexl2.parser.ASTOrNode)29 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)27 ExceededTermThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode)26 HashSet (java.util.HashSet)23 ExceededOrThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode)22 ASTEQNode (org.apache.commons.jexl2.parser.ASTEQNode)22 ASTReference (org.apache.commons.jexl2.parser.ASTReference)20 ASTIdentifier (org.apache.commons.jexl2.parser.ASTIdentifier)19 ASTReferenceExpression (org.apache.commons.jexl2.parser.ASTReferenceExpression)17 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)16 QueryException (datawave.webservice.query.exception.QueryException)13 List (java.util.List)13 ASTFunctionNode (org.apache.commons.jexl2.parser.ASTFunctionNode)13 LiteralRange (datawave.query.jexl.LiteralRange)12 JexlArgumentDescriptor (datawave.query.jexl.functions.arguments.JexlArgumentDescriptor)11