Search in sources :

Example 96 with Document

use of datawave.query.attributes.Document in project datawave by NationalSecurityAgency.

the class JexlEvaluationTest method testSomeFilterFunctions.

@Test
public void testSomeFilterFunctions() {
    String query = "ANCHOR == 'a' && filter:includeRegex(FOO, 'baz.*')";
    Document d = new Document();
    d.put("ANCHOR", new Content("a", new Key("shard", "datatype\0uid"), true));
    d.put("FOO", new Content("bazaar", new Key("shard", "datatype\0uid"), true));
    // Case 1: Single fielded filter function, field is present
    evaluate(query, d);
    query = "ANCHOR == 'a' && filter:includeRegex((FOO||FOO2||FOO3), 'baz.*')";
    String orderMattersQuery = "ANCHOR == 'a' && filter:includeRegex((FOO3||FOO2||FOO), 'baz.*')";
    d = new Document();
    d.put("ANCHOR", new Content("a", new Key("shard", "datatype\0uid"), true));
    d.put("FOO", new Content("bazaar", new Key("shard", "datatype\0uid"), true));
    d.put("FOO3", new Content("bazaar", new Key("shard", "datatype\0uid"), true));
    // Case 2: Multi-fielded filter function, both fields present
    evaluate(query, d);
    evaluate(orderMattersQuery, d);
    d = new Document();
    d.put("ANCHOR", new Content("a", new Key("shard", "datatype\0uid"), true));
    d.put("FOO", new Content("bazaar", new Key("shard", "datatype\0uid"), true));
    d.put("FOO3", new Content("nohit", new Key("shard", "datatype\0uid"), true));
    // Case 3: Multi-fielded filter function, only first field is present
    evaluate(query, d);
    evaluate(orderMattersQuery, d);
    d = new Document();
    d.put("ANCHOR", new Content("a", new Key("shard", "datatype\0uid"), true));
    d.put("FOO", new Content("nohit", new Key("shard", "datatype\0uid"), true));
    d.put("FOO3", new Content("bazaar", new Key("shard", "datatype\0uid"), true));
    // Case 4: Multi-fielded filter function, only second field is present
    evaluate(query, d);
    evaluate(orderMattersQuery, d);
}
Also used : Content(datawave.query.attributes.Content) Document(datawave.query.attributes.Document) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 97 with Document

use of datawave.query.attributes.Document 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

Document (datawave.query.attributes.Document)97 Key (org.apache.accumulo.core.data.Key)76 Test (org.junit.Test)35 Value (org.apache.accumulo.core.data.Value)30 HashSet (java.util.HashSet)28 Range (org.apache.accumulo.core.data.Range)26 Attribute (datawave.query.attributes.Attribute)18 Map (java.util.Map)17 Attributes (datawave.query.attributes.Attributes)16 HashMap (java.util.HashMap)16 AbstractMap (java.util.AbstractMap)14 TypeAttribute (datawave.query.attributes.TypeAttribute)13 Entry (java.util.Map.Entry)13 PreNormalizedAttribute (datawave.query.attributes.PreNormalizedAttribute)12 Set (java.util.Set)12 Content (datawave.query.attributes.Content)11 TypeMetadata (datawave.query.util.TypeMetadata)10 QueryImpl (datawave.webservice.query.QueryImpl)10 DatawaveKey (datawave.query.data.parsers.DatawaveKey)9 DatawaveJexlContext (datawave.query.jexl.DatawaveJexlContext)9