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);
}
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);
}
Aggregations