use of org.apache.commons.jexl2.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class TLDEventDataFilter method extractQueryFieldsFromScript.
/**
* Extract the query fields from the script and sort them
*
* @param script
*/
private void extractQueryFieldsFromScript(ASTJexlScript script) {
queryFields = new ArrayList<>();
String field;
List<ASTIdentifier> identifiers = JexlASTHelper.getIdentifiers(script);
for (ASTIdentifier identifier : identifiers) {
field = JexlASTHelper.deconstructIdentifier(identifier);
if (!queryFields.contains(field)) {
queryFields.add(field);
}
}
// sort the queryFields
Collections.sort(queryFields);
queryFields = Collections.unmodifiableList(queryFields);
}
use of org.apache.commons.jexl2.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class JexlASTHelperTest method testGetLiteralValueThrowsNSEE.
@Test(expected = NoSuchElementException.class)
public void testGetLiteralValueThrowsNSEE() throws Exception {
ASTJexlScript query = JexlASTHelper.parseJexlQuery("FOO == FOO2");
assertNull(JexlASTHelper.getLiteralValue(query));
}
use of org.apache.commons.jexl2.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class JexlASTHelperTest method testFindDelayedRange.
@Test
public void testFindDelayedRange() throws Exception {
ASTJexlScript script = JexlASTHelper.parseJexlQuery("((_Delayed_ = true) && ((_Bounded_ = true) && (A < 'b' && A > 'a'))) && !(FOO == 'bar')");
LiteralRange range = JexlASTHelper.findRange().getRange(script.jjtGetChild(0));
Assert.assertNull(range);
script = JexlASTHelper.parseJexlQuery("((_Delayed_ = true) && ((_Bounded_ = true) && (A < 'b' && A > 'a')))");
range = JexlASTHelper.findRange().getRange(script.jjtGetChild(0));
Assert.assertNotNull(range);
Assert.assertNotNull(range.getLowerNode());
Assert.assertNotNull(range.getUpperNode());
Assert.assertEquals("a", range.getLower());
Assert.assertEquals("b", range.getUpper());
Assert.assertFalse(range.isLowerInclusive());
Assert.assertFalse(range.isUpperInclusive());
}
use of org.apache.commons.jexl2.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class JexlASTHelperTest method testDereferenceMarkerNodeSafely.
// dereference marked node while preserving the final wrapper layer
@Test
public void testDereferenceMarkerNodeSafely() throws ParseException {
String query = "(((((_Value_ = true) && (FOO =~ 'a.*')))))";
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
JexlNode child = script.jjtGetChild(0);
JexlNode test = JexlASTHelper.dereferenceSafely(child);
Assert.assertEquals("((_Value_ = true) && (FOO =~ 'a.*'))", JexlStringBuildingVisitor.buildQueryWithoutParse(test));
}
use of org.apache.commons.jexl2.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class JexlASTHelperTest method testFindIndexedRange.
@Test
public void testFindIndexedRange() throws Exception {
MockMetadataHelper helper = new MockMetadataHelper();
helper.setIndexedFields(Collections.singleton("A"));
ASTJexlScript script = JexlASTHelper.parseJexlQuery("((_Bounded_ = true) && (A < 'b' && A > 'a'))");
LiteralRange range = JexlASTHelper.findRange().indexedOnly(null, helper).getRange(script.jjtGetChild(0));
Assert.assertNotNull(range);
Assert.assertNotNull(range.getLowerNode());
Assert.assertNotNull(range.getUpperNode());
Assert.assertEquals("a", range.getLower());
Assert.assertEquals("b", range.getUpper());
Assert.assertFalse(range.isLowerInclusive());
Assert.assertFalse(range.isUpperInclusive());
script = JexlASTHelper.parseJexlQuery("B < 5 && B > 1");
range = JexlASTHelper.findRange().indexedOnly(null, helper).getRange(script.jjtGetChild(0));
Assert.assertNull(range);
}
Aggregations