use of org.eclipse.ditto.rql.query.criteria.Criteria in project ditto by eclipse.
the class QueryParser method parseSudoCountThings.
/**
* Parses a SudoCountThings command into a query.
*
* @param sudoCountThings the command.
* @return the query.
*/
public CompletionStage<Query> parseSudoCountThings(final SudoCountThings sudoCountThings) {
final DittoHeaders headers = sudoCountThings.getDittoHeaders();
final String filters = sudoCountThings.getFilter().orElse(null);
final Criteria criteria = queryFilterCriteriaFactory.filterCriteria(filters, headers);
return CompletableFuture.completedStage(queryBuilderFactory.newUnlimitedBuilder(criteria).build());
}
use of org.eclipse.ditto.rql.query.criteria.Criteria in project ditto by eclipse.
the class QueryParser method parse.
/**
* Parses a search command into a query.
*
* @param commandToValidate the search command.
* @return the query.
*/
public CompletionStage<Query> parse(final ThingSearchQueryCommand<?> commandToValidate) {
final Criteria criteria = parseCriteria(commandToValidate);
return queryCriteriaValidator.validateCommand(commandToValidate).thenApply(command -> {
if (command instanceof QueryThings) {
final QueryThings queryThings = (QueryThings) command;
final QueryBuilder queryBuilder = queryBuilderFactory.newBuilder(criteria);
queryThings.getOptions().map(optionStrings -> String.join(",", optionStrings)).ifPresent(options -> setOptions(options, queryBuilder, command.getDittoHeaders()));
return queryBuilder.build();
} else if (command instanceof StreamThings) {
final StreamThings streamThings = (StreamThings) command;
final QueryBuilder queryBuilder = queryBuilderFactory.newUnlimitedBuilder(criteria);
streamThings.getSort().ifPresent(sort -> setOptions(sort, queryBuilder, command.getDittoHeaders()));
return queryBuilder.build();
} else {
return queryBuilderFactory.newUnlimitedBuilder(criteria).build();
}
});
}
use of org.eclipse.ditto.rql.query.criteria.Criteria in project ditto by eclipse.
the class ThingsSearchCursor method getNextPageFilterImpl.
/**
* Recursive implementation of {@code getNextPageFilter}.
*
* @param sortOptionEntries sort options of the parsed query.
* @param previousValues values of the fields in the sort options of a cursor marking its position.
* @param cf a criteria factory.
* @param i dimension to start generating criteria for.
* @return criteria starting from the ith dimension.
*/
private static Criteria getNextPageFilterImpl(final List<org.eclipse.ditto.rql.query.SortOption> sortOptionEntries, final JsonArray previousValues, final CriteriaFactory cf, final int i) {
final org.eclipse.ditto.rql.query.SortOption sortOption = sortOptionEntries.get(i);
final JsonValue previousValue = previousValues.get(i).orElse(JsonFactory.nullLiteral());
final Criteria ithDimensionCriteria = getDimensionLtCriteria(sortOption, previousValue, cf);
if (i + 1 >= sortOptionEntries.size()) {
return ithDimensionCriteria;
} else {
final Criteria nextDimension = getNextPageFilterImpl(sortOptionEntries, previousValues, cf, i + 1);
return getNextDimensionCriteria(ithDimensionCriteria, nextDimension, sortOption, previousValue, cf);
}
}
use of org.eclipse.ditto.rql.query.criteria.Criteria in project ditto by eclipse.
the class ComplexCriteriaIT method findAllWithOrCriteria.
@Test
public void findAllWithOrCriteria() {
final Criteria crit = cf.or(Arrays.asList(searchForValue(KNOWN_ATTRIBUTE_KEY_1), searchForValue(KNOWN_ATTRIBUTE_KEY_2)));
final Collection<ThingId> result = findForCriteria(crit);
assertThat(result).containsOnly(THING_ID_WITH_KEY_1_AND_2, THING_ID_WITH_KEY_1_ONLY, THING_ID_WITH_KEY_2_ONLY);
}
use of org.eclipse.ditto.rql.query.criteria.Criteria in project ditto by eclipse.
the class ExistsIT method existsByUnknownAttribute.
@Test
public void existsByUnknownAttribute() {
final Criteria crit = cf.existsCriteria(ef.existsByAttribute(THINGS_UNKNOWN_ATTR));
final Collection<ThingId> result = findForCriteria(crit);
assertThat(result).isEmpty();
}
Aggregations