Search in sources :

Example 16 with QueryPlan

use of datawave.query.planner.QueryPlan in project datawave by NationalSecurityAgency.

the class RangeStreamTest method testNestedOr.

@Test
public void testNestedOr() throws Exception {
    String originalQuery = "(FOO == 'bag' || FOO == 'ba' || FOO == 'barglegarglebarsh')";
    ASTJexlScript script = JexlASTHelper.parseJexlQuery(originalQuery);
    config.setBeginDate(new Date(0));
    config.setEndDate(new Date(System.currentTimeMillis()));
    Multimap<String, Type<?>> dataTypes = HashMultimap.create();
    dataTypes.putAll("FOO", Sets.newHashSet(new LcNoDiacriticsType()));
    dataTypes.putAll("NUM", Sets.newHashSet(new NumberType()));
    config.setQueryFieldsDatatypes(dataTypes);
    config.setIndexedFields(dataTypes);
    MockMetadataHelper helper = new MockMetadataHelper();
    helper.setIndexedFields(dataTypes.keySet());
    Range range1 = makeTestRange("20190314", "datatype1\u0000234");
    Range range2 = makeTestRange("20190314", "datatype1\u0000345");
    Range range3 = makeTestRange("20190314", "datatype1\u0000123");
    Set<Range> expectedRanges = Sets.newHashSet(range1, range2, range3);
    RangeStream rangeStream = new RangeStream(config, new ScannerFactory(config.getConnector(), 1), helper);
    rangeStream.setLimitScanners(true);
    for (QueryPlan queryPlan : rangeStream.streamPlans(script)) {
        for (Range range : queryPlan.getRanges()) {
            assertTrue("Tried to remove unexpected range " + range.toString() + " from expected ranges: " + expectedRanges.toString(), expectedRanges.remove(range));
        }
    }
    assertTrue("Expected ranges not found in query plan: " + expectedRanges.toString(), expectedRanges.isEmpty());
}
Also used : ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) RangeFactoryForTests.makeTestRange(datawave.common.test.utils.query.RangeFactoryForTests.makeTestRange) Range(org.apache.accumulo.core.data.Range) ScannerFactory(datawave.query.tables.ScannerFactory) QueryPlan(datawave.query.planner.QueryPlan) LcNoDiacriticsType(datawave.data.type.LcNoDiacriticsType) MockMetadataHelper(datawave.query.util.MockMetadataHelper) NoOpType(datawave.data.type.NoOpType) NumberType(datawave.data.type.NumberType) LcNoDiacriticsType(datawave.data.type.LcNoDiacriticsType) Type(datawave.data.type.Type) NumberType(datawave.data.type.NumberType) Test(org.junit.Test)

Example 17 with QueryPlan

use of datawave.query.planner.QueryPlan in project datawave by NationalSecurityAgency.

the class TupleToRange method createShardRange.

public static Iterator<QueryPlan> createShardRange(JexlNode queryNode, String shard, IndexInfo indexInfo) {
    JexlNode myNode = queryNode;
    if (indexInfo.getNode() != null) {
        myNode = indexInfo.getNode();
    }
    Range range = RangeFactory.createShardRange(shard);
    if (log.isTraceEnabled() && null != myNode) {
        log.trace("Building shard " + range + " From " + JexlStringBuildingVisitor.buildQuery(myNode));
    }
    return Collections.singleton(new QueryPlan(myNode, range)).iterator();
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) Range(org.apache.accumulo.core.data.Range) QueryPlan(datawave.query.planner.QueryPlan)

Example 18 with QueryPlan

use of datawave.query.planner.QueryPlan in project datawave by NationalSecurityAgency.

the class TupleToRange method createDayRange.

public static Iterator<QueryPlan> createDayRange(JexlNode queryNode, String shard, IndexInfo indexInfo) {
    JexlNode myNode = queryNode;
    if (indexInfo.getNode() != null) {
        myNode = indexInfo.getNode();
    }
    Range range = RangeFactory.createDayRange(shard);
    if (log.isTraceEnabled())
        log.trace("Building day" + range + " from " + (null == myNode ? "NoQueryNode" : JexlStringBuildingVisitor.buildQuery(myNode)));
    return Collections.singleton(new QueryPlan(myNode, range)).iterator();
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) Range(org.apache.accumulo.core.data.Range) QueryPlan(datawave.query.planner.QueryPlan)

Example 19 with QueryPlan

