Skip to content
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

spanner: ReadOnlyTransaction().ReadRowUsingIndex() #1035

Closed
majelbstoat opened this issue Jun 19, 2018 · 3 comments
Closed

spanner: ReadOnlyTransaction().ReadRowUsingIndex() #1035

majelbstoat opened this issue Jun 19, 2018 · 3 comments
Assignees
Labels
api: spanner Issues related to the Spanner API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@majelbstoat
Copy link

majelbstoat commented Jun 19, 2018

ReadRow is useful method for getting a single row. However, if you want to get all the columns of a single row using an index (a common case for unique fields, like, say finding a user by username), it's much harder. ReadUsingIndex requires that you define STORING for every column name, which is duplicative and brittle to maintain (remembering to add every new column as you go*) .

The alternative is to use a SELECT ... {FORCE_INDEX=index} statement, and call Query. Both this and ReadUsingIndex require the handling of an iterator which you need to process for just a single item, iterator.Done for Not Found etc.

It would be helpful if the APIs for such similar queries weren't so wildly different.

I would like to see ReadRowUsingIndex, which under the hood did the same kind of join as SELECT {FORCE_INDEX} query does, and which returns a single row (technically the first) as a result. I wouldn't even mind if it was enforced that you could only call this on a UNIQUE index. This would dramatically reduce boilerplate, which already has to be quite substantial due to Go's lack of generics.

--

(* meta-point, for those cases where I really do want to do this, I'd love to see a language extension like STORING ALL or something similar. DynamoDB offers this for its Global Indices, for example.)

@JustinBeckwith JustinBeckwith added the triage me I really want to be triaged. label Jun 19, 2018
@jba
Copy link
Contributor

jba commented Jun 19, 2018

Thanks for your suggestion.

@snehashah16 thoughts?

@jba jba added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Jun 19, 2018
@jba jba self-assigned this Jun 19, 2018
@JustinBeckwith JustinBeckwith removed the triage me I really want to be triaged. label Jun 19, 2018
@jeanbza jeanbza unassigned jba Oct 19, 2018
@snehashah16
Copy link

One other way to make this easy, expose the ExecuteQuery (non streaming) version to avoid iterating on resultSets.

@enocom enocom added the api: spanner Issues related to the Spanner API. label Oct 26, 2018
@odeke-em odeke-em changed the title Feature Request: spanner.ReadOnlyTransaction().ReadRowUsingIndex() spanner: ReadOnlyTransaction().ReadRowUsingIndex() Jul 31, 2019
@odeke-em
Copy link
Contributor

Thank you for this report! @AlisskaPie and @IlyaFaer are working on this with CL https://code-review.googlesource.com/c/gocloud/+/43190

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

8 participants