Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

feat: add function to get a single row from a range #1074

Merged
merged 1 commit into from
Nov 17, 2019

Conversation

devjgm
Copy link
Contributor

@devjgm devjgm commented Nov 17, 2019

Fixes: #386

This is just a convenience, but it seems nice in some cases. I found on
example that could use this in our current code. I also have another one
in an upcoming PR where I would like this.

Do we like this? Or do we have a better API to consider?


This change is Reviewable

@devjgm devjgm requested a review from coryan November 17, 2019 19:11
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 17, 2019
@devjgm devjgm changed the title feat: add function to get a single row from a range. feat: add function to get a single row from a range Nov 17, 2019
Copy link
Contributor

@coryan coryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, and I cannot think of a better one.

Reviewed 3 of 3 files at r1.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Fixes: googleapis#386

This is just a convenience, but it seems nice in some cases. I found on
example that could use this in our current code. I also have another one
in an upcoming PR where I would like this.
@codecov
Copy link

codecov bot commented Nov 17, 2019

Codecov Report

Merging #1074 into master will decrease coverage by 0.43%.
The diff coverage is 95.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1074      +/-   ##
==========================================
- Coverage      92%   91.56%   -0.44%     
==========================================
  Files         162      163       +1     
  Lines       11807    11826      +19     
==========================================
- Hits        10863    10829      -34     
- Misses        944      997      +53
Impacted Files Coverage Δ
google/cloud/spanner/samples/samples.cc 75.51% <100%> (+0.16%) ⬆️
google/cloud/spanner/row_test.cc 100% <100%> (ø) ⬆️
google/cloud/spanner/row.h 88.31% <75%> (-0.73%) ⬇️
.../spanner/benchmarks/multiple_rows_cpu_benchmark.cc 65.02% <0%> (-12.63%) ⬇️
google/cloud/spanner/internal/spanner_stub.cc 69.23% <0%> (-1.1%) ⬇️
...anner/integration_tests/client_integration_test.cc 99.45% <0%> (-0.01%) ⬇️
google/cloud/spanner/keys.h 100% <0%> (ø) ⬆️
google/cloud/spanner/database_admin_connection.h 100% <0%> (ø)
google/cloud/spanner/internal/retry_loop.h 100% <0%> (+4.54%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4a1bcc8...6ce93c6. Read the comment docs.

@devjgm devjgm merged commit 0f4392f into googleapis:master Nov 17, 2019
@devjgm devjgm deleted the feat-next-row branch November 17, 2019 21:30
devjgm added a commit that referenced this pull request Nov 21, 2019
After some discussion with the local folks, we decided to change the semantics and name of GetCurrentRow that was added in #1074. Previously GetCurrentRow would return the first row in a range that might potentially contain multiple rows. The observation is that those may not be the best or safest semantics for callers.

The use case we're trying to address is when a callers does a query/read and they know that only one row should be returned. Maybe they used LIMIT 1, or maybe they specified a primary key to guarantee this. In any case, if they know that only one result can be returned, it would be nice to let them conveniently access that one row without having to create a loop, break out, etc.

The problem with GetCurrentRow was that if the row range happened to have more than one row, there would be no error and the user may never notice this. So it seems safer to clearly name this function and change its semantics so that it will produce an error if the given range does not contain exactly a single row.

We also considered requiring the caller to pass an rvalue (i.e., std::move the range into the argument). The reason I don't enforce this is because that would then prevent callers for subsequently calling the RowStream::ReadTimestamp function.

Adding @devbww as the reviewer since he initially raised some of these questions. And cc: @coryan and @mr-salty as potentially interested observers who are welcome to comment if they want.
devjgm added a commit to devjgm/google-cloud-cpp that referenced this pull request May 7, 2020
…e-cloud-cpp-spanner#1074)

* feat: add function to get a single row from a range

Fixes: googleapis/google-cloud-cpp-spanner#386

This is just a convenience, but it seems nice in some cases. I found on
example that could use this in our current code. I also have another one
in an upcoming PR where I would like this.
devjgm added a commit to devjgm/google-cloud-cpp that referenced this pull request May 7, 2020
…-cpp-spanner#1092)

After some discussion with the local folks, we decided to change the semantics and name of GetCurrentRow that was added in googleapis/google-cloud-cpp-spanner#1074. Previously GetCurrentRow would return the first row in a range that might potentially contain multiple rows. The observation is that those may not be the best or safest semantics for callers.

The use case we're trying to address is when a callers does a query/read and they know that only one row should be returned. Maybe they used LIMIT 1, or maybe they specified a primary key to guarantee this. In any case, if they know that only one result can be returned, it would be nice to let them conveniently access that one row without having to create a loop, break out, etc.

The problem with GetCurrentRow was that if the row range happened to have more than one row, there would be no error and the user may never notice this. So it seems safer to clearly name this function and change its semantics so that it will produce an error if the given range does not contain exactly a single row.

We also considered requiring the caller to pass an rvalue (i.e., std::move the range into the argument). The reason I don't enforce this is because that would then prevent callers for subsequently calling the RowStream::ReadTimestamp function.

Adding @devbww as the reviewer since he initially raised some of these questions. And cc: @coryan and @mr-salty as potentially interested observers who are welcome to comment if they want.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider a Client::ReadRow() function.
3 participants