Search in sources :

Example 16 with ASTJexlScript

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

the class JexlASTHelperTest method testFindLiteral.

@Test
public void testFindLiteral() throws Throwable {
    ASTJexlScript script = JexlASTHelper.parseJexlQuery("i == 10");
    if (log.isDebugEnabled()) {
        PrintingVisitor.printQuery(script);
    }
    JexlNode literal = JexlASTHelper.findLiteral(script);
    Assert.assertTrue(literal instanceof ASTNumberLiteral);
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ASTNumberLiteral(org.apache.commons.jexl2.parser.ASTNumberLiteral) Test(org.junit.Test)

Example 17 with ASTJexlScript

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

the class JexlASTHelperTest method test.

@Test
public void test() throws Exception {
    ASTJexlScript query = JexlASTHelper.parseJexlQuery("FOO == 'bar' and (FOO == 'bar' and FOO == 'bar')");
    List<ASTEQNode> eqNodes = JexlASTHelper.getEQNodes(query);
    for (JexlNode eqNode : eqNodes) {
        Assert.assertFalse(JexlASTHelper.isWithinOr(eqNode));
    }
}
Also used : ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 18 with ASTJexlScript

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

the class JexlASTHelperTest method test2.

@Test
public void test2() throws Exception {
    ASTJexlScript query = JexlASTHelper.parseJexlQuery("FOO == '1' and (FOO == '2' or (FOO == '3' and FOO == '4'))");
    List<ASTEQNode> eqNodes = JexlASTHelper.getEQNodes(query);
    Map<String, Boolean> expectations = Maps.newHashMap();
    expectations.put("1", false);
    expectations.put("2", true);
    expectations.put("3", true);
    expectations.put("4", true);
    for (JexlNode eqNode : eqNodes) {
        String value = JexlASTHelper.getLiteralValue(eqNode).toString();
        Assert.assertTrue(expectations.containsKey(value));
        Assert.assertEquals(expectations.get(value), JexlASTHelper.isWithinOr(eqNode));
    }
}
Also used : ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 19 with ASTJexlScript

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

the class DefaultQueryPlanner method timedPruneGeoWaveTerms.

protected ASTJexlScript timedPruneGeoWaveTerms(QueryStopwatch timers, ASTJexlScript script, MetadataHelper metadataHelper) throws DatawaveQueryException {
    Multimap<String, String> prunedTerms = HashMultimap.create();
    ASTJexlScript finalScript = script;
    script = visitorManager.timedVisit(timers, "Prune GeoWave Terms", () -> GeoWavePruningVisitor.pruneTree(finalScript, prunedTerms, metadataHelper));
    if (log.isDebugEnabled()) {
        log.debug("Pruned the following GeoWave terms: [" + prunedTerms.entries().stream().map(x -> x.getKey() + "==" + x.getValue()).collect(Collectors.joining(",")) + "]");
    }
    return script;
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript)

Example 20 with ASTJexlScript

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

the class DefaultQueryPlanner method parseQueryAndValidatePattern.

protected ASTJexlScript parseQueryAndValidatePattern(String query, TraceStopwatch stopwatch) {
    ASTJexlScript queryTree;
    try {
        queryTree = JexlASTHelper.parseAndFlattenJexlQuery(query);
        ValidPatternVisitor.check(queryTree);
        ValidComparisonVisitor.check(queryTree);
    } catch (StackOverflowError soe) {
        if (log.isTraceEnabled()) {
            log.trace("Stack trace for overflow " + soe);
        }
        stopwatch.stop();
        PreConditionFailedQueryException qe = new PreConditionFailedQueryException(DatawaveErrorCode.QUERY_DEPTH_OR_TERM_THRESHOLD_EXCEEDED, soe);
        log.warn(qe);
        throw new DatawaveFatalQueryException(qe);
    } catch (ParseException e) {
        stopwatch.stop();
        BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.UNPARSEABLE_JEXL_QUERY, e, MessageFormat.format("Query: {0}", query));
        log.warn(qe);
        throw new DatawaveFatalQueryException(qe);
    } catch (PatternSyntaxException e) {
        stopwatch.stop();
        BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.INVALID_REGEX, e, MessageFormat.format("Query: {0}", query));
        log.warn(qe);
        throw new DatawaveFatalQueryException(qe);
    }
    return queryTree;
}
Also used : PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) ParseException(org.apache.commons.jexl2.parser.ParseException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

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