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);
}
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));
}
}
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));
}
}
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;
}
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;
}
Aggregations