Search in sources :

Example 1 with JexlNodes.newInstanceOfType

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

the class TreeFlatteningRebuilder method rebuildNode.

/**
 * Returns a copy of the passed in node.
 *
 * If the original node has children, those exact children (not copies) will be added to the copied node. However, the parentage of those child nodes will
 * be left as-is.
 *
 * If the original node has no children, we will simply use the RebuildingVisitor to copy the node.
 *
 * @param node
 *            the node to copy
 * @return the copied node
 */
private JexlNode rebuildNode(JexlNode node) {
    JexlNode newNode;
    if (node.jjtGetNumChildren() == 0) {
        newNode = RebuildingVisitor.copy(node);
    } else {
        newNode = JexlNodes.newInstanceOfType(node);
        newNode.image = node.image;
        JexlNodes.ensureCapacity(newNode, node.jjtGetNumChildren());
        int nodeIdx = 0;
        for (JexlNode child : children(node)) newNode.jjtAddChild(child, nodeIdx++);
    }
    return newNode;
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode)

Example 2 with JexlNodes.newInstanceOfType

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

the class PushdownMissingIndexRangeNodesVisitor method visit.

@Override
public Object visit(ASTAndNode node, Object data) {
    LiteralRange range = JexlASTHelper.findRange().indexedOnly(this.dataTypeFilter, this.helper).notDelayed().getRange(node);
    if (range != null) {
        return delayBoundedIndexHole(range, node, data);
    } else {
        JexlNode andNode = JexlNodes.newInstanceOfType(node);
        andNode.image = node.image;
        andNode.jjtSetParent(node.jjtGetParent());
        // We have no bounded range to replace, just proceed as normal
        JexlNodes.ensureCapacity(andNode, node.jjtGetNumChildren());
        for (int i = 0; i < node.jjtGetNumChildren(); i++) {
            JexlNode newChild = (JexlNode) node.jjtGetChild(i).jjtAccept(this, data);
            andNode.jjtAddChild(newChild, i);
            newChild.jjtSetParent(andNode);
        }
        return andNode;
    }
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) IndexHoleMarkerJexlNode(datawave.query.jexl.nodes.IndexHoleMarkerJexlNode) LiteralRange(datawave.query.jexl.LiteralRange)

Example 3 with JexlNodes.newInstanceOfType

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

the class UniqueExpressionTermsVisitor method removeDuplicateNodes.

private JexlNode removeDuplicateNodes(JexlNode node, Object data) {
    // Traverse each child to de-dupe their children.
    // @formatter:off
    List<JexlNode> visitedChildren = Arrays.stream(children(node)).map(child -> (JexlNode) child.jjtAccept(this, data)).filter(Objects::nonNull).collect(Collectors.toList());
    // @formatter:on
    // Dedupe the visited children.
    List<JexlNode> uniqueChildren = getUniqueChildren(visitedChildren);
    if (uniqueChildren.size() == 1) {
        // If only one child remains, return it.
        return uniqueChildren.get(0);
    } else {
        // If two or more children remain, return a copy with the unique children.
        JexlNode copy = JexlNodes.newInstanceOfType(node);
        copy.image = node.image;
        copy.jjtSetParent(node.jjtGetParent());
        JexlNodes.children(copy, uniqueChildren.toArray(new JexlNode[0]));
        return copy;
    }
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode)

Aggregations

JexlNode (org.apache.commons.jexl2.parser.JexlNode)3 LiteralRange (datawave.query.jexl.LiteralRange)1 IndexHoleMarkerJexlNode (datawave.query.jexl.nodes.IndexHoleMarkerJexlNode)1