use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class QueryPruningVisitorTest method notFalseTest.
@Test
public void notFalseTest() throws ParseException {
String query = "!false";
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
Assert.assertEquals(QueryPruningVisitor.TruthState.TRUE, 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 QueryPruningVisitorTest method NRNoFieldTest.
@Test
public void NRNoFieldTest() throws ParseException {
String query = "_NOFIELD_ !~ 'x'";
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
Assert.assertEquals(QueryPruningVisitor.TruthState.FALSE, 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 QueryPruningVisitorTest method falseDoubleAndRewriteTest.
@Test
public void falseDoubleAndRewriteTest() throws ParseException {
String query = "FIELD1 == 'x' && _NOFIELD_ == 'y' && FIELD2 == 'y'";
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
JexlNode reduced = QueryPruningVisitor.reduce(script, true);
JexlEvaluation jexlEvaluation = new JexlEvaluation(JexlStringBuildingVisitor.buildQuery(reduced), new DefaultArithmetic());
boolean jexlState = jexlEvaluation.apply(new Tuple3<>(new Key(), new Document(), new DatawaveJexlContext()));
Assert.assertFalse(jexlState);
Assert.assertEquals("false", JexlStringBuildingVisitor.buildQuery(reduced));
Assert.assertEquals("false", JexlStringBuildingVisitor.buildQuery(QueryPruningVisitor.reduce(script, false)));
Assert.assertTrue(logAppender.getMessages().size() == 2);
Assert.assertEquals("Pruning FIELD1 == 'x' && _NOFIELD_ == 'y' && FIELD2 == 'y' to false", logAppender.getMessages().get(0));
Assert.assertEquals("Query before prune: FIELD1 == 'x' && _NOFIELD_ == 'y' && FIELD2 == 'y'\nQuery after prune: false", logAppender.getMessages().get(1));
}
use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class QueryPruningVisitorTest method branchedTest.
@Test
public void branchedTest() throws ParseException {
String query = "FIELD1 == 'x' || (_NOFIELD_ == 'y' && FIELD2 == 'z')";
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 QueryPruningVisitorTest method nestedBranchRewriteTest.
@Test
public void nestedBranchRewriteTest() throws ParseException {
String query = "((_NOFIELD_ == 'x' || _NOFIELD_ == 'y') && _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(3, logAppender.getMessages().size());
Assert.assertEquals("Pruning (_NOFIELD_ == 'x' || _NOFIELD_ == 'y') && _NOFIELD_ == 'z' to false", logAppender.getMessages().get(0));
Assert.assertEquals("Pruning ((_NOFIELD_ == 'x' || _NOFIELD_ == 'y') && _NOFIELD_ == 'z') from ((_NOFIELD_ == 'x' || _NOFIELD_ == 'y') && _NOFIELD_ == 'z') || FIELD2 == 'z'", logAppender.getMessages().get(1));
Assert.assertEquals("Query before prune: ((_NOFIELD_ == 'x' || _NOFIELD_ == 'y') && _NOFIELD_ == 'z') || FIELD2 == 'z'\nQuery after prune: FIELD2 == 'z'", logAppender.getMessages().get(2));
}
Aggregations