@@ -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+
837866StatusOr<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+
859889TEST_F (ClientIntegrationTest, PartitionRead) {
860890 auto expected_rows = AddSingerDataToTable (*client_);
861891 ASSERT_STATUS_OK (expected_rows);
0 commit comments