Skip to content

add @Query expressions for n1ql.scope and n1ql.collection and stop overloading n1ql.bucket with the collection name #1445

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
mikereiche opened this issue May 26, 2022 · 0 comments · Fixed by #1460

Comments

@mikereiche
Copy link
Collaborator

mikereiche commented May 26, 2022

Arun Vijayraghavan Today at 11:20 AM
Hello Team need some info, in elixir the proposal is that the bucket name will be dynamically generated , what it means to us is that bucket name could be different for example foo can be foo_xyz123 in dev
foo_abc234 in test and foo_lol777 in prod
My question is what are the areas in Spring Data that a bucket name is used and will warrant a developer to make code changes if the bucket name was hardcoded.
As an example, in SDK bootstrapping requires a bucket name and that will need to be changed.
We know today that connection string . username . password changes but other than that with this proposed change what would be the impact on developers code (edited)

4 replies

Michael Reiche 1 hour ago
are n1ql joins possible across scopes? [edit: yes]. Across buckets? [edit: yes] (edited)

Michael Reiche 1 hour ago
The integration tests use a generated bucket name, so we have lots of experience with this.
The obvious is that developers cannot hard-code the bucketName (for instance in an @query they should be using the #{#n1ql.bucket) instead of hard-coding the bucket name ). They should be using that anyway.
There is one case to consider, let’s see… when using scopes and collections - in order to be backwards compatible with @queries that used #{#n1ql.bucket} and did not use scopes and queries - #{#n1ql.bucket} returns the collection name (which comes from an annotation or an option) and uses a query_context of bucket.scope. That by itself is fine, but if they want to join with a different collection then that other collection must be hard-coded in the @query. "SELECT FROM #{#n1ql.bucket} , other_collection where …" I guess this is ok - the first collection will be the one from #{#n1ql.bucket, and the other collection will be other_collection (in the same bucket). We should probably add a #{#n1ql.collection} to use instead of the overloaded #{#n1ql.bucket}.
For joins across scopes, the keyspace name in the second scope would need to be fully specified as bucket.scope.collection. Since #{#n1ql.bucket} is overloaded to be the collection name, there is no expression for the bucketname. So this case would be broken. (it’s kind of already broken as the bucketname of the second bucket.scope.collection needs to be hard-coded, but with generated bucketnames it would really be broken as hard-coding is not an option). The solution would be to stop overloading n1ql.bucket with the collection name and create a new n1ql.collection. (and n1ql.scope would be nice, too) . Since this would be a breaking-change, it would be good to target for the spring-data-couchbase 5.x release.
A hack/workaround would be to get the bucketname from template.getCouchbaseClientFactory().getBucket().name(), and add a buckeName parameter to the query and use it in the query as #{#[]} (edited)

@mikereiche mikereiche added this to the 5.0 M5 (2022.0.0) milestone May 26, 2022
mikereiche added a commit that referenced this issue Jun 14, 2022
This adds n1ql.scope and n1ql.collection spel expressions for
@query so that n1ql.bucket doesn't need to be overloaded with
the collection name. This will make the bucket name available
in n1q.bucket.

This is a breaking change as queries that used n1ql.bucket to
get the collection name (especially in the case of pre-scope-
and-collection @queries that (a) referenced n1ql.bucket instead
of referencing other spel expressions that include the
bucket/collection name; and (b)  still worked after the
repository was moved from a bucket onto a collection by
virtue of n1ql.bucket having the value of the collection in
such instances.

Closes #1445.
mikereiche added a commit that referenced this issue Jun 16, 2022
This adds n1ql.scope and n1ql.collection spel expressions for
@query so that n1ql.bucket doesn't need to be overloaded with
the collection name. This will make the bucket name available
in n1q.bucket.

This is a breaking change as queries that used n1ql.bucket to
get the collection name (especially in the case of pre-scope-
and-collection @queries that (a) referenced n1ql.bucket instead
of referencing other spel expressions that include the
bucket/collection name; and (b)  still worked after the
repository was moved from a bucket onto a collection by
virtue of n1ql.bucket having the value of the collection in
such instances.

Closes #1445.
mikereiche added a commit that referenced this issue Jun 16, 2022
This adds n1ql.scope and n1ql.collection spel expressions for
@query so that n1ql.bucket doesn't need to be overloaded with
the collection name. This will make the bucket name available
in n1q.bucket.

This is a breaking change as queries that used n1ql.bucket to
get the collection name (especially in the case of pre-scope-
and-collection @queries that (a) referenced n1ql.bucket instead
of referencing other spel expressions that include the
bucket/collection name; and (b)  still worked after the
repository was moved from a bucket onto a collection by
virtue of n1ql.bucket having the value of the collection in
such instances.

Closes #1445.
mikereiche added a commit that referenced this issue Jun 17, 2022
The scope and collection from the repository annotation are associated with
the method call by CrudMethodMetadataProcessor. This will also need #1445 to
work.

Closes #1441.
mikereiche added a commit that referenced this issue Jun 17, 2022
The scope and collection from the repository annotation are associated with
the method call by CrudMethodMetadataProcessor. This will also need #1445 to
work.

Closes #1441.
mikereiche added a commit that referenced this issue Jun 17, 2022
The scope and collection from the repository annotation are associated with
the method call by CrudMethodMetadataProcessor. This will also need #1445 to
work.

Closes #1441.
mikereiche added a commit that referenced this issue Jun 17, 2022
The scope and collection from the repository annotation are associated with
the method call by CrudMethodMetadataProcessor. This will also need #1445 to
work.

Closes #1441.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant