use of com.apple.foundationdb.record.query.expressions.ComponentWithComparison in project fdb-record-layer by FoundationDB.
the class InExtractor method mapClauses.
private QueryComponent mapClauses(QueryComponent filter, BiFunction<ComponentWithComparison, List<FieldKeyExpression>, QueryComponent> mapper, @Nullable List<FieldKeyExpression> fields) {
if (filter instanceof ComponentWithComparison) {
final ComponentWithComparison withComparison = (ComponentWithComparison) filter;
return mapper.apply(withComparison, fields);
} else if (filter instanceof ComponentWithChildren) {
ComponentWithChildren componentWithChildren = (ComponentWithChildren) filter;
return componentWithChildren.withOtherChildren(componentWithChildren.getChildren().stream().map(component -> mapClauses(component, mapper, fields)).collect(Collectors.toList()));
} else if (filter instanceof ComponentWithSingleChild) {
ComponentWithSingleChild componentWithSingleChild = (ComponentWithSingleChild) filter;
List<FieldKeyExpression> nestedFields = null;
if (fields != null && (componentWithSingleChild instanceof NestedField || componentWithSingleChild instanceof OneOfThemWithComponent)) {
nestedFields = new ArrayList<>(fields);
nestedFields.add(Key.Expressions.field(((BaseField) componentWithSingleChild).getFieldName(), componentWithSingleChild instanceof NestedField ? KeyExpression.FanType.None : KeyExpression.FanType.FanOut));
}
return componentWithSingleChild.withOtherChild(mapClauses(componentWithSingleChild.getChild(), mapper, nestedFields));
} else if (filter instanceof ComponentWithNoChildren) {
return filter;
} else {
throw new Query.InvalidExpressionException("Unsupported query type " + filter.getClass());
}
}
use of com.apple.foundationdb.record.query.expressions.ComponentWithComparison in project fdb-record-layer by FoundationDB.
the class TextIndexTest method queryMapDocumentsWithIndex.
@Nonnull
private List<Long> queryMapDocumentsWithIndex(@Nonnull String key, @Nonnull QueryComponent textFilter, int planHash, boolean isCoveringIndexExpected) throws InterruptedException, ExecutionException {
if (!(textFilter instanceof ComponentWithComparison)) {
throw new RecordCoreArgumentException("filter without comparison provided as text filter");
}
final QueryComponent filter = Query.field("entry").oneOfThem().matches(Query.and(Query.field("key").equalsValue(key), textFilter));
Matcher<RecordQueryPlan> indexMatcher = textIndexScan(allOf(indexName(MAP_ON_VALUE_INDEX.getName()), groupingBounds(allOf(notNullValue(), hasTupleString("[[" + key + "],[" + key + "]]"))), textComparison(equalTo(((ComponentWithComparison) textFilter).getComparison()))));
if (isCoveringIndexExpected) {
indexMatcher = coveringIndexScan(indexMatcher);
}
final Matcher<RecordQueryPlan> planMatcher = descendant(indexMatcher);
return queryDocuments(Collections.singletonList(MAP_DOC), Collections.singletonList(field("doc_id")), filter, planHash, planMatcher).map(t -> t.getLong(0)).asList().get();
}
use of com.apple.foundationdb.record.query.expressions.ComponentWithComparison in project fdb-record-layer by FoundationDB.
the class TextIndexTest method queryMapDocumentsWithGroupedIndex.
@Nonnull
private List<Long> queryMapDocumentsWithGroupedIndex(@Nonnull String key, @Nonnull QueryComponent textFilter, long group, int planHash) throws InterruptedException, ExecutionException {
if (!(textFilter instanceof ComponentWithComparison)) {
throw new RecordCoreArgumentException("filter without comparison provided as text filter");
}
final QueryComponent filter = Query.and(Query.field("group").equalsValue(group), Query.field("entry").oneOfThem().matches(Query.and(Query.field("key").equalsValue(key), textFilter)));
final Matcher<RecordQueryPlan> planMatcher = descendant(coveringIndexScan(textIndexScan(allOf(indexName(MAP_ON_VALUE_GROUPED_INDEX.getName()), groupingBounds(allOf(notNullValue(), hasTupleString("[[" + group + ", " + key + "],[" + group + ", " + key + "]]"))), textComparison(equalTo(((ComponentWithComparison) textFilter).getComparison()))))));
return queryDocuments(Collections.singletonList(MAP_DOC), Collections.singletonList(field("doc_id")), filter, planHash, planMatcher).map(t -> t.getLong(0)).asList().get();
}
use of com.apple.foundationdb.record.query.expressions.ComponentWithComparison in project fdb-record-layer by FoundationDB.
the class TextIndexTest method queryComplexDocumentsWithIndex.
@Nonnull
private List<Tuple> queryComplexDocumentsWithIndex(@Nonnull QueryComponent textFilter, @Nullable QueryComponent additionalFilter, boolean skipFilterCheck, long group, int planHash) throws InterruptedException, ExecutionException {
if (!(textFilter instanceof ComponentWithComparison)) {
throw new RecordCoreArgumentException("filter without comparison provided as text filter");
}
final Matcher<RecordQueryPlan> textScanMatcher = textIndexScan(allOf(indexName(COMPLEX_TEXT_BY_GROUP.getName()), groupingBounds(allOf(notNullValue(), hasTupleString("[[" + group + "],[" + group + "]]"))), textComparison(equalTo(((ComponentWithComparison) textFilter).getComparison()))));
// Don't care whether it's covering or not
final Matcher<RecordQueryPlan> textPlanMatcher = anyOf(textScanMatcher, coveringIndexScan(textScanMatcher));
final Matcher<RecordQueryPlan> planMatcher;
final QueryComponent filter;
if (additionalFilter != null) {
if (skipFilterCheck) {
planMatcher = descendant(textPlanMatcher);
} else {
planMatcher = descendant(filter(additionalFilter, descendant(textPlanMatcher)));
}
filter = Query.and(textFilter, additionalFilter, Query.field("group").equalsValue(group));
} else {
planMatcher = descendant(textPlanMatcher);
filter = Query.and(textFilter, Query.field("group").equalsValue(group));
}
return queryComplexDocumentsWithPlan(filter, planHash, planMatcher);
}
Aggregations