Skip to content

chore(spanner): use DeliverTime column and RECEIVE_MyQueue TVF in queue - #14354

Merged
sakthivelmanii merged 2 commits into
mainfrom
fix-spanner-queue-sample-columns
Sep 11, 2026
Merged

sakthivelmanii merged 2 commits into
mainfrom
fix-spanner-queue-sample-columns

Conversation

@sakthivelmanii

Copy link
Copy Markdown
Contributor

No description provided.

@sakthivelmanii
sakthivelmanii requested review from a team as code owners September 11, 2026 14:28
@sakthivelmanii sakthivelmanii changed the title chore(spanner): use DeliverTime column and RECEIVE_MyQueue TVF in que… chore(spanner): use DeliverTime column and RECEIVE_MyQueue TVF in queue Sep 11, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the queue sample to use the correct DeliverTime column in the insert statement and switches the queue reading function to RECEIVE_MyQueue. However, because RECEIVE_MyQueue is a mutating operation, executing it within a read-only transaction (dbClient.singleUse()) will result in a runtime error. It should be executed within a read-write transaction instead.

Comment on lines 164 to +165
try (ResultSet resultSet = dbClient.singleUse().executeQuery(
Statement.of("SELECT * FROM READ_MyQueue(max_duration => '1m')"))) {
Statement.of("SELECT * FROM RECEIVE_MyQueue(max_duration => '1m')"))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The RECEIVE_MyQueue table-valued function (TVF) is a mutating queue operation (it leases/dequeues messages, modifying the queue state). In Cloud Spanner, mutating operations cannot be executed within a read-only transaction, such as dbClient.singleUse(). Attempting to do so will result in a runtime error.

To resolve this, execute the query within a read-write transaction instead:

dbClient.readWriteTransaction().run(
    transaction -> {
      try (ResultSet resultSet = transaction.executeQuery(
          Statement.of("SELECT * FROM RECEIVE_MyQueue(max_duration => '1m')"))) {
        if (resultSet.next()) {
          System.out.println("Received message ID: " + resultSet.getLong("Id"));
        } else {
          System.out.println("No message received");
        }
      }
      return null;
    });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's reading from queue only

@sakthivelmanii
sakthivelmanii enabled auto-merge (squash) September 11, 2026 14:37
@sakthivelmanii
sakthivelmanii force-pushed the fix-spanner-queue-sample-columns branch from bab0645 to a36c8ef Compare September 11, 2026 15:33
@sakthivelmanii
sakthivelmanii enabled auto-merge (squash) September 11, 2026 16:31
@sakthivelmanii
sakthivelmanii merged commit d43128a into main Sep 11, 2026
206 checks passed
@sakthivelmanii
sakthivelmanii deleted the fix-spanner-queue-sample-columns branch September 11, 2026 16:33
lqiu96 added a commit that referenced this pull request Sep 14, 2026
…4366)

In .kokoro/build.sh, changed_file_list used a two-dot git diff
(${BASE_SHA} ${HEAD_SHA}), which compares BASE_SHA directly to HEAD_SHA.
When BASE_SHA moves ahead on main after the PR branch diverges, files
merged into main on other modules were erroneously included in the diff.

Switch to a three-dot git diff (${BASE_SHA}...${HEAD_SHA}) to diff
against the merge base between BASE_SHA and HEAD_SHA, matching
.kokoro/common.sh get_modified_files() behavior.

Logs from lint job in
#14354 which only
touched a spanner file:
```
java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryArrowArray.java
java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryArrowResultSet.java
java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryArrowStruct.java
java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryBaseArray.java
java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryBaseStruct.java
java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryStatement.java
java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryTemporalUtility.java
java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowArrayOfPrimitivesTest.java
java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowResultSetTest.java
java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryArrowStructTest.java
java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcCustomLoggerTest.java
java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryStatementTest.java
java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryTemporalUtilityTest.java
java-spanner/samples/snippets/src/main/java/com/example/spanner/QueueSample.java
Matched: java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryArrowArray.java
Changed Modules: java-bigquery-jdbc java-bigquery-jdbc java-bigquery-jdbc java-bigquery-jdbc java-bigquery-jdbc java-bigquery-jdbc java-bigquery-jdbc java-bigquery-jdbc java-bigquery-jdbc java-bigquery-jdbc java-bigquery-jdbc java-bigquery-jdbc java-bigquery-jdbc
Formatting only changed modules: java-bigquery-jdbc
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants