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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations