use of com.apple.foundationdb.record.query.plan.planning.FilterSatisfiedMask in project fdb-record-layer by FoundationDB.
the class QueryToKeyMatcher method matches.
@Nonnull
private Match matches(@Nonnull NestedField query, @Nonnull NestingKeyExpression key, @Nonnull MatchingMode matchingMode, @Nullable FilterSatisfiedMask filterMask) {
if (key.getParent().getFanType() != KeyExpression.FanType.None) {
// in theory, maybe, concatenate could work with certain things, but for now, no.
return Match.none();
} else {
if (Objects.equals(query.getFieldName(), key.getParent().getFieldName())) {
FilterSatisfiedMask childMask = filterMask != null ? filterMask.getChild(query.getChild()) : null;
Match childMatch = matches(query.getChild(), key.getChild(), matchingMode, childMask);
if (childMask != null && childMask.isSatisfied() && filterMask.getExpression() == null) {
filterMask.setExpression(key);
}
return childMatch;
} else {
return Match.none();
}
}
}
use of com.apple.foundationdb.record.query.plan.planning.FilterSatisfiedMask in project fdb-record-layer by FoundationDB.
the class LucenePlanner method getScanForOrLucene.
private LuceneIndexQueryPlan getScanForOrLucene(@Nonnull Index index, final String parentFieldName, final OrComponent filter, final FilterSatisfiedMask filterMask, final ScanComparisons groupingComparisons) {
final Iterator<FilterSatisfiedMask> subFilterMasks = filterMask != null ? filterMask.getChildren().iterator() : null;
final List<QueryComponent> filters = filter.getChildren();
LuceneIndexQueryPlan combinedComparison = null;
for (QueryComponent subFilter : filters) {
final FilterSatisfiedMask childMask = subFilterMasks != null ? subFilterMasks.next() : null;
LuceneIndexQueryPlan childComparison = getComparisonsForLuceneFilter(index, parentFieldName, subFilter, childMask, groupingComparisons);
if (childComparison != null && childMask != null) {
childMask.setSatisfied(true);
combinedComparison = combinedComparison == null ? childComparison : LuceneIndexQueryPlan.merge(childComparison, combinedComparison, "OR");
}
}
if (filterMask != null && filterMask.getUnsatisfiedFilters().isEmpty()) {
filterMask.setSatisfied(true);
}
return combinedComparison;
}
use of com.apple.foundationdb.record.query.plan.planning.FilterSatisfiedMask in project fdb-record-layer by FoundationDB.
the class LucenePlanner method planLucene.
@Override
protected ScoredPlan planLucene(@Nonnull CandidateScan candidateScan, @Nonnull Index index, @Nonnull QueryComponent filter, @Nullable KeyExpression sort) {
FilterSatisfiedMask filterMask = FilterSatisfiedMask.of(filter);
KeyExpression rootExp = index.getRootExpression();
ScanComparisons groupingComparisons;
// Getting grouping information from the index key and query filter
if (rootExp instanceof GroupingKeyExpression) {
KeyExpression groupingKey = ((GroupingKeyExpression) rootExp).getGroupingSubKey();
QueryToKeyMatcher.Match groupingMatch = new QueryToKeyMatcher(filter).matchesCoveringKey(groupingKey, filterMask);
if (!groupingMatch.getType().equals((QueryToKeyMatcher.MatchType.EQUALITY))) {
return null;
}
groupingComparisons = new ScanComparisons(groupingMatch.getEqualityComparisons(), Collections.emptySet());
} else {
groupingComparisons = null;
}
LuceneIndexQueryPlan lucenePlan = getComparisonsForLuceneFilter(index, null, filter, filterMask, groupingComparisons);
if (lucenePlan == null) {
return null;
}
RecordQueryPlan plan = lucenePlan;
plan = addTypeFilterIfNeeded(candidateScan, plan, getPossibleTypes(index));
if (filterMask.allSatisfied()) {
filterMask.setSatisfied(true);
}
return new ScoredPlan(plan, filterMask.getUnsatisfiedFilters(), Collections.emptyList(), 11 - filterMask.getUnsatisfiedFilters().size(), lucenePlan.createsDuplicates(), null);
}
use of com.apple.foundationdb.record.query.plan.planning.FilterSatisfiedMask in project fdb-record-layer by FoundationDB.
the class LucenePlanner method getScanForAndLucene.
private LuceneIndexQueryPlan getScanForAndLucene(@Nonnull Index index, @Nullable String parentFieldName, @Nonnull AndComponent filter, @Nullable FilterSatisfiedMask filterMask, final ScanComparisons groupingComparisons) {
final Iterator<FilterSatisfiedMask> subFilterMasks = filterMask != null ? filterMask.getChildren().iterator() : null;
final List<QueryComponent> filters = filter.getChildren();
LuceneIndexQueryPlan combinedComparison = null;
for (QueryComponent subFilter : filters) {
final FilterSatisfiedMask childMask = subFilterMasks != null ? subFilterMasks.next() : null;
LuceneIndexQueryPlan childComparison = getComparisonsForLuceneFilter(index, parentFieldName, subFilter, childMask, groupingComparisons);
if (childComparison != null && childMask != null) {
childMask.setSatisfied(true);
combinedComparison = combinedComparison == null ? childComparison : LuceneIndexQueryPlan.merge(combinedComparison, childComparison, "AND");
} else if (combinedComparison != null && childComparison == null) {
combinedComparison = null;
break;
}
}
if (filterMask != null && filterMask.getUnsatisfiedFilters().isEmpty()) {
filterMask.setSatisfied(true);
}
return combinedComparison;
}
use of com.apple.foundationdb.record.query.plan.planning.FilterSatisfiedMask in project fdb-record-layer by FoundationDB.
the class RecordQueryPlanner method planText.
@Nullable
private ScoredPlan planText(@Nonnull CandidateScan candidateScan, @Nonnull Index index, @Nonnull QueryComponent filter, @Nullable KeyExpression sort) {
if (sort != null) {
// TODO: Full Text: Sorts are not supported with full text queries (https://github.com/FoundationDB/fdb-record-layer/issues/55)
return null;
}
FilterSatisfiedMask filterMask = FilterSatisfiedMask.of(filter);
final TextScan scan = TextScanPlanner.getScanForQuery(index, filter, false, filterMask);
if (scan == null) {
return null;
}
// TODO: Check the rest of the fields of the text index expression to see if the sort and unsatisfied filters can be helped.
RecordQueryPlan plan = new RecordQueryTextIndexPlan(index.getName(), scan, candidateScan.reverse);
// Add a type filter if the index is over more types than those the query specifies
Set<String> possibleTypes = getPossibleTypes(index);
plan = addTypeFilterIfNeeded(candidateScan, plan, possibleTypes);
// is "strict", it must be surrounded be a filter plan.
if (scan.getTextComparison() instanceof Comparisons.TextContainsAllPrefixesComparison) {
Comparisons.TextContainsAllPrefixesComparison textComparison = (Comparisons.TextContainsAllPrefixesComparison) scan.getTextComparison();
if (textComparison.isStrict()) {
plan = new RecordQueryFilterPlan(plan, filter);
filterMask.setSatisfied(true);
}
}
// than other indexes.
return new ScoredPlan(plan, filterMask.getUnsatisfiedFilters(), Collections.emptyList(), 10, scan.createsDuplicates(), null);
}
Aggregations