use of datawave.query.planner.QueryPlan in project datawave by NationalSecurityAgency.

the class TupleToRange method createDocumentRanges.

/**
 * @param queryNode
 * @param shard
 * @param indexMatches
 * @param isTldQuery
 * @return
 */
public static Iterator<QueryPlan> createDocumentRanges(JexlNode queryNode, String shard, IndexInfo indexMatches, boolean isTldQuery) {
    List<QueryPlan> ranges = Lists.newArrayListWithCapacity(indexMatches.uids().size());
    for (IndexMatch indexMatch : indexMatches.uids()) {
        String docId = indexMatch.getUid();
        Range range;
        if (isTldQuery) {
            range = RangeFactory.createTldDocumentSpecificRange(shard, docId);
        } else {
            range = RangeFactory.createDocumentSpecificRange(shard, docId);
        }
        if (log.isTraceEnabled())
            log.trace(queryNode + " " + indexMatch.getNode());
        // Log info if indexMatch is not null
        if (log.isTraceEnabled() && null != indexMatch.getNode()) {
            // query node can be null in this case
            log.trace("Building " + range + " from " + (null == queryNode ? "NoQueryNode" : JexlStringBuildingVisitor.buildQuery(queryNode)) + " actually " + JexlStringBuildingVisitor.buildQuery(indexMatch.getNode()));
        }
        ranges.add(new QueryPlan(indexMatch.getNode(), range));
    }
    return ranges.iterator();
}
Also used : QueryPlan(datawave.query.planner.QueryPlan) Range(org.apache.accumulo.core.data.Range)

Example 20 with QueryPlan

use of datawave.query.planner.QueryPlan in project datawave by NationalSecurityAgency.

the class FacetQueryPlanVisitor method visit.

@Override
public QueryPlan visit(ASTEQNode node, Object data) {
    // We are looking for identifier = literal
    JexlASTHelper.IdentifierOpLiteral op = JexlASTHelper.getIdentifierOpLiteral(node);
    if (op == null) {
        return null;
    }
    final String fieldName = op.deconstructIdentifier();
    // if we have a null literal, then we cannot resolve against the index
    if (op.getLiteralValue() == null) {
        return null;
    }
    String literal = op.getLiteralValue().toString();
    Key startKey = new Key(literal + "\u0000");
    Key endKey = new Key(literal + "\uFFFF");
    Collection<String> fieldPairs = new ArrayList<>();
    for (String facet : facetedFields) {
        StringBuilder facetBuilder = new StringBuilder(fieldName);
        facetBuilder.append("\u0000").append(facet);
        fieldPairs.add(facetBuilder.toString());
    }
    QueryPlan plan = new QueryPlan(node, Collections.singleton(new Range(startKey, true, endKey, false)), fieldPairs);
    // toString of String returns the String
    queryPlans.add(plan);
    return plan;
}
Also used : JexlASTHelper(datawave.query.jexl.JexlASTHelper) ArrayList(java.util.ArrayList) QueryPlan(datawave.query.planner.QueryPlan) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key)

Aggregations

QueryPlan (datawave.query.planner.QueryPlan)32 Range (org.apache.accumulo.core.data.Range)31 RangeFactoryForTests.makeTestRange (datawave.common.test.utils.query.RangeFactoryForTests.makeTestRange)26 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)26 LcNoDiacriticsType (datawave.data.type.LcNoDiacriticsType)25 NoOpType (datawave.data.type.NoOpType)25 NumberType (datawave.data.type.NumberType)25 Type (datawave.data.type.Type)25 ScannerFactory (datawave.query.tables.ScannerFactory)25 MockMetadataHelper (datawave.query.util.MockMetadataHelper)25 Test (org.junit.Test)24 SimpleDateFormat (java.text.SimpleDateFormat)8 JexlNode (org.apache.commons.jexl2.parser.JexlNode)3 ArrayList (java.util.ArrayList)2 RangeFactoryForTests.makeDayRange (datawave.common.test.utils.query.RangeFactoryForTests.makeDayRange)1 RangeFactoryForTests.makeShardedRange (datawave.common.test.utils.query.RangeFactoryForTests.makeShardedRange)1 JexlASTHelper (datawave.query.jexl.JexlASTHelper)1 SessionOptions (datawave.query.tables.SessionOptions)1 ScannerChunk (datawave.query.tables.async.ScannerChunk)1 HashMap (java.util.HashMap)1