Skip to content

Commit f30988e

Browse files
committed
fix formatting; include integration testing
1 parent 9fd6445 commit f30988e

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

google/cloud/spanner/client.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ RowStream Client::Read(Transaction::SingleUseOptions transaction_options,
6868
std::vector<std::string> columns, Options opts) {
6969
opts = internal::MergeOptions(std::move(opts), opts_);
7070
auto directed_read_option = ExtractOpt<DirectedReadOption>(opts);
71-
auto order_by= ExtractOpt<OrderByOption>(opts);
71+
auto order_by = ExtractOpt<OrderByOption>(opts);
7272

7373
internal::OptionsSpan span(std::move(opts));
7474
return conn_->Read({spanner_internal::MakeSingleUseTransaction(
@@ -83,7 +83,7 @@ RowStream Client::Read(Transaction transaction, std::string table, KeySet keys,
8383
std::vector<std::string> columns, Options opts) {
8484
opts = internal::MergeOptions(std::move(opts), opts_);
8585
auto directed_read_option = ExtractOpt<DirectedReadOption>(opts);
86-
auto order_by= ExtractOpt<OrderByOption>(opts);
86+
auto order_by = ExtractOpt<OrderByOption>(opts);
8787
internal::OptionsSpan span(std::move(opts));
8888
return conn_->Read({std::move(transaction), std::move(table), std::move(keys),
8989
std::move(columns),
@@ -98,8 +98,7 @@ RowStream Client::Read(ReadPartition const& read_partition, Options opts) {
9898
auto order_by = ExtractOpt<OrderByOption>(opts);
9999
internal::OptionsSpan span(std::move(opts));
100100
return conn_->Read(spanner_internal::MakeReadParams(
101-
read_partition, std::move(directed_read_option),
102-
std::move(order_by)));
101+
read_partition, std::move(directed_read_option), std::move(order_by)));
103102
}
104103

105104
StatusOr<std::vector<ReadPartition>> Client::PartitionRead(

google/cloud/spanner/integration_tests/client_integration_test.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ class ClientIntegrationTest : public spanner_testing::DatabaseIntegrationTest {
8787
spanner_testing::DatabaseIntegrationTest::TearDownTestSuite();
8888
}
8989

90+
static void InsertUnorderedSingers() {
91+
auto commit_result = client_->Commit(
92+
Mutations{InsertMutationBuilder("Singers",
93+
{"SingerId", "FirstName", "LastName"})
94+
.EmplaceRow(3, "test-fname-3", "test-lname-3")
95+
.EmplaceRow(1, "test-fname-1", "test-lname-1")
96+
.EmplaceRow(2, "test-fname-2", "test-lname-2")
97+
.Build()},
98+
Options{}.set<GrpcCompressionAlgorithmOption>(GRPC_COMPRESS_DEFLATE));
99+
ASSERT_STATUS_OK(commit_result);
100+
}
101+
90102
static std::unique_ptr<Client> client_;
91103
};
92104

@@ -834,6 +846,23 @@ TEST_F(ClientIntegrationTest, DirectedReadWithinReadWriteTransaction) {
834846
"in a read-only transaction")));
835847
}
836848

849+
/// @test Verify that Read() returns rows ordered by primary key.
850+
TEST_F(ClientIntegrationTest, ReadWithOrderByPrimaryKey) {
851+
ASSERT_NO_FATAL_FAILURE(InsertUnorderedSingers());
852+
853+
auto rows = client_->Read(
854+
"Singers", KeySet::All(), {"SingerId", "FirstName", "LastName"},
855+
Options{}.set<OrderByOption>(OrderBy::kOrderByPrimaryKey));
856+
857+
using RowType = std::tuple<std::int64_t, std::string, std::string>;
858+
std::vector<std::int64_t> actual_singer_ids;
859+
for (auto& row : StreamOf<RowType>(rows)) {
860+
if (!row) break;
861+
actual_singer_ids.push_back(std::get<0>(*row));
862+
}
863+
EXPECT_THAT(actual_singer_ids, ::testing::ElementsAre(1, 2, 3));
864+
}
865+
837866
StatusOr<std::vector<std::vector<Value>>> AddSingerDataToTable(Client client) {
838867
std::vector<std::vector<Value>> expected_rows;
839868
auto commit = client.Commit(
@@ -856,6 +885,7 @@ StatusOr<std::vector<std::vector<Value>>> AddSingerDataToTable(Client client) {
856885
return expected_rows;
857886
}
858887

888+
859889
TEST_F(ClientIntegrationTest, PartitionRead) {
860890
auto expected_rows = AddSingerDataToTable(*client_);
861891
ASSERT_STATUS_OK(expected_rows);

0 commit comments

Comments
 (0)