use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class QueryPruningVisitorTest method dualStatementQueryTest.
@Test
public void dualStatementQueryTest() throws ParseException {
String query = "(Expression = 'somevalue'); FIELD == 'x'";
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
Assert.assertEquals(QueryPruningVisitor.TruthState.UNKNOWN, QueryPruningVisitor.getState(script));
Assert.assertEquals(query, JexlStringBuildingVisitor.buildQuery(QueryPruningVisitor.reduce(script, false)));
query = "(Expression = 'somevalue'); FIELD == 'x' || true";
script = JexlASTHelper.parseJexlQuery(query);
Assert.assertEquals(QueryPruningVisitor.TruthState.TRUE, QueryPruningVisitor.getState(script));
Assert.assertEquals("(Expression = 'somevalue'); true", JexlStringBuildingVisitor.buildQuery(QueryPruningVisitor.reduce(script, false)));
query = "(Expression = 'somevalue'); FIELD == 'x' && false";
script = JexlASTHelper.parseJexlQuery(query);
Assert.assertEquals(QueryPruningVisitor.TruthState.UNKNOWN, QueryPruningVisitor.getState(script));
Assert.assertEquals("(Expression = 'somevalue'); false", JexlStringBuildingVisitor.buildQuery(QueryPruningVisitor.reduce(script, false)));
}
use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class QueryPruningVisitorTest method deeplyNestedBranchRewriteTest.
@Test
public void deeplyNestedBranchRewriteTest() throws ParseException {
String query = "((_NOFIELD_ == 'x' || _NOFIELD_ == 'y') && (_NOFIELD_ == 'a' || _NOFIELD_ == 'b') && _NOFIELD_ == 'z') || FIELD2 == 'z'";
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
JexlNode reduced = QueryPruningVisitor.reduce(script, true);
Assert.assertEquals("FIELD2 == 'z'", JexlStringBuildingVisitor.buildQuery(reduced));
Assert.assertEquals("FIELD2 == 'z'", JexlStringBuildingVisitor.buildQuery(QueryPruningVisitor.reduce(script, false)));
Assert.assertEquals(logAppender.getMessages().size() + "", 3, logAppender.getMessages().size());
Assert.assertEquals("Pruning (_NOFIELD_ == 'x' || _NOFIELD_ == 'y') && (_NOFIELD_ == 'a' || _NOFIELD_ == 'b') && _NOFIELD_ == 'z' to false", logAppender.getMessages().get(0));
Assert.assertEquals("Pruning ((_NOFIELD_ == 'x' || _NOFIELD_ == 'y') && (_NOFIELD_ == 'a' || _NOFIELD_ == 'b') && _NOFIELD_ == 'z') from ((_NOFIELD_ == 'x' || _NOFIELD_ == 'y') && (_NOFIELD_ == 'a' || _NOFIELD_ == 'b') && _NOFIELD_ == 'z') || FIELD2 == 'z'", logAppender.getMessages().get(1));
Assert.assertEquals("Query before prune: ((_NOFIELD_ == 'x' || _NOFIELD_ == 'y') && (_NOFIELD_ == 'a' || _NOFIELD_ == 'b') && _NOFIELD_ == 'z') || FIELD2 == 'z'\nQuery after prune: FIELD2 == 'z'", logAppender.getMessages().get(2));
}
use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class QueryPruningVisitorTest method functionTest.
@Test
public void functionTest() throws ParseException {
String query = "filter:isNull(FIELD)";
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
Assert.assertEquals(QueryPruningVisitor.TruthState.UNKNOWN, QueryPruningVisitor.getState(script));
Assert.assertEquals(0, logAppender.getMessages().size(), logAppender.getMessages().size());
}
use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class RegexFunctionVisitorTest method assertVisitorResult.
private void assertVisitorResult(String original, String expected, String field) throws ParseException {
ASTJexlScript originalScript = JexlASTHelper.parseJexlQuery(original);
Set<String> indexOnlyFields = Sets.newHashSet(field);
JexlNode actual = RegexFunctionVisitor.expandRegex(null, null, indexOnlyFields, originalScript);
// Verify the resulting script is as expected, with a valid lineage.
JexlNodeAssert.assertThat(actual).isEqualTo(expected).hasValidLineage();
// Verify the original script was not modified and has a valid lineage.
JexlNodeAssert.assertThat(originalScript).isEqualTo(original).hasValidLineage();
}
use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class RewriteNegationsVisitorTest method testConjunctionOfNEAndNestedNeAndEQ.
// Test AST such that (!A && (!B && C))
@Test
public void testConjunctionOfNEAndNestedNeAndEQ() throws ParseException {
String queryString = "FOO != BAR && (BAR != FOO && BAR == CAT)";
String expectedQuery = "!(FOO == BAR) && (!(BAR == FOO) && BAR == CAT)";
ASTJexlScript script = JexlASTHelper.parseJexlQuery(queryString);
ASTJexlScript negatedScript = RewriteNegationsVisitor.rewrite(script);
String negatedQuery = JexlStringBuildingVisitor.buildQuery(negatedScript);
String errMsg = "Failed for query structure like (!A && !B && !C))";
assertEquals(errMsg, expectedQuery, negatedQuery);
}
Aggregations