Search in sources :

Example 11 with DatawaveJexlContext

use of datawave.query.jexl.DatawaveJexlContext in project datawave by NationalSecurityAgency.

the class JexlEvaluationTest method testCompare.

private void testCompare(String query, boolean expected) {
    // populate doc
    Key docKey = new Key("shard", "datatype\0uid");
    Document d = new Document();
    d.put("FOO", new Content("bar", docKey, true));
    d.put("FIELD_A", new Content("apple", docKey, true));
    d.put("FIELD_A", new Content("banana", docKey, true));
    d.put("FIELD_B", new Content("xylophone", docKey, true));
    d.put("FIELD_B", new Content("zephyr", docKey, true));
    d.put("FIELD_C", new Content("zebra", docKey, true));
    d.put("FIELD_C", new Content("zephyr", docKey, true));
    // populate context from doc
    DatawaveJexlContext context = new DatawaveJexlContext();
    d.visit(Arrays.asList("FOO", "FIELD_A", "FIELD_B", "FIELD_C"), context);
    Tuple3<Key, Document, DatawaveJexlContext> tuple = new Tuple3<>(docKey, d, context);
    JexlEvaluation evaluation = new JexlEvaluation(query, new HitListArithmetic());
    boolean result = evaluation.apply(tuple);
    assertEquals(expected, result);
}
Also used : HitListArithmetic(datawave.query.jexl.HitListArithmetic) Content(datawave.query.attributes.Content) Tuple3(datawave.query.util.Tuple3) Document(datawave.query.attributes.Document) DatawaveJexlContext(datawave.query.jexl.DatawaveJexlContext) Key(org.apache.accumulo.core.data.Key)

Aggregations

DatawaveJexlContext (datawave.query.jexl.DatawaveJexlContext)11 Key (org.apache.accumulo.core.data.Key)10 Document (datawave.query.attributes.Document)8 Test (org.junit.Test)7 Content (datawave.query.attributes.Content)5 JexlEvaluation (datawave.query.function.JexlEvaluation)3 DefaultArithmetic (datawave.query.jexl.DefaultArithmetic)3 Tuple3 (datawave.query.util.Tuple3)3 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)3 JexlNode (org.apache.commons.jexl2.parser.JexlNode)3 HitListArithmetic (datawave.query.jexl.HitListArithmetic)2 Attributes (datawave.query.attributes.Attributes)1 IndexOnlyFunctionIterator (datawave.query.iterator.IndexOnlyFunctionIterator)1 DelayedNonEventIndexContext (datawave.query.jexl.DelayedNonEventIndexContext)1 TermFrequencyList (datawave.query.jexl.functions.TermFrequencyList)1 HashMap (java.util.HashMap)1 Range (org.apache.accumulo.core.data.Range)1