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");
}
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");
}
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();
}
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();
}
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");
}
Aggregations