弹簧数据cosmosdb库中不支持的cosmosdb的分页的抵消

发布于 2025-01-21 23:03:14 字数 1802 浏览 0 评论 0 原文

我正在尝试通过分页从 cosmostemplate.pagination.query()获取数据,但是问题是我没有从分页对象中设置的偏移中获取数据。以下是我用于设置分页的代码,

DocumentQuery documentQuery = new DocumentQuery(criteriaList, CriteriaType.AND));
if (Objects.nonNull(Offset) && Objects.nonNull(limit)) {
    PageRequest cosmosPageRequest = CosmosPageRequest.of(Offset, limit);        
    documentQuery.with(cosmosPageRequest);     
    Page<User> page = cosmosTemplate.paginationQuery(documentQuery, User.class, COLLECTION_NAME);
...
}

这总是会返回使用第一组对象的列表。因此,例如,当我将偏移设置为11并限制10时,它总是将我的记录返回,偏移0到10。我也尝试查看库,但在检索记录时也没有设置偏移的位置。以下是同一形式的代码Azure-cosmosdb库 AbstractQueryGenerator.generatecosmosquery()

    protected SqlQuerySpec generateCosmosQuery(@NonNull CosmosQuery query,
                                           @NonNull String queryHead) {
    final Pair<String, List<Pair<String, Object>>> queryBody = generateQueryBody(query);
    String queryString = String.join(" ", queryHead, queryBody.getFirst(), generateQueryTail(query));
    final List<Pair<String, Object>> parameters = queryBody.getSecond();

    List<SqlParameter> sqlParameters = parameters.stream()
                                                 .map(p -> new SqlParameter("@" + p.getFirst(),
                                                     toCosmosDbValue(p.getSecond())))
                                                 .collect(Collectors.toList());

    if (query.getLimit() > 0) {
        queryString = new StringBuilder(queryString)
            .append("OFFSET 0 LIMIT ")
            .append(query.getLimit()).toString();
    }

    return new SqlQuerySpec(queryString, sqlParameters);
}

在此处也完成了偏移的硬编码,而不是从分页对象中取出。任何人都可以建议我在此库中不支持我做错了什么或根据偏移获得记录。

I am trying to get data by pagination from CosmosTemplate.paginationQuery(), but the problem is I am not getting data from the offset that I am setting in pagination object. Below is my code for setting pagination,

DocumentQuery documentQuery = new DocumentQuery(criteriaList, CriteriaType.AND));
if (Objects.nonNull(Offset) && Objects.nonNull(limit)) {
    PageRequest cosmosPageRequest = CosmosPageRequest.of(Offset, limit);        
    documentQuery.with(cosmosPageRequest);     
    Page<User> page = cosmosTemplate.paginationQuery(documentQuery, User.class, COLLECTION_NAME);
...
}

This always returns me list with first set of objects. So for example when I am setting offset as 11 and limit 10, it is always returning me records with offset 0 to 10. I tried to check library as well but there also no where they are setting offset while retrieving records. Below is the code for the same form azure-cosmosdb library AbstractQueryGenerator.generateCosmosQuery().

    protected SqlQuerySpec generateCosmosQuery(@NonNull CosmosQuery query,
                                           @NonNull String queryHead) {
    final Pair<String, List<Pair<String, Object>>> queryBody = generateQueryBody(query);
    String queryString = String.join(" ", queryHead, queryBody.getFirst(), generateQueryTail(query));
    final List<Pair<String, Object>> parameters = queryBody.getSecond();

    List<SqlParameter> sqlParameters = parameters.stream()
                                                 .map(p -> new SqlParameter("@" + p.getFirst(),
                                                     toCosmosDbValue(p.getSecond())))
                                                 .collect(Collectors.toList());

    if (query.getLimit() > 0) {
        queryString = new StringBuilder(queryString)
            .append("OFFSET 0 LIMIT ")
            .append(query.getLimit()).toString();
    }

    return new SqlQuerySpec(queryString, sqlParameters);
}

Over here also hard coding for offset is done instead of taking from pagination object. Please can anyone suggest if I am doing anything wrong or getting records based on offset is not supported in this library.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丢了幸福的猪 2025-01-28 23:03:14

这是Azure-Spring-Data-Cosmos SDK中的一个错误,它不符合 offset 作为 cosmospagerequest 的一部分,并且始终将其设置为0。
目前正在调查它,并将很快修复。遵循此问题以获取更新 - https://github.com/azure.com/azure/ Azure-sdk-for-java/essess/28032

然而,作为解决方法,最好的方法是使用本示例中提到的查询注释使用自定义查询 - offset的使用 -

查询注释 -

This is a bug in the azure-spring-data-cosmos SDK, where it does not honor the OFFSET as part of CosmosPageRequest and always set it to 0.
It is currently being investigated and will be fixed soon. Follow this issue for updates - https://github.com/Azure/azure-sdk-for-java/issues/28032

However, as a workaround for now, the best way would be to use a custom query using query annotation as mentioned in this example - Usage of offset - https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/integration/ContactRepositoryIT.java#L235

Query annotation - https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/repository/ContactRepository.java#L39

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文