Search in sources :

Example 11 with ASTJexlScript

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

the class JexlASTHelperTest method jexlNodeInequality.

@Test
public void jexlNodeInequality() throws Exception {
    ASTJexlScript one = JexlASTHelper.parseJexlQuery("FOO == '1'");
    ASTJexlScript two = JexlASTHelper.parseJexlQuery("'1' == '1'");
    Assert.assertFalse(JexlASTHelper.equals(one, two));
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) Test(org.junit.Test)

Example 12 with ASTJexlScript

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

the class JexlASTHelperTest method test1.

@Test
public void test1() throws Exception {
    ASTJexlScript query = JexlASTHelper.parseJexlQuery("FOO == '1' and (FOO == '2' and (FOO == '3' or FOO == '4'))");
    List<ASTEQNode> eqNodes = JexlASTHelper.getEQNodes(query);
    Map<String, Boolean> expectations = Maps.newHashMap();
    expectations.put("1", false);
    expectations.put("2", false);
    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));
    }
}
Also used : ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 13 with ASTJexlScript

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

the class JexlASTHelperTest method test3.

@Test
public void test3() throws Exception {
    ASTJexlScript query = JexlASTHelper.parseJexlQuery("FOO == '1'");
    List<ASTEQNode> eqNodes = JexlASTHelper.getEQNodes(query);
    Map<String, Boolean> expectations = Maps.newHashMap();
    expectations.put("1", false);
    for (JexlNode eqNode : eqNodes) {
        String value = JexlASTHelper.getLiteralValue(eqNode).toString();
        Assert.assertTrue(expectations.containsKey(value));
        Assert.assertEquals(expectations.get(value), JexlASTHelper.isWithinOr(eqNode));
    }
}
Also used : ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 14 with ASTJexlScript

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

the class JexlASTHelperTest method testFindRange.

@Test
public void testFindRange() throws Exception {
    ASTJexlScript script = JexlASTHelper.parseJexlQuery("((_Bounded_ = true) && (A < 'b' && A > 'a')) && !(FOO == 'bar')");
    LiteralRange range = JexlASTHelper.findRange().getRange(script.jjtGetChild(0));
    Assert.assertNull(range);
    script = JexlASTHelper.parseJexlQuery("(A < 5 && A > 1)");
    range = JexlASTHelper.findRange().getRange(script.jjtGetChild(0));
    Assert.assertNull(range);
    script = JexlASTHelper.parseJexlQuery("((_Bounded_ = true) && (A < 5 && A > 1))");
    range = JexlASTHelper.findRange().getRange(script.jjtGetChild(0));
    Assert.assertNotNull(range);
    Assert.assertNotNull(range.getLowerNode());
    Assert.assertNotNull(range.getUpperNode());
    Assert.assertEquals(1, range.getLower());
    Assert.assertEquals(5, range.getUpper());
    Assert.assertFalse(range.isLowerInclusive());
    Assert.assertFalse(range.isUpperInclusive());
    script = JexlASTHelper.parseJexlQuery("((_Bounded_ = true) && (A <= 5 && A >= 1))");
    range = JexlASTHelper.findRange().getRange(script.jjtGetChild(0));
    Assert.assertNotNull(range);
    Assert.assertNotNull(range.getLowerNode());
    Assert.assertNotNull(range.getUpperNode());
    Assert.assertEquals(1, range.getLower());
    Assert.assertEquals(5, range.getUpper());
    Assert.assertTrue(range.isLowerInclusive());
    Assert.assertTrue(range.isUpperInclusive());
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) Test(org.junit.Test)

Example 15 with ASTJexlScript

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

the class JexlASTHelperTest method sameJexlNodeEquality.

@Test
public void sameJexlNodeEquality() throws Exception {
    ASTJexlScript query = JexlASTHelper.parseJexlQuery("FOO == '1'");
    Assert.assertTrue(JexlASTHelper.equals(query, query));
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) Test(org.junit.Test)

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