Search in sources :

Example 6 with ASTLTNode

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

the class JexlNodeFactory method buildNullNode.

public static JexlNode buildNullNode(JexlNode original, ASTIdentifier identifier) {
    JexlNode copy;
    if (original instanceof ASTEQNode) {
        copy = new ASTEQNode(ParserTreeConstants.JJTEQNODE);
    } else if (original instanceof ASTNENode) {
        copy = new ASTNENode(ParserTreeConstants.JJTNENODE);
    } else if (original instanceof ASTERNode) {
        copy = new ASTERNode(ParserTreeConstants.JJTERNODE);
    } else if (original instanceof ASTNRNode) {
        copy = new ASTNRNode(ParserTreeConstants.JJTNRNODE);
    } else if (original instanceof ASTGTNode) {
        copy = new ASTGTNode(ParserTreeConstants.JJTGTNODE);
    } else if (original instanceof ASTGENode) {
        copy = new ASTGENode(ParserTreeConstants.JJTGENODE);
    } else if (original instanceof ASTLTNode) {
        copy = new ASTLTNode(ParserTreeConstants.JJTLTNODE);
    } else if (original instanceof ASTLENode) {
        copy = new ASTLENode(ParserTreeConstants.JJTLENODE);
    } else {
        throw new UnsupportedOperationException("Cannot handle " + original);
    }
    copy.jjtSetParent(original.jjtGetParent());
    ASTNullLiteral literalNode = new ASTNullLiteral(ParserTreeConstants.JJTNULLLITERAL);
    return buildUntypedNewLiteralNode(copy, identifier, literalNode);
}
Also used : ASTNENode(org.apache.commons.jexl2.parser.ASTNENode) ASTLENode(org.apache.commons.jexl2.parser.ASTLENode) ASTGENode(org.apache.commons.jexl2.parser.ASTGENode) ASTERNode(org.apache.commons.jexl2.parser.ASTERNode) ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) ASTNRNode(org.apache.commons.jexl2.parser.ASTNRNode) ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ExceededTermThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode) ASTGTNode(org.apache.commons.jexl2.parser.ASTGTNode) ASTNullLiteral(org.apache.commons.jexl2.parser.ASTNullLiteral) ASTLTNode(org.apache.commons.jexl2.parser.ASTLTNode)

Example 7 with ASTLTNode

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

the class CompositeRange method isValid.

// this composite range is invalid if
// - it doesn't contain any nodes, or they are all null
// - it contains an invalid leaf node, or doesn't contain a valid leaf node
// - it contains a regex node
// - it represents an unbounded range (i.e. contains all GT/GE nodes, or all LT/LE nodes)
// - there are gaps in the upper or lower bound
@Override
public boolean isValid() {
    // if we have no nodes, or they are all null
    if (jexlNodeList.isEmpty() || jexlNodeList.stream().allMatch(Objects::isNull) || jexlNodeListLowerBound.stream().allMatch(Objects::isNull) || jexlNodeListUpperBound.stream().allMatch(Objects::isNull))
        return false;
    boolean allGTOrGENodes = true;
    boolean allLTOrLENodes = true;
    for (JexlNode node : jexlNodeList) {
        Class nodeClass = node.getClass();
        // if this is an invalid leaf node, or not a valid leaf node, we're done
        if (INVALID_LEAF_NODE_CLASSES.contains(nodeClass) || !VALID_LEAF_NODE_CLASSES.contains(nodeClass))
            return false;
        // regex and not equals nodes are not allowed in a bounded range
        if (node instanceof ASTERNode || node instanceof ASTNENode)
            return false;
        // keeping track of whether all the nodes are GT or GE
        if (!(node instanceof ASTGTNode || node instanceof ASTGENode))
            allGTOrGENodes = false;
        // keeping track of whether all the nodes are LT or LE
        if (!(node instanceof ASTLTNode || node instanceof ASTLENode))
            allLTOrLENodes = false;
    }
    // there's no value in creating composites for unbounded ranges
    if (allGTOrGENodes || allLTOrLENodes)
        return false;
    // look for gaps in the lower bound. trailing nulls are ok, but nulls followed by non-nulls are not
    boolean hasNullNode = false;
    for (JexlNode lowerNode : jexlNodeListLowerBound) {
        if (hasNullNode && lowerNode != null)
            return false;
        hasNullNode = hasNullNode || lowerNode == null;
    }
    // look for gaps in the upper bound. trailing nulls are ok, but nulls followed by non-nulls are not
    hasNullNode = false;
    for (JexlNode upperNode : jexlNodeListUpperBound) {
        if (hasNullNode && upperNode != null)
            return false;
        hasNullNode = hasNullNode || upperNode == null;
    }
    return true;
}
Also used : ASTNENode(org.apache.commons.jexl2.parser.ASTNENode) ASTLENode(org.apache.commons.jexl2.parser.ASTLENode) ASTGENode(org.apache.commons.jexl2.parser.ASTGENode) ASTERNode(org.apache.commons.jexl2.parser.ASTERNode) Objects(java.util.Objects) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ASTGTNode(org.apache.commons.jexl2.parser.ASTGTNode) ASTLTNode(org.apache.commons.jexl2.parser.ASTLTNode)

