Search in sources :

Example 1 with SelectionSpec

use of org.hypertrace.core.documentstore.query.SelectionSpec 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 SelectionSpec

use of org.hypertrace.core.documentstore.query.SelectionSpec 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 SelectionSpec

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

the class MongoQueryExecutorIntegrationTest method testFindWithNestedFields.

@Test
public void testFindWithNestedFields() throws IOException {
    List<SelectionSpec> selectionSpecs = List.of(SelectionSpec.of(IdentifierExpression.of("item")), SelectionSpec.of(IdentifierExpression.of("price")), SelectionSpec.of(IdentifierExpression.of("props.seller.name"), "seller"), SelectionSpec.of(IdentifierExpression.of("props.brand")), SelectionSpec.of(IdentifierExpression.of("props.seller.address.city")));
    Query query = Query.builder().addSelections(selectionSpecs).setFilter(LogicalExpression.builder().operand(RelationalExpression.of(IdentifierExpression.of("item"), IN, ConstantExpression.ofStrings(List.of("Mirror", "Comb", "Shampoo")))).operator(OR).operand(RelationalExpression.of(IdentifierExpression.of("props.seller.address.pincode"), EQ, ConstantExpression.of(700007))).build()).addSort(IdentifierExpression.of("props.brand"), ASC).addSort(IdentifierExpression.of("item"), ASC).addSort(IdentifierExpression.of("props.seller.address.city"), ASC).build();
    Iterator<Document> resultDocs = collection.find(query);
    assertDocsEqual(resultDocs, "mongo/filter_on_nested_fields_response.json");
}
Also used : SelectionSpec(org.hypertrace.core.documentstore.query.SelectionSpec) Query(org.hypertrace.core.documentstore.query.Query) Document(org.hypertrace.core.documentstore.Document) Test(org.junit.jupiter.api.Test)

Example 4 with SelectionSpec

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

the class MongoSelectionsUpdatingTransformer method transform.

@Override
public Query transform(final Query query) {
    List<SelectionSpec> newSpecs = new ArrayList<>();
    for (SelectionSpec spec : query.getSelections()) {
        MongoSelectionsUpdatingTransformation transformer = new MongoSelectionsUpdatingTransformation(query.getAggregations(), spec);
        SelectionSpec newSpec = spec.getExpression().accept(transformer);
        newSpecs.add(newSpec);
    }
    return new TransformedQueryBuilder(query).setSelections(newSpecs).build();
}
Also used : TransformedQueryBuilder(org.hypertrace.core.documentstore.query.transform.TransformedQueryBuilder) SelectionSpec(org.hypertrace.core.documentstore.query.SelectionSpec) ArrayList(java.util.ArrayList)

Example 5 with SelectionSpec

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

the class SelectionConverter method convert.

@Override
public Selection convert(final List<Expression> expressions, final RequestContext requestContext) throws ConversionException {
    final List<SelectionSpec> specs = new ArrayList<>();
    for (final Expression expression : expressions) {
        final SelectionSpec selectingSpec = getSpec(expression, requestContext);
        specs.add(selectingSpec);
    }
    return Selection.builder().selectionSpecs(specs).build();
}
Also used : SelectionSpec(org.hypertrace.core.documentstore.query.SelectionSpec) SelectTypeExpression(org.hypertrace.core.documentstore.expression.type.SelectTypeExpression) Expression(org.hypertrace.entity.query.service.v1.Expression) ArrayList(java.util.ArrayList)

Aggregations

SelectionSpec (org.hypertrace.core.documentstore.query.SelectionSpec)9 Query (org.hypertrace.core.documentstore.query.Query)6 Test (org.junit.jupiter.api.Test)6 Document (org.hypertrace.core.documentstore.Document)5 Filter (org.hypertrace.core.documentstore.query.Filter)5 Selection (org.hypertrace.core.documentstore.query.Selection)5 ArrayList (java.util.ArrayList)3 SelectTypeExpression (org.hypertrace.core.documentstore.expression.type.SelectTypeExpression)2 Pagination (org.hypertrace.core.documentstore.query.Pagination)2 Sort (org.hypertrace.core.documentstore.query.Sort)2 TransformedQueryBuilder (org.hypertrace.core.documentstore.query.transform.TransformedQueryBuilder)2 BasicDBObject (com.mongodb.BasicDBObject)1 Expression (org.hypertrace.entity.query.service.v1.Expression)1