Search in sources :

Example 1 with Filter

use of org.hypertrace.core.documentstore.query.Filter in project document-store by hypertrace.

the class MongoQueryExecutorIntegrationTest method testFindWithDuplicateSelections.

@Test
public void testFindWithDuplicateSelections() throws IOException {
    List<SelectionSpec> selectionSpecs = List.of(SelectionSpec.of(IdentifierExpression.of("item")), SelectionSpec.of(IdentifierExpression.of("item")), SelectionSpec.of(IdentifierExpression.of("price")), SelectionSpec.of(IdentifierExpression.of("quantity")), SelectionSpec.of(IdentifierExpression.of("quantity")), SelectionSpec.of(IdentifierExpression.of("date")));
    Selection selection = Selection.builder().selectionSpecs(selectionSpecs).build();
    Filter filter = Filter.builder().expression(RelationalExpression.of(IdentifierExpression.of("item"), NOT_IN, ConstantExpression.ofStrings(List.of("Soap", "Bottle")))).build();
    Query query = Query.builder().setSelection(selection).setFilter(filter).build();
    Iterator<Document> resultDocs = collection.find(query);
    assertDocsEqual(resultDocs, "mongo/simple_filter_response.json");
}
Also used : SelectionSpec(org.hypertrace.core.documentstore.query.SelectionSpec) Query(org.hypertrace.core.documentstore.query.Query) Filter(org.hypertrace.core.documentstore.query.Filter) Selection(org.hypertrace.core.documentstore.query.Selection) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Example 2 with Filter

use of org.hypertrace.core.documentstore.query.Filter in project document-store by hypertrace.

the class MongoQueryExecutorIntegrationTest method testFindWithDuplicateSortingAndPagination.

@Test
public void testFindWithDuplicateSortingAndPagination() throws IOException {
    List<SelectionSpec> selectionSpecs = List.of(SelectionSpec.of(IdentifierExpression.of("item")), SelectionSpec.of(IdentifierExpression.of("price")), SelectionSpec.of(IdentifierExpression.of("quantity")), SelectionSpec.of(IdentifierExpression.of("date")));
    Selection selection = Selection.builder().selectionSpecs(selectionSpecs).build();
    Filter filter = Filter.builder().expression(RelationalExpression.of(IdentifierExpression.of("item"), IN, ConstantExpression.ofStrings(List.of("Mirror", "Comb", "Shampoo", "Bottle")))).build();
    Sort sort = Sort.builder().sortingSpec(SortingSpec.of(IdentifierExpression.of("quantity"), DESC)).sortingSpec(SortingSpec.of(IdentifierExpression.of("item"), ASC)).sortingSpec(SortingSpec.of(IdentifierExpression.of("quantity"), DESC)).sortingSpec(SortingSpec.of(IdentifierExpression.of("item"), ASC)).build();
    Pagination pagination = Pagination.builder().offset(1).limit(3).build();
    Query query = Query.builder().setSelection(selection).setFilter(filter).setSort(sort).setPagination(pagination).build();
    Iterator<Document> resultDocs = collection.find(query);
    assertDocsEqual(resultDocs, "mongo/filter_with_sorting_and_pagination_response.json");
}
Also used : Pagination(org.hypertrace.core.documentstore.query.Pagination) SelectionSpec(org.hypertrace.core.documentstore.query.SelectionSpec) Query(org.hypertrace.core.documentstore.query.Query) Filter(org.hypertrace.core.documentstore.query.Filter) Selection(org.hypertrace.core.documentstore.query.Selection) Sort(org.hypertrace.core.documentstore.query.Sort) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Example 3 with Filter

use of org.hypertrace.core.documentstore.query.Filter in project entity-service by hypertrace.

the class FilterConverter method convert.

@Override
public Filter convert(final EntityQueryRequest request, final RequestContext requestContext) throws ConversionException {
    final org.hypertrace.entity.query.service.v1.Filter filter = request.getFilter();
    final FilterTypeExpression allFilters;
    if (org.hypertrace.entity.query.service.v1.Filter.getDefaultInstance().equals(filter)) {
        allFilters = extraFiltersApplier.getExtraFilters(request, requestContext);
    } else {
        final Converter<org.hypertrace.entity.query.service.v1.Filter, ? extends FilterTypeExpression> filterConverter = filterConverterFactory.getFilterConverter(filter.getOperator());
        final FilterTypeExpression filterTypeExpression = filterConverter.convert(filter, requestContext);
        allFilters = extraFiltersApplier.addExtraFilters(filterTypeExpression, request, requestContext);
    }
    return Filter.builder().expression(allFilters).build();
}
Also used : Filter(org.hypertrace.core.documentstore.query.Filter) FilterTypeExpression(org.hypertrace.core.documentstore.expression.type.FilterTypeExpression)