Example 8 with ASTLTNode

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

the class DatawaveInterpreter method evaluateRange.

/**
 * * This will determine if this ANDNode contains a range, and will invoke the appropriate range function instead of evaluating the LT/LE and GT/GE nodes *
 * independently as that does not work when there are sets of values in the context. * * @param node * @return a collection of hits (or empty set) if we
 * evaluated a range. null otherwise.
 */
private Collection<?> evaluateRange(ASTAndNode node) {
    Collection<?> evaluation = null;
    LiteralRange range = JexlASTHelper.findRange().getRange(node);
    if (range != null) {
        JexlNode left = range.getLowerNode();
        JexlNode right = range.getUpperNode();
        if (left instanceof ASTLENode || left instanceof ASTLTNode) {
            JexlNode temp = left;
            left = right;
            right = temp;
        }
        if ((left instanceof ASTGENode || left instanceof ASTGTNode) && (right instanceof ASTLENode || right instanceof ASTLTNode)) {
            JexlNode leftIdentifier = dereference(left.jjtGetChild(0));
            JexlNode rightIdentifier = dereference(right.jjtGetChild(0));
            if (leftIdentifier instanceof ASTIdentifier && rightIdentifier instanceof ASTIdentifier) {
                String fieldName = leftIdentifier.image;
                if (fieldName.equals(rightIdentifier.image)) {
                    Object fieldValue = leftIdentifier.jjtAccept(this, null);
                    Object leftValue = left.jjtGetChild(1).jjtAccept(this, null);
                    boolean leftInclusive = left instanceof ASTGENode;
                    Object rightValue = right.jjtGetChild(1).jjtAccept(this, null);
                    boolean rightInclusive = right instanceof ASTLENode;
                    if (leftValue instanceof Number && rightValue instanceof Number) {
                        if (fieldValue instanceof Collection) {
                            evaluation = QueryFunctions.between((Collection) fieldValue, ((Number) leftValue).floatValue(), leftInclusive, ((Number) rightValue).floatValue(), rightInclusive);
                        } else {
                            evaluation = QueryFunctions.between(fieldValue, ((Number) leftValue).floatValue(), leftInclusive, ((Number) rightValue).floatValue(), rightInclusive);
                        }
                    } else {
                        if (fieldValue instanceof Collection) {
                            evaluation = QueryFunctions.between((Collection) fieldValue, String.valueOf(leftValue), leftInclusive, String.valueOf(rightValue), rightInclusive);
                        } else {
                            evaluation = QueryFunctions.between(fieldValue, String.valueOf(leftValue), leftInclusive, String.valueOf(rightValue), rightInclusive);
                        }
                    }
                    addHits(fieldValue);
                }
            }
        }
    }
    return evaluation;
}
Also used : ASTGENode(org.apache.commons.jexl2.parser.ASTGENode) ASTIdentifier(org.apache.commons.jexl2.parser.ASTIdentifier) ASTGTNode(org.apache.commons.jexl2.parser.ASTGTNode) ASTLTNode(org.apache.commons.jexl2.parser.ASTLTNode) ASTLENode(org.apache.commons.jexl2.parser.ASTLENode) ExceededOrThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) Collection(java.util.Collection)

Example 9 with ASTLTNode

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

the class JexlNodeFactory method buildBooleanNode.

public static JexlNode buildBooleanNode(JexlNode original, ASTIdentifier identifier, Boolean literal) {
    JexlNode copy;
    if (original instanceof ASTEQNode) {
        copy = new ASTEQNode(ParserTreeConstants.JJTEQNODE);
    } else if (original instanceof ASTNENode) {
        copy = new ASTNENode(ParserTreeConstants.JJTNENODE);
    } else if (original instanceof ASTERNode) {
        copy = new ASTERNode(ParserTreeConstants.JJTERNODE);
    } else if (original instanceof ASTNRNode) {
        copy = new ASTNRNode(ParserTreeConstants.JJTNRNODE);
    } else if (original instanceof ASTGTNode) {
        copy = new ASTGTNode(ParserTreeConstants.JJTGTNODE);
    } else if (original instanceof ASTGENode) {
        copy = new ASTGENode(ParserTreeConstants.JJTGENODE);
    } else if (original instanceof ASTLTNode) {
        copy = new ASTLTNode(ParserTreeConstants.JJTLTNODE);
    } else if (original instanceof ASTLENode) {
        copy = new ASTLENode(ParserTreeConstants.JJTLENODE);
    } else {
        throw new UnsupportedOperationException("Cannot handle " + original);
    }
    copy.jjtSetParent(original.jjtGetParent());
    JexlNode literalNode;
    if (literal) {
        literalNode = new ASTTrueNode(ParserTreeConstants.JJTTRUENODE);
    } else {
        literalNode = new ASTFalseNode(ParserTreeConstants.JJTFALSENODE);
    }
    return buildUntypedNewLiteralNode(copy, identifier, literalNode);
}
Also used : ASTNENode(org.apache.commons.jexl2.parser.ASTNENode) ASTLENode(org.apache.commons.jexl2.parser.ASTLENode) ASTGENode(org.apache.commons.jexl2.parser.ASTGENode) ASTERNode(org.apache.commons.jexl2.parser.ASTERNode) ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) ASTFalseNode(org.apache.commons.jexl2.parser.ASTFalseNode) ASTNRNode(org.apache.commons.jexl2.parser.ASTNRNode) ASTTrueNode(org.apache.commons.jexl2.parser.ASTTrueNode) ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ExceededTermThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode) ASTGTNode(org.apache.commons.jexl2.parser.ASTGTNode) ASTLTNode(org.apache.commons.jexl2.parser.ASTLTNode)

Aggregations

ASTLENode (org.apache.commons.jexl2.parser.ASTLENode)9 ASTLTNode (org.apache.commons.jexl2.parser.ASTLTNode)9 JexlNode (org.apache.commons.jexl2.parser.JexlNode)9 ASTGENode (org.apache.commons.jexl2.parser.ASTGENode)8 ASTGTNode (org.apache.commons.jexl2.parser.ASTGTNode)8 ASTEQNode (org.apache.commons.jexl2.parser.ASTEQNode)5 ASTERNode (org.apache.commons.jexl2.parser.ASTERNode)5 ASTNENode (org.apache.commons.jexl2.parser.ASTNENode)5 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)4 ASTNRNode (org.apache.commons.jexl2.parser.ASTNRNode)4 ExceededTermThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode)3 ASTAndNode (org.apache.commons.jexl2.parser.ASTAndNode)3 LiteralRange (datawave.query.jexl.LiteralRange)2 QueryPropertyMarker (datawave.query.jexl.nodes.QueryPropertyMarker)2 ArrayList (java.util.ArrayList)2 ASTFunctionNode (org.apache.commons.jexl2.parser.ASTFunctionNode)2 ASTNotNode (org.apache.commons.jexl2.parser.ASTNotNode)2 ASTNullLiteral (org.apache.commons.jexl2.parser.ASTNullLiteral)2 ASTOrNode (org.apache.commons.jexl2.parser.ASTOrNode)2 ASTReference (org.apache.commons.jexl2.parser.ASTReference)2