Skip to content

Commit d28436c

Browse files
fix(bigquery-jdbc): fix manual commit mode failure for non-US regions (#13285)
## Problem Manual commit mode fails when using BigQuery JDBC with non-US datasets. **STR (Steps to Reproduce)** 1. Create BigQuery JDBC connection 2. Set a non-US location (e.g. `EU`) via `Location` property 3. Enable session mode (`EnableSession = 1`) 4. Disable auto-commit: ```java conn.setAutoCommit(false); ``` 5. Execute a simple query: ```sql SELECT 1; ``` **ER (Expected Result)** - Query executes successfully in manual commit mode - BigQuery uses configured Location (e.g. EU) - No region mismatch errors occur **AR (Actual Result)** Query execution fails with: ``` GoogleJsonResponseException: 400 Bad Request INVALID_ARGUMENT Error: 3848323 ``` **Sample java code:** ```java String jdbcUrl = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443"; Properties props = new Properties(); props.put("OAuthType", "0"); props.put("OAuthPvtKeyPath", "<key-file-path>"); props.put("ProjectId", "<project-id>"); props.put("Location", "EU"); props.put("EnableSession", "1"); try (Connection conn = DriverManager.getConnection(jdbcUrl, props)) { conn.setAutoCommit(false); try (PreparedStatement ps = conn.prepareStatement("SELECT 1;")) { ps.execute(); } } ``` Co-authored-by: Jin Seop Kim <jinseop@google.com>
1 parent 8a9fab9 commit d28436c

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,10 @@ public Job create(JobInfo jobInfo, JobOption... options) {
416416
new Supplier<JobId>() {
417417
@Override
418418
public JobId get() {
419-
return JobId.of();
419+
// Explicitly set the location for a new job when provided in options.
420+
// Otherwise, the job may be created with an incorrect location
421+
// (e.g. in transaction mode outside the US).
422+
return JobId.of().setLocation(getOptions().getLocation());
420423
}
421424
};
422425
return create(jobInfo, idProvider, options);

java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpcTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,8 @@ public void testCreateJobTelemetry() throws Exception {
795795
"{\"kind\":\"bigquery#job\",\"id\":\""
796796
+ PROJECT_ID
797797
+ ":"
798+
+ LOCATION
799+
+ ":"
798800
+ JOB_ID
799801
+ "\",\"status\":{\"state\":\"DONE\"}}");
800802

@@ -804,7 +806,7 @@ public void testCreateJobTelemetry() throws Exception {
804806

805807
verifyRequest("POST", "/projects/" + PROJECT_ID + "/jobs");
806808
Map<String, String> attributes = new HashMap<>();
807-
attributes.put("bq.rpc.response.job.id", PROJECT_ID + ":" + JOB_ID);
809+
attributes.put("bq.rpc.response.job.id", PROJECT_ID + ":" + LOCATION + ":" + JOB_ID);
808810
attributes.put("bq.rpc.response.job.status.state", "DONE");
809811
verifySpan(
810812
"com.google.cloud.bigquery.BigQueryRpc.createJob",

0 commit comments

Comments
 (0)