Skip to content

Distinct fields in CouchbaseRepository methods are ignored by Couchbase N1ql statement generator #1200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
khanium opened this issue Aug 20, 2021 · 1 comment · Fixed by #1202
Labels
type: enhancement A general enhancement

Comments

@khanium
Copy link

khanium commented Aug 20, 2021

Distinct fields in CouchbaseRepository methods are ignored by Couchbase N1ql statement generator

@Repository
public interface ComponentRepository extends CouchbaseRepository<Component, String> {

  List<Component> findDistinctNameByCreator(String creator); 

}

As a workaround, you can create inline @query and add DISTINCT clause and empty __id and __cas values:

    @Query("SELECT DISTINCT ' ' as `__id`, 0 as `__cas`, name from #{#n1ql.bucket} WHERE #{#n1ql.filter} AND `creator` = $1 ")
    List<Component> findDistinctNameByCreator(String creator);

The expectation is to receive the same output as CouchbaseTemplate does:

return template.findByQuery(Component.class)
                .distinct(DISTINCT_NAME)
                .matching(QueryCriteria.where("creator").eq(creator))
                .all();

Request:
Take into consideration the Distinct fields for generating dynamic n1ql queries from repository methods.

@mikereiche
Copy link
Collaborator

BTW - such a method name without a predicate (i.e. findDistinctIcao()) fails to generate a derived method. findAllDistinctIcao() also fails. This is an issue with the framework, not spring-data-couchbase.

@mikereiche mikereiche added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 20, 2021
mikereiche added a commit that referenced this issue Aug 21, 2021
mikereiche added a commit that referenced this issue Aug 23, 2021
…1202)

Support derived queries from methods named findDistinctF1AndF2ByF3().

Closes #1200.
@mikereiche mikereiche added this to the 4.3 M3 (2021.1.0) milestone Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
3 participants