Search in sources :

Example 26 with ASTJexlScript

use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.

the class QueryModelVisitorTest method testCastesianProduct.

@Test
public void testCastesianProduct() throws ParseException {
    model.addTermToModel("FOO1", "1BAR");
    model.addTermToModel("FOO1", "2BAR");
    String original = "FOO == FOO1";
    ASTJexlScript groomed = JexlASTHelper.InvertNodeVisitor.invertSwappedNodes(JexlASTHelper.parseJexlQuery(original));
    String expected = "(BAR1 == $1BAR || BAR2 == $1BAR || BAR1 == $2BAR || BAR2 == $2BAR)";
    assertResult(JexlStringBuildingVisitor.buildQuery(groomed), expected);
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) Test(org.junit.Test)

Example 27 with ASTJexlScript

use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.

the class QueryModelVisitorTest method assertResult.

private ASTJexlScript assertResult(String original, String expected) throws ParseException {
    ASTJexlScript originalScript = JexlASTHelper.parseJexlQuery(original);
    ASTJexlScript actualScript = QueryModelVisitor.applyModel(originalScript, model, allFields);
    // Verify the resulting script is as expected with a valid lineage.
    JexlNodeAssert.assertThat(actualScript).isEqualTo(expected).hasValidLineage();
    // Verify the original script was not modified, and has a valid lineage.
    JexlNodeAssert.assertThat(originalScript).isEqualTo(original).hasValidLineage();
    return actualScript;
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript)

Example 28 with ASTJexlScript

use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.

the class QueryModelVisitorTest method testNoExpansion.

private void testNoExpansion(String query, String expected, QueryModel model, Set<String> expectedFields) {
    try {
        Set<String> allFields = new HashSet<>();
        allFields.addAll(model.getForwardQueryMapping().keySet());
        allFields.addAll(model.getForwardQueryMapping().values());
        ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
        NoExpansionFunctionVisitor.VisitResult result = NoExpansionFunctionVisitor.findNoExpansionFields(script);
        JexlNodeAssert.assertThat(script).isNotEqualTo(result.script);
        Assert.assertEquals(expectedFields, result.noExpansionFields);
        ASTJexlScript applied;
        if (result.noExpansionFields.size() > 0) {
            applied = QueryModelVisitor.applyModel(result.script, model, allFields, result.noExpansionFields);
        } else {
            applied = QueryModelVisitor.applyModel(result.script, model, allFields);
        }
        if (log.isTraceEnabled()) {
            log.trace("expected: " + expected);
            log.trace("actual  : " + JexlStringBuildingVisitor.buildQueryWithoutParse(applied));
        }
        ASTJexlScript expectedScript = JexlASTHelper.parseAndFlattenJexlQuery(expected);
        assertTrue(TreeEqualityVisitor.checkEquality(expectedScript, applied).isEqual());
    } catch (ParseException e) {
        fail("Error testing query: " + query);
    }
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) ParseException(org.apache.commons.jexl2.parser.ParseException) HashSet(java.util.HashSet)

Example 29 with ASTJexlScript

use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.

the class QueryPropertyMarkerSourceConsolidatorTest method assertResult.

private void assertResult(String original, String expected) throws ParseException {
    ASTJexlScript originalScript = JexlASTHelper.parseJexlQuery(original);
    ASTJexlScript actual = QueryPropertyMarkerSourceConsolidator.consolidate(originalScript);
    JexlNodeAssert.assertThat(actual).isEqualTo(expected).hasValidLineage();
    JexlNodeAssert.assertThat(originalScript).hasExactQueryString(original).hasValidLineage();
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript)

Example 30 with ASTJexlScript

use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.

the class QueryPruningVisitorTest method orFalseTest.

@Test
public void orFalseTest() throws ParseException {
    String query = "false || _NOFIELD_ == 'z'";
    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)

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