Search in sources :

Example 41 with ParseException

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

the class QueryPruningVisitorTest method NRTest.

@Test
public void NRTest() throws ParseException {
    String query = "FIELD !~ 'x'";
    ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
    Assert.assertEquals(QueryPruningVisitor.TruthState.UNKNOWN, QueryPruningVisitor.getState(script));
    Assert.assertEquals(0, logAppender.getMessages().size(), logAppender.getMessages().size());
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) Test(org.junit.Test)

Example 42 with ParseException

use of org.apache.commons.jexl2.parser.ParseException 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());
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) Test(org.junit.Test)

Example 43 with ParseException

use of org.apache.commons.jexl2.parser.ParseException 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());
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) Test(org.junit.Test)

Example 44 with ParseException

use of org.apache.commons.jexl2.parser.ParseException 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));
}
Also used : DefaultArithmetic(datawave.query.jexl.DefaultArithmetic) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) JexlEvaluation(datawave.query.function.JexlEvaluation) JexlNode(org.apache.commons.jexl2.parser.JexlNode) Document(datawave.query.attributes.Document) DatawaveJexlContext(datawave.query.jexl.DatawaveJexlContext) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 45 with ParseException

use of org.apache.commons.jexl2.parser.ParseException 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());
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) Test(org.junit.Test)

Aggregations

ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)258 Test (org.junit.Test)214 JexlNode (org.apache.commons.jexl2.parser.JexlNode)56 ShardQueryConfiguration (datawave.query.config.ShardQueryConfiguration)36 Date (java.util.Date)33 ParseException (org.apache.commons.jexl2.parser.ParseException)18 HashSet (java.util.HashSet)14 Key (org.apache.accumulo.core.data.Key)9 ArrayList (java.util.ArrayList)7 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)6 IOException (java.io.IOException)5 ASTERNode (org.apache.commons.jexl2.parser.ASTERNode)5 MockMetadataHelper (datawave.query.util.MockMetadataHelper)4 PartialKey (org.apache.accumulo.core.data.PartialKey)4 Document (datawave.query.attributes.Document)3 JexlEvaluation (datawave.query.function.JexlEvaluation)3 DatawaveJexlContext (datawave.query.jexl.DatawaveJexlContext)3 DefaultArithmetic (datawave.query.jexl.DefaultArithmetic)3 StringReader (java.io.StringReader)3 AbstractMap (java.util.AbstractMap)3