Search in sources :

Example 96 with JexlNode

use of org.apache.commons.jexl2.parser.JexlNode in project datawave by NationalSecurityAgency.

the class JexlNodeSetTest method testClear.

@Test
public void testClear() {
    JexlNode node1 = JexlNodeFactory.buildEQNode("FOO", "bar");
    JexlNode node2 = JexlNodeFactory.buildEQNode("FOO2", "bar2");
    JexlNode node3 = JexlNodeFactory.buildEQNode("FOO3", "bar3");
    Collection<JexlNode> nodes = Lists.newArrayList(node1, node2, node3);
    JexlNodeSet nodeSet = new JexlNodeSet();
    nodeSet.addAll(nodes);
    assertTrue(nodeSet.contains(node1));
    assertTrue(nodeSet.contains(node2));
    assertTrue(nodeSet.contains(node3));
    assertFalse(nodeSet.isEmpty());
    nodeSet.clear();
    assertFalse(nodeSet.contains(node1));
    assertFalse(nodeSet.contains(node2));
    assertFalse(nodeSet.contains(node3));
    assertTrue(nodeSet.isEmpty());
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 97 with JexlNode

use of org.apache.commons.jexl2.parser.JexlNode in project datawave by NationalSecurityAgency.

the class JexlNodeSetTest method testToArray1.

@Test
public void testToArray1() {
    JexlNode node = JexlNodeFactory.buildEQNode("FOO", "bar");
    JexlNodeSet nodeSet = new JexlNodeSet();
    nodeSet.add(node);
    Object[] array = nodeSet.toArray();
    assertEquals(1, array.length);
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 98 with JexlNode

use of org.apache.commons.jexl2.parser.JexlNode in project datawave by NationalSecurityAgency.

the class JexlNodeSetTest method testGetNodesAndGetNodeKeys.

@Test
public void testGetNodesAndGetNodeKeys() {
    JexlNode node = JexlNodeFactory.buildEQNode("FOO", "bar");
    String key = "FOO == 'bar'";
    JexlNodeSet nodeSet = new JexlNodeSet();
    nodeSet.add(node);
    assertEquals(Collections.singleton(key), nodeSet.getNodeKeys());
    assertEquals(node, nodeSet.getNodes().iterator().next());
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 99 with JexlNode

use of org.apache.commons.jexl2.parser.JexlNode in project datawave by NationalSecurityAgency.

the class JexlNodeSetTest method testDirectAddAll.

// Test exercises the directAddAll() codepath found within the addAll() method.
@Test
public void testDirectAddAll() {
    JexlNode node1 = JexlNodeFactory.buildEQNode("FOO", "bar");
    JexlNode node2 = JexlNodeFactory.buildEQNode("FOO2", "bar2");
    JexlNodeSet nodeSet = new JexlNodeSet();
    nodeSet.add(node1);
    nodeSet.add(node2);
    JexlNode node3 = JexlNodeFactory.buildEQNode("FOO3", "bar3");
    JexlNode node4 = JexlNodeFactory.buildEQNode("FOO4", "bar4");
    JexlNodeSet otherSet = new JexlNodeSet();
    otherSet.add(node3);
    otherSet.add(node4);
    assertEquals(2, nodeSet.size());
    assertEquals(2, otherSet.size());
    nodeSet.addAll(otherSet);
    assertEquals(4, nodeSet.size());
    assertTrue(nodeSet.contains(node1));
    assertTrue(nodeSet.contains(node2));
    assertTrue(nodeSet.contains(node3));
    assertTrue(nodeSet.contains(node4));
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) Test(org.junit.Test)

Example 100 with JexlNode

use of org.apache.commons.jexl2.parser.JexlNode in project datawave by NationalSecurityAgency.

the class RangeStream method containsIndexOnlyFields.

protected boolean containsIndexOnlyFields(JexlNode node) throws TableNotFoundException {
    List<ASTIdentifier> identifiers = JexlASTHelper.getIdentifiers(node);
    Set<String> indexOnlyFields = metadataHelper.getIndexOnlyFields(config.getDatatypeFilter());
    // Hack to get around the extra ASTIdentifier left in the AST by the threshold marker node
    Iterator<ASTIdentifier> iter = identifiers.iterator();
    while (iter.hasNext()) {
        ASTIdentifier id = iter.next();
        if (ExceededValueThresholdMarkerJexlNode.label().equals(id.image) || ExceededTermThresholdMarkerJexlNode.label().equals(id.image) || ExceededOrThresholdMarkerJexlNode.label().equals(id.image)) {
            iter.remove();
        }
    }
    for (ASTIdentifier identifier : identifiers) {
        String fieldName = JexlASTHelper.deconstructIdentifier(identifier);
        if (indexOnlyFields.contains(fieldName)) {
            return true;
        }
    }
    return false;
}
Also used : ASTIdentifier(org.apache.commons.jexl2.parser.ASTIdentifier)

Aggregations

JexlNode (org.apache.commons.jexl2.parser.JexlNode)327 Test (org.junit.Test)124 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)64 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)57 ArrayList (java.util.ArrayList)51 JexlNode (org.apache.commons.jexl3.parser.JexlNode)38 ASTAndNode (org.apache.commons.jexl2.parser.ASTAndNode)37 ExceededTermThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode)34 ASTEQNode (org.apache.commons.jexl2.parser.ASTEQNode)29 ASTOrNode (org.apache.commons.jexl2.parser.ASTOrNode)29 ASTReference (org.apache.commons.jexl2.parser.ASTReference)27 ExceededOrThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode)25 ASTIdentifier (org.apache.commons.jexl2.parser.ASTIdentifier)24 HashSet (java.util.HashSet)23 ASTReferenceExpression (org.apache.commons.jexl2.parser.ASTReferenceExpression)19 ASTFunctionNode (org.apache.commons.jexl2.parser.ASTFunctionNode)17 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)16 IndexHoleMarkerJexlNode (datawave.query.jexl.nodes.IndexHoleMarkerJexlNode)15 ASTERNode (org.apache.commons.jexl2.parser.ASTERNode)15 LiteralRange (datawave.query.jexl.LiteralRange)13