Search in sources :

Example 11 with ParseException

use of org.apache.commons.jexl2.parser.ParseException 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 12 with ParseException

use of org.apache.commons.jexl2.parser.ParseException 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 13 with ParseException

use of org.apache.commons.jexl2.parser.ParseException 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 14 with ParseException

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

the class QueryPropertyMarkerVisitorTest method givenNode.

private void givenNode(String query) throws ParseException {
    JexlNode node = JexlASTHelper.parseJexlQuery(query);
    PrintingVisitor.printQuery(node);
    instance = QueryPropertyMarkerVisitor.getInstance(node);
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode)

Example 15 with ParseException

use of org.apache.commons.jexl2.parser.ParseException 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)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