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