Skip to content

Commit 5778b63

Browse files
olavloiteaverikitsch
authored andcommitted
fix: Add ORDER BY to guarantee output order (GoogleCloudPlatform#1903)
1 parent b3a3143 commit 5778b63

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

spanner/cloud-client/src/main/java/com/example/spanner/SpannerSample.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ static class Venue {
168168

169169
// [START spanner_insert_datatypes_data]
170170
static Value availableDates1 = Value.dateArray(Arrays.asList(
171-
Date.parseDate("2020-12-01"),
171+
Date.parseDate("2020-12-01"),
172172
Date.parseDate("2020-12-02"),
173173
Date.parseDate("2020-12-03")));
174174
static Value availableDates2 = Value.dateArray(Arrays.asList(
175-
Date.parseDate("2020-11-01"),
175+
Date.parseDate("2020-11-01"),
176176
Date.parseDate("2020-11-05"),
177177
Date.parseDate("2020-11-15")));
178178
static Value availableDates3 = Value.dateArray(Arrays.asList(
@@ -185,7 +185,7 @@ static class Venue {
185185
Arrays.asList(
186186
new Venue(4, "Venue 4", exampleBytes1, 1800,
187187
availableDates1, "2018-09-02", false, 0.85543f),
188-
new Venue(19, "Venue 19", exampleBytes2, 6300,
188+
new Venue(19, "Venue 19", exampleBytes2, 6300,
189189
availableDates2, "2019-01-15", true, 0.98716f),
190190
new Venue(42, "Venue 42", exampleBytes3, 3000,
191191
availableDates3, "2018-10-01", false, 0.72598f));
@@ -328,7 +328,7 @@ static void deleteExampleData(DatabaseClient dbClient) {
328328

329329
// [START spanner_query_data]
330330
static void query(DatabaseClient dbClient) {
331-
try (ResultSet resultSet = dbClient
331+
try (ResultSet resultSet = dbClient
332332
.singleUse() // Execute a single read or query against Cloud Spanner.
333333
.executeQuery(Statement.of("SELECT SingerId, AlbumId, AlbumTitle FROM Albums"))) {
334334
while (resultSet.next()) {
@@ -459,7 +459,7 @@ public Void run(TransactionContext transaction) throws Exception {
459459
// [START spanner_query_data_with_new_column]
460460
static void queryMarketingBudget(DatabaseClient dbClient) {
461461
// Rows without an explicit value for MarketingBudget will have a MarketingBudget equal to
462-
// null. A try-with-resource block is used to automatically release resources held by
462+
// null. A try-with-resource block is used to automatically release resources held by
463463
// ResultSet.
464464
try (ResultSet resultSet = dbClient
465465
.singleUse()
@@ -834,7 +834,8 @@ static void queryWithArrayOfStruct(DatabaseClient dbClient) {
834834
Statement.newBuilder(
835835
"SELECT SingerId FROM Singers WHERE "
836836
+ "STRUCT<FirstName STRING, LastName STRING>(FirstName, LastName) "
837-
+ "IN UNNEST(@names)")
837+
+ "IN UNNEST(@names) "
838+
+ "ORDER BY SingerId DESC")
838839
.bind("names")
839840
.toStructArray(nameType, bandMembers)
840841
.build();
@@ -1009,8 +1010,8 @@ public Void run(TransactionContext transaction) throws Exception {
10091010
try (ResultSet resultSet = transaction.executeQuery(Statement.of(sql))) {
10101011
while (resultSet.next()) {
10111012
System.out.printf(
1012-
"%s %s\n",
1013-
resultSet.getString("FirstName"),
1013+
"%s %s\n",
1014+
resultSet.getString("FirstName"),
10141015
resultSet.getString("LastName"));
10151016
}
10161017
}
@@ -1255,7 +1256,7 @@ static void writeDatatypesData(DatabaseClient dbClient) {
12551256
// [START spanner_query_with_array_parameter]
12561257
static void queryWithArray(DatabaseClient dbClient) {
12571258
Value exampleArray = Value.dateArray(Arrays.asList(
1258-
Date.parseDate("2020-10-01"),
1259+
Date.parseDate("2020-10-01"),
12591260
Date.parseDate("2020-11-01")));
12601261

12611262
Statement statement =
@@ -1319,7 +1320,7 @@ static void queryWithBytes(DatabaseClient dbClient) {
13191320
resultSet.getString("VenueName"));
13201321
}
13211322
}
1322-
}
1323+
}
13231324
// [END spanner_query_with_bytes_parameter]
13241325

13251326
// [START spanner_query_with_date_parameter]

0 commit comments

Comments
 (0)