Search in sources :

Example 6 with ASTJexlScript

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);
}
Also used : ASTIdentifier(org.apache.commons.jexl2.parser.ASTIdentifier)

Example 7 with ASTJexlScript

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));
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) Test(org.junit.Test)

Example 8 with ASTJexlScript

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());
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) Test(org.junit.Test)

Example 9 with ASTJexlScript

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));
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 10 with ASTJexlScript

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);
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) Test(org.junit.Test)

Aggregations

ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)458 Test (org.junit.Test)385 Key (org.apache.accumulo.core.data.Key)69 JexlNode (org.apache.commons.jexl2.parser.JexlNode)67 HashSet (java.util.HashSet)50 ShardQueryConfiguration (datawave.query.config.ShardQueryConfiguration)48 MockMetadataHelper (datawave.query.util.MockMetadataHelper)40 ArrayList (java.util.ArrayList)39 Type (datawave.data.type.Type)38 LcNoDiacriticsType (datawave.data.type.LcNoDiacriticsType)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