Search in sources :

Example 61 with ASTJexlScript

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

Example 62 with ASTJexlScript

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

Example 63 with ASTJexlScript

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

Example 64 with ASTJexlScript

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();
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) JexlNode(org.apache.commons.jexl2.parser.JexlNode)

Example 65 with ASTJexlScript

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

Aggregations

ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)457 Test (org.junit.Test)385 Key (org.apache.accumulo.core.data.Key)69 JexlNode (org.apache.commons.jexl2.parser.JexlNode)61 HashSet (java.util.HashSet)50 ShardQueryConfiguration (datawave.query.config.ShardQueryConfiguration)48 MockMetadataHelper (datawave.query.util.MockMetadataHelper)40 Type (datawave.data.type.Type)38 LcNoDiacriticsType (datawave.data.type.LcNoDiacriticsType)37 ArrayList (java.util.ArrayList)37 ExpressionFilter (datawave.query.jexl.visitors.EventDataQueryExpressionVisitor.ExpressionFilter)36 ScannerFactory (datawave.query.tables.ScannerFactory)35 Date (java.util.Date)35 NoOpType (datawave.data.type.NoOpType)34 NumberType (datawave.data.type.NumberType)34 AbstractMap (java.util.AbstractMap)32 Range (org.apache.accumulo.core.data.Range)30 Value (org.apache.accumulo.core.data.Value)29 RangeFactoryForTests.makeTestRange (datawave.common.test.utils.query.RangeFactoryForTests.makeTestRange)26 QueryPlan (datawave.query.planner.QueryPlan)26