Search in sources :

Example 1 with JexlNodes

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

the class ExecutableExpansionVisitor method bridge.

/**
 * bridge the gap between an orNode child and the expansion andNode so as to maintain tree continuity
 *
 * @param bridgeTo
 *            the node to attach to the leaf of the bridge
 * @param bridgeFrom
 *            the node to begin bridging from, may be null to prevent bridging
 * @return a JexlNode tree fragment representing a bridge of JexlNodes from bridgeFrom to bridgeTo, or bridgeTo if bridgeFrom is null
 */
private JexlNode bridge(JexlNode bridgeTo, JexlNode bridgeFrom) {
    JexlNode bridge = bridgeTo;
    if (bridgeFrom != null) {
        // make a copy of the extended region of the tree and add the orChild in bypassing the orNode
        bridge = RebuildingVisitor.copy(bridgeFrom);
        // loop down through the copied extension until we get to the leaf
        JexlNode current = bridge.jjtGetChild(0);
        while (current != null && current.jjtGetNumChildren() != 0) {
            current = current.jjtGetChild(0);
        }
        // sanity check
        if (current == null) {
            log.error("Unexpected bridge format between andNode and orNode");
            return null;
        }
        // attach the oldOr to the end of the extension
        bridgeTo.jjtSetParent(current);
        current.jjtAddChild(bridgeTo, 0);
    }
    return bridge;
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode)

Example 2 with JexlNodes

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

the class WhindexVisitor method visitLeafNode.

/**
 * The default leaf node visitor, which uses the anded nodes to determine whether a whindex can be formed with this leaf node.
 *
 * @param node
 *            A leaf node from the original script
 * @param eData
 *            ExpandData, containing ancestor anded nodes, used anded nodes, and a flag indicating whether whindexes were found
 * @return Returns a whindex node if one can be made, otherwise returns the original node
 */
private JexlNode visitLeafNode(JexlNode node, ExpandData eData) {
    Set<String> fieldNames = new HashSet<>();
    JexlASTHelper.getIdentifiers(node).forEach(x -> fieldNames.add(JexlASTHelper.getIdentifier(x)));
    JexlNode resultNode = node;
    if (fieldNames.size() == 1) {
        String fieldName = Iterables.getOnlyElement(fieldNames);
        Multimap<String, JexlNode> leafNodes = LinkedHashMultimap.create();
        leafNodes.put(fieldName, node);
        List<WhindexTerm> foundWhindexes = findWhindex(leafNodes, eData.andedNodes, HashMultimap.create(), eData.usedAndedNodes);
        // if whindexes were found, create JexlNodes from them
        if (!foundWhindexes.isEmpty()) {
            List<JexlNode> whindexNodes = new ArrayList<>();
            for (WhindexTerm whindexTerm : foundWhindexes) {
                JexlNode whindexNode = whindexTerm.createWhindexNode();
                whindexNodes.add(whindexNode);
                jexlNodeToWhindexMap.put(JexlASTHelper.dereference(whindexNode), whindexTerm);
            }
            if (!whindexNodes.isEmpty()) {
                eData.foundWhindex = true;
                resultNode = createUnwrappedAndNode(whindexNodes);
            }
        }
    }
    return resultNode;
}
Also used : ArrayList(java.util.ArrayList) ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with JexlNodes

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

the class ExpandCompositeTerms method visitLeafNode.

/**
 * The default leaf node visitor, which uses the anded nodes to determine whether a composite can be formed with this leaf node.
 *
 * @param node
 *            A leaf node from the original script
 * @param eData
 *            ExpandData, containing ancestor anded nodes, used anded nodes, and a flag indicating whether composites were found
 * @return Returns a composite node if one can be made, otherwise returns the original node
 */
private JexlNode visitLeafNode(JexlNode node, ExpandData eData) {
    LiteralRange range = JexlASTHelper.findRange().getRange(node);
    String fieldName = (range != null) ? range.getFieldName() : JexlASTHelper.getIdentifier(node);
    Multimap<String, JexlNode> leafNodes = LinkedHashMultimap.create();
    leafNodes.put(fieldName, node);
    List<Composite> foundComposites = findComposites(leafNodes, eData.andedNodes, eData.usedAndedNodes);
    JexlNode resultNode = node;
    // if composites were found, create JexlNodes from them
    if (!foundComposites.isEmpty()) {
        List<JexlNode> compositeNodes = createCompositeNodes(foundComposites);
        if (!compositeNodes.isEmpty()) {
            eData.foundComposite = true;
            resultNode = createUnwrappedAndNode(compositeNodes);
        }
    }
    return resultNode;
}
Also used : Composite(datawave.query.composite.Composite) JexlNode(org.apache.commons.jexl2.parser.JexlNode) LiteralRange(datawave.query.jexl.LiteralRange)

Example 4 with JexlNodes

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

the class JexlNodeFactory method wrapChildren.

/**
 * Add the children JexlNodes to the parent JexlNode, correctly setting parent pointers, parenthesis, and reference nodes.
 *
 * @param parent
 * @param children
 * @return
 */
public static JexlNode wrapChildren(JexlNode parent, Iterable<? extends JexlNode> children) {
    parent = setChildren(parent, children);
    JexlNode grandParent = parent.jjtGetParent();
    // If we have more than one element in the new node, wrap it in
    // parentheses
    JexlNode wrapped = wrap(parent);
    // Set the parent pointer
    wrapped.jjtSetParent(grandParent);
    return wrapped;
}
Also used : ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ExceededTermThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode)

Example 5 with JexlNodes

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

the class JexlNodeFactory method setChildren.

/**
 * Add the children JexlNodes to the parent JexlNode, correctly setting parent pointers, parenthesis, and reference nodes.
 *
 * @param parent
 * @param children
 * @return
 */
public static JexlNode setChildren(JexlNode parent, Iterable<? extends JexlNode> children) {
    int i = 0;
    // hopefully
    JexlNodes.ensureCapacity(parent, Iterables.size(children));
    // collection...
    for (JexlNode child : children) {
        parent.jjtAddChild(child, i);
        child.jjtSetParent(parent);
        i++;
    }
    return parent;
}
Also used : ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ExceededTermThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode)

Aggregations

JexlNode (org.apache.commons.jexl2.parser.JexlNode)5 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)3 ExceededTermThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode)2 Composite (datawave.query.composite.Composite)1 LiteralRange (datawave.query.jexl.LiteralRange)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1