use of org.apache.commons.jexl2.parser.ParseException 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;
}
use of org.apache.commons.jexl2.parser.ParseException in project datawave by NationalSecurityAgency.
the class JexlControlledQueryParser method checkIfQueryAllowed.
private void checkIfQueryAllowed(String query) throws ParseException {
JexlNode node;
try {
node = JexlASTHelper.parseJexlQuery(query);
} catch (Throwable e) {
throw new ParseException(e.getMessage());
}
Set<String> fields = new TreeSet<>();
List<ASTIdentifier> idList = JexlASTHelper.getIdentifiers(node);
for (ASTIdentifier id : idList) {
String fieldName = id.image;
if (!StringUtils.isEmpty(fieldName)) {
fieldName = fieldName.trim().toUpperCase();
if (fieldName.charAt(0) == '$') {
fields.add(fieldName.substring(1));
} else {
fields.add(fieldName);
}
}
}
fields.removeAll(allowedFields);
if (!fields.isEmpty()) {
throw new ParseException("Unallowed field(s) '" + fields + "' for this type of query");
}
}
use of org.apache.commons.jexl2.parser.ParseException in project datawave by NationalSecurityAgency.
the class PushdownUnexecutableNodesVisitorTest method testFieldIndex.
@Test
public void testFieldIndex() throws ParseException {
ASTJexlScript query = JexlASTHelper.parseJexlQuery(baseQuery);
replayAll();
// field index
Assert.assertEquals(expectedPreFieldState, ExecutableDeterminationVisitor.getState(query, config, helper, true));
JexlNode result = PushdownUnexecutableNodesVisitor.pushdownPredicates(query, true, config, indexedFields, indexOnlyFields, nonEventFields, helper);
Assert.assertEquals(expectedFieldIndexPushdown, JexlStringBuildingVisitor.buildQuery(result));
Assert.assertEquals(expectedPostFieldState, ExecutableDeterminationVisitor.getState(result, config, helper, true));
verifyAll();
}
use of org.apache.commons.jexl2.parser.ParseException in project datawave by NationalSecurityAgency.
the class PushdownUnexecutableNodesVisitorTest method testGlobalIndex.
@Test
public void testGlobalIndex() throws ParseException {
ASTJexlScript query = JexlASTHelper.parseJexlQuery(baseQuery);
replayAll();
// global index
Assert.assertEquals(expectedPreGlobalState, ExecutableDeterminationVisitor.getState(query, config, helper, false));
JexlNode result = PushdownUnexecutableNodesVisitor.pushdownPredicates(query, false, config, indexedFields, indexOnlyFields, nonEventFields, helper);
Assert.assertEquals(expectedGlobalIndexPushdown, JexlStringBuildingVisitor.buildQuery(result));
Assert.assertEquals(expectedPostGlobalState, ExecutableDeterminationVisitor.getState(result, config, helper, false));
verifyAll();
}
use of org.apache.commons.jexl2.parser.ParseException 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);
}
Aggregations