Search in sources :

Example 1 with Criteria

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());
}
Also used : DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria)

Example 2 with Criteria

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();
        }
    });
}
Also used : InvalidOptionException(org.eclipse.ditto.thingsearch.model.signals.commands.exceptions.InvalidOptionException) QueryBuilder(org.eclipse.ditto.rql.query.QueryBuilder) SudoCountThings(org.eclipse.ditto.thingsearch.api.commands.sudo.SudoCountThings) QueryFilterCriteriaFactory(org.eclipse.ditto.rql.query.filter.QueryFilterCriteriaFactory) CriteriaFactory(org.eclipse.ditto.rql.query.criteria.CriteriaFactory) ParserException(org.eclipse.ditto.rql.model.ParserException) Set(java.util.Set) CompletableFuture(java.util.concurrent.CompletableFuture) QueryBuilderFactory(org.eclipse.ditto.rql.query.QueryBuilderFactory) ThingsFieldExpressionFactory(org.eclipse.ditto.rql.query.expression.ThingsFieldExpressionFactory) RqlPredicateParser(org.eclipse.ditto.rql.parser.RqlPredicateParser) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) CompletionStage(java.util.concurrent.CompletionStage) PredicateParser(org.eclipse.ditto.rql.model.predicates.PredicateParser) ThingSearchQueryCommand(org.eclipse.ditto.thingsearch.model.signals.commands.query.ThingSearchQueryCommand) Query(org.eclipse.ditto.rql.query.Query) RqlOptionParser(org.eclipse.ditto.rql.parser.thingsearch.RqlOptionParser) QueryCriteriaValidator(org.eclipse.ditto.thingsearch.service.persistence.query.validation.QueryCriteriaValidator) ParameterOptionVisitor(org.eclipse.ditto.thingsearch.api.query.filter.ParameterOptionVisitor) StreamThings(org.eclipse.ditto.thingsearch.model.signals.commands.query.StreamThings) QueryThings(org.eclipse.ditto.thingsearch.model.signals.commands.query.QueryThings) QueryThings(org.eclipse.ditto.thingsearch.model.signals.commands.query.QueryThings) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria) QueryBuilder(org.eclipse.ditto.rql.query.QueryBuilder) StreamThings(org.eclipse.ditto.thingsearch.model.signals.commands.query.StreamThings)

Example 3 with Criteria

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);
    }
}
Also used : JsonValue(org.eclipse.ditto.json.JsonValue) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria)

Example 4 with Criteria

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);
}
Also used : ThingId(org.eclipse.ditto.things.model.ThingId) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria) Test(org.junit.Test)

Example 5 with Criteria

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();
}
Also used : ThingId(org.eclipse.ditto.things.model.ThingId) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria) Test(org.junit.Test)

Aggregations

Criteria (org.eclipse.ditto.rql.query.criteria.Criteria)57 Test (org.junit.Test)50 ThingId (org.eclipse.ditto.things.model.ThingId)44 SingleComparisonNode (org.eclipse.ditto.rql.model.predicates.ast.SingleComparisonNode)8 DittoHeaders (org.eclipse.ditto.base.model.headers.DittoHeaders)5 Set (java.util.Set)4 List (java.util.List)3 Optional (java.util.Optional)3 Nullable (javax.annotation.Nullable)3 Signal (org.eclipse.ditto.base.model.signals.Signal)3 CommandResponse (org.eclipse.ditto.base.model.signals.commands.CommandResponse)3 RqlPredicateParser (org.eclipse.ditto.rql.parser.RqlPredicateParser)3 QueryFilterCriteriaFactory (org.eclipse.ditto.rql.query.filter.QueryFilterCriteriaFactory)3 Done (akka.Done)2 ActorRef (akka.actor.ActorRef)2 Props (akka.actor.Props)2 Collections (java.util.Collections)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletionStage (java.util.concurrent.CompletionStage)2 Predicate (java.util.function.Predicate)2