use of datawave.query.jexl.DatawaveJexlContext in project datawave by NationalSecurityAgency.
the class JexlEvaluationTest method testSimpleQuery.
@Test
public void testSimpleQuery() {
String query = "FOO == 'bar'";
Document d = new Document();
d.put("FOO", new Content("bar", new Key("shard", "datatype\0uid"), true));
JexlEvaluation evaluation = new JexlEvaluation(query);
DatawaveJexlContext context = new DatawaveJexlContext();
d.visit(Collections.singleton("FOO"), context);
boolean result = evaluation.apply(new Tuple3<>(new Key("shard", "datatype\0uid"), d, context));
assertTrue(result);
}
use of datawave.query.jexl.DatawaveJexlContext in project datawave by NationalSecurityAgency.
the class JexlEvaluationTest method evaluate.
// Assume fields are {ANCHOR, FOO, FOO2} and a constant doc key
private void evaluate(String query, Document d) {
JexlEvaluation evaluation = new JexlEvaluation(query);
DatawaveJexlContext context = new DatawaveJexlContext();
d.visit(Arrays.asList("ANCHOR", "FOO", "FOO2", "FOO3"), context);
boolean result = evaluation.apply(new Tuple3<>(new Key("shard", "datatype\0uid"), d, context));
assertTrue(result);
}
use of datawave.query.jexl.DatawaveJexlContext in project datawave by NationalSecurityAgency.
the class QueryPruningVisitorTest method trueRewriteTest.
@Test
public void trueRewriteTest() throws ParseException {
String query = "true || (FIELD1 == '1' && filter:isNull(FIELD2))";
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
JexlNode reduced = QueryPruningVisitor.reduce(script, true);
JexlEvaluation jexlEvaluation = new JexlEvaluation(JexlStringBuildingVisitor.buildQuery(reduced), new DefaultArithmetic());
boolean jexlState = jexlEvaluation.apply(new Tuple3<>(new Key(), new Document(), new DatawaveJexlContext()));
Assert.assertTrue(jexlState);
Assert.assertEquals("true", JexlStringBuildingVisitor.buildQuery(reduced));
Assert.assertEquals("true", JexlStringBuildingVisitor.buildQuery(QueryPruningVisitor.reduce(script, false)));
Assert.assertTrue(logAppender.getMessages().size() == 2);
Assert.assertEquals("Pruning true || (FIELD1 == '1' && filter:isNull(FIELD2)) to true", logAppender.getMessages().get(0));
Assert.assertEquals("Query before prune: true || (FIELD1 == '1' && filter:isNull(FIELD2))\nQuery after prune: true", logAppender.getMessages().get(1));
}
use of datawave.query.jexl.DatawaveJexlContext in project datawave by NationalSecurityAgency.
the class QueryPruningVisitorTest method falseAndRewriteTest.
@Test
public void falseAndRewriteTest() throws ParseException {
String query = "FIELD1 == 'x' && _NOFIELD_ == 'y'";
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
JexlNode reduced = QueryPruningVisitor.reduce(script, true);
JexlEvaluation jexlEvaluation = new JexlEvaluation(JexlStringBuildingVisitor.buildQuery(reduced), new DefaultArithmetic());
boolean jexlState = jexlEvaluation.apply(new Tuple3<>(new Key(), new Document(), new DatawaveJexlContext()));
Assert.assertFalse(jexlState);
Assert.assertEquals("false", JexlStringBuildingVisitor.buildQuery(reduced));
Assert.assertEquals("false", JexlStringBuildingVisitor.buildQuery(QueryPruningVisitor.reduce(script, false)));
Assert.assertTrue(logAppender.getMessages().size() == 2);
Assert.assertEquals("Pruning FIELD1 == 'x' && _NOFIELD_ == 'y' to false", logAppender.getMessages().get(0));
Assert.assertEquals("Query before prune: FIELD1 == 'x' && _NOFIELD_ == 'y'\nQuery after prune: false", logAppender.getMessages().get(1));
}
use of datawave.query.jexl.DatawaveJexlContext in project datawave by NationalSecurityAgency.
the class IndexOnlyContextCreator method newDatawaveJexlContext.
@Override
protected DatawaveJexlContext newDatawaveJexlContext(final Tuple3<Key, Document, Map<String, Object>> from) {
final DatawaveJexlContext parentContext = super.newDatawaveJexlContext(from);
DatawaveJexlContext newContext;
if (this.createIndexOnlyJexlContext) {
final Key key = from.first();
final IndexOnlyFunctionIterator<Tuple3<Key, Document, DatawaveJexlContext>> iterator = new IndexOnlyFunctionIterator<>(this.documentSpecificSource, this, key);
newContext = new IndexOnlyJexlContext<>(parentContext, iterator);
} else {
newContext = parentContext;
}
// see if there are any delayed nodes that need to be processed
if (delayedNonEventFieldMap != null && !delayedNonEventFieldMap.isEmpty()) {
// build the current document range from the document Key to end of the document, even though for some query logics this may be too large a range,
// it will be narrowed with equality later
Key startKey = new Key(from.first().getRow(), from.first().getColumnFamily());
Key endKey = new Key(startKey.getRow().toString(), startKey.getColumnFamily() + Constants.MAX_UNICODE_STRING);
Range docRange = new Range(startKey, true, endKey, false);
newContext = new DelayedNonEventIndexContext(newContext, iteratorBuildingVisitor, delayedNonEventFieldMap, docRange, columnFamilies, inclusive, equality);
}
return newContext;
}
Aggregations