Search in sources :

Example 51 with JexlNode

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

the class JexlASTHelperTest method parse1LeadingBackslashRegex.

@Test
public void parse1LeadingBackslashRegex() throws Exception {
    String query = "CITY =~ '\\\\city'";
    JexlNode node = JexlASTHelper.parseJexlQuery(query);
    String interpretedQuery = JexlStringBuildingVisitor.buildQuery(node);
    Assert.assertEquals(query, interpretedQuery);
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 52 with JexlNode

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

the class JexlASTHelperTest method parse3TrailingBackslashesRegex.

@Test
public void parse3TrailingBackslashesRegex() throws Exception {
    String query = "CITY =~ 'city\\\\\\\\\\\\'";
    JexlNode node = JexlASTHelper.parseJexlQuery(query);
    String interpretedQuery = JexlStringBuildingVisitor.buildQuery(node);
    Assert.assertEquals(query, interpretedQuery);
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 53 with JexlNode

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

the class JexlASTHelperTest method transitiveRegexParseTest.

// This test is here to ensure that we can freely convert between a jexl tree and
// a query string, without impact to the string literal for the regex node.
// WEB QUERY: CITY =~ 'ci\\\\\\ty\.blah'
// StringLiteral.image: "ci\\\\\\ty\.blah"
@Test
public void transitiveRegexParseTest() throws Exception {
    String query = "CITY =~ 'ci\\\\\\\\\\\\ty\\.blah'";
    JexlNode node = JexlASTHelper.parseJexlQuery(query);
    String interpretedQuery = JexlStringBuildingVisitor.buildQuery(node);
    JexlNode newNode = JexlASTHelper.parseJexlQuery(interpretedQuery);
    String reinterpretedQuery = JexlStringBuildingVisitor.buildQuery(newNode);
    Assert.assertEquals("CITY =~ 'ci\\\\\\\\\\\\ty\\.blah'", interpretedQuery);
    Assert.assertEquals(reinterpretedQuery, interpretedQuery);
    Assert.assertEquals("ci\\\\\\\\\\\\ty\\.blah", node.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0).image);
    Assert.assertEquals(node.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0).image, newNode.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0).image);
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 54 with JexlNode

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

the class PushdownNegationVisitor method visit.

@Override
public Object visit(ASTNRNode node, Object data) {
    if (data instanceof NegationState) {
        NegationState state = (NegationState) data;
        if (state.isNegated()) {
            // replace this node with an ER node
            JexlNode eqNode = JexlNodeFactory.buildERNode(JexlASTHelper.getIdentifier(node), JexlASTHelper.getLiteral(node).image);
            JexlNodes.swap(node.jjtGetParent(), node, eqNode);
            state.setNegated(false);
            return state;
        }
    }
    // keep going
    return super.visit(node, data);
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode)

Example 55 with JexlNode

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

the class PushdownNegationVisitor method pushdownNegations.

/**
 * Create a copy of the tree and flatten it, then pushdown all negations
 *
 * @param tree
 *            the original tree
 * @return the modified tree with all negations pushed down
 */
public static JexlNode pushdownNegations(JexlNode tree) {
    // flatten the input
    JexlNode flattened = TreeFlatteningRebuildingVisitor.flatten(tree);
    flattened.jjtAccept(new PushdownNegationVisitor(), new NegationState(false));
    // flatten the result
    return TreeFlatteningRebuildingVisitor.flatten(flattened);
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode)

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