Search in sources :

Example 6 with ASTJexlScript

use of org.apache.commons.jexl3.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 7 with ASTJexlScript

use of org.apache.commons.jexl3.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 8 with ASTJexlScript

use of org.apache.commons.jexl3.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 9 with ASTJexlScript

use of org.apache.commons.jexl3.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)

Example 10 with ASTJexlScript

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

the class JexlASTHelperTest method testIdentifierParse.

private void testIdentifierParse(String query, Set<String> expectedIdentifiers) {
    try {
        ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
        Set<String> fields = JexlASTHelper.getIdentifierNames(script);
        assertEquals("Expected fields but was", expectedIdentifiers, fields);
    } catch (ParseException e) {
        e.printStackTrace();
    }
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) ParseException(org.apache.commons.jexl2.parser.ParseException)

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