Search in sources :

Example 6 with DatawaveJexlContext

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);
}
Also used : Content(datawave.query.attributes.Content) Document(datawave.query.attributes.Document) DatawaveJexlContext(datawave.query.jexl.DatawaveJexlContext) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 7 with DatawaveJexlContext

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);
}
Also used : DatawaveJexlContext(datawave.query.jexl.DatawaveJexlContext) Key(org.apache.accumulo.core.data.Key)

Example 8 with DatawaveJexlContext

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));
}
Also used : DefaultArithmetic(datawave.query.jexl.DefaultArithmetic) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) JexlEvaluation(datawave.query.function.JexlEvaluation) JexlNode(org.apache.commons.jexl2.parser.JexlNode) Document(datawave.query.attributes.Document) DatawaveJexlContext(datawave.query.jexl.DatawaveJexlContext) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 9 with DatawaveJexlContext

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));
}
Also used : DefaultArithmetic(datawave.query.jexl.DefaultArithmetic) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) JexlEvaluation(datawave.query.function.JexlEvaluation) JexlNode(org.apache.commons.jexl2.parser.JexlNode) Document(datawave.query.attributes.Document) DatawaveJexlContext(datawave.query.jexl.DatawaveJexlContext) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 10 with DatawaveJexlContext

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;
}
Also used : DelayedNonEventIndexContext(datawave.query.jexl.DelayedNonEventIndexContext) Tuple3(datawave.query.util.Tuple3) DatawaveJexlContext(datawave.query.jexl.DatawaveJexlContext) IndexOnlyFunctionIterator(datawave.query.iterator.IndexOnlyFunctionIterator) Range(org.apache.accumulo.core.data.Range) 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