Example 4 with Filter

use of org.hypertrace.core.documentstore.query.Filter in project entity-service by hypertrace.

the class QueryConverter method convert.

@Override
public Query convert(final EntityQueryRequest request, final RequestContext requestContext) throws ConversionException {
    final QueryBuilder builder = Query.builder();
    setFieldIfNotEmpty(request.getSelectionList(), builder::setSelection, selectionConverter, requestContext);
    final Filter filter = filterConverter.convert(request, requestContext);
    builder.setFilter(filter);
    setFieldIfNotEmpty(getExpressionsForFromClause(request), builder::addFromClauses, fromClauseConverter, requestContext);
    setFieldIfNotEmpty(request.getGroupByList(), builder::setAggregation, groupByConverter, requestContext);
    setFieldIfNotEmpty(request.getOrderByList(), builder::setSort, orderByConverter, requestContext);
    if (request.getLimit() > 0 || request.getOffset() > 0) {
        final Pagination pagination = paginationBuilder.limit(request.getLimit()).offset(request.getOffset()).build();
        builder.setPagination(pagination);
    }
    return builder.build();
}
Also used : Pagination(org.hypertrace.core.documentstore.query.Pagination) Filter(org.hypertrace.core.documentstore.query.Filter) QueryBuilder(org.hypertrace.core.documentstore.query.Query.QueryBuilder)

Example 5 with Filter

use of org.hypertrace.core.documentstore.query.Filter in project document-store by hypertrace.

the class MongoQueryExecutorIntegrationTest method testFindWithSortingAndPagination.

@Test
public void testFindWithSortingAndPagination() throws IOException {
    List<SelectionSpec> selectionSpecs = List.of(SelectionSpec.of(IdentifierExpression.of("item")), SelectionSpec.of(IdentifierExpression.of("price")), SelectionSpec.of(IdentifierExpression.of("quantity")), SelectionSpec.of(IdentifierExpression.of("date")));
    Selection selection = Selection.builder().selectionSpecs(selectionSpecs).build();
    Filter filter = Filter.builder().expression(RelationalExpression.of(IdentifierExpression.of("item"), IN, ConstantExpression.ofStrings(List.of("Mirror", "Comb", "Shampoo", "Bottle")))).build();
    Sort sort = Sort.builder().sortingSpec(SortingSpec.of(IdentifierExpression.of("quantity"), DESC)).sortingSpec(SortingSpec.of(IdentifierExpression.of("item"), ASC)).build();
    Pagination pagination = Pagination.builder().offset(1).limit(3).build();
    Query query = Query.builder().setSelection(selection).setFilter(filter).setSort(sort).setPagination(pagination).build();
    Iterator<Document> resultDocs = collection.find(query);
    assertDocsEqual(resultDocs, "mongo/filter_with_sorting_and_pagination_response.json");
}
Also used : Pagination(org.hypertrace.core.documentstore.query.Pagination) SelectionSpec(org.hypertrace.core.documentstore.query.SelectionSpec) Query(org.hypertrace.core.documentstore.query.Query) Filter(org.hypertrace.core.documentstore.query.Filter) Selection(org.hypertrace.core.documentstore.query.Selection) Sort(org.hypertrace.core.documentstore.query.Sort) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Aggregations

Filter (org.hypertrace.core.documentstore.query.Filter)8 Selection (org.hypertrace.core.documentstore.query.Selection)6 Document (org.hypertrace.core.documentstore.Document)5 Query (org.hypertrace.core.documentstore.query.Query)5 SelectionSpec (org.hypertrace.core.documentstore.query.SelectionSpec)5 Test (org.junit.jupiter.api.Test)5 Pagination (org.hypertrace.core.documentstore.query.Pagination)3 Sort (org.hypertrace.core.documentstore.query.Sort)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 BasicDBObject (com.mongodb.BasicDBObject)1 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 Collectors.toUnmodifiableList (java.util.stream.Collectors.toUnmodifiableList)1 JSONDocument (org.hypertrace.core.documentstore.JSONDocument)1 FilterTypeExpression (org.hypertrace.core.documentstore.expression.type.FilterTypeExpression)1 QueryBuilder (org.hypertrace.core.documentstore.query.Query.QueryBuilder)1 AttributeValueList (org.hypertrace.entity.data.service.v1.AttributeValueList)1