Repository navigation
[WIP] fix(bigquery-jdbc): validate stream TableSchema and gate sessions, transactions, and target projects - #15187
Conversation
…ansactions, and target projects Stack: PR 5 of 6 (base: `fix/swa-v2-4-direct-insert-parser`) ### Summary - Validate the authoritative destination `TableSchema` returned by `createWriteStream` (`isSupportedStreamTableSchema` / `isWriteStreamCompatible`) before opening `StreamWriter` or polling `batchParameters`, falling back cleanly to SQL DML when unreferenced columns (such as DDL `DEFAULT` or `ARRAY`/`STRUCT`/`RANGE` columns) are present on the target table, and verify end-to-end reordered `(col_b, col_a)` `ProtoRows` streaming. - Propagate `DefaultDataset` in `BigQueryStatement.generateBigQuerySettings()`, make `getUseLegacySql()` null-safe and skip positional dry runs in Legacy SQL mode, and resolve target projects (`resolveTargetProject`) using `DefaultDataset` strictly for 1-part unqualified table names while resolving 2-part names against `catalog` / `bigQuery.getOptions().getProjectId()`. - Retry unbound positional dry runs at most once in `executeBatch()` when a target table is created after `prepareStatement()` (removing the obsolete bound `getWriteBatchJobConfiguration` helper), and fall back to SQL DML inside active multi-statement transactions or active-session anonymous `_` temp datasets. ### Testing - `make lint`, `mvn -B -ntp dependency:analyze -Pquick-build -DfailOnWarning=true -Dmdep.analyze.skip=false`, `mvn -q -Denforcer.skip=true -Dclirr.skip=true test-compile`, and `make unittest` (`BigQueryStatementTest` and `BigQueryPreparedStatementWriteApiTest` covering reordered `ProtoRows` streaming, `createWriteStream` table-schema mismatch SQL fallback, unqualified `DefaultDataset` vs. 2-part `catalog` / ADC `options` project resolution, deferred-table retry dry runs, non-repeated persistent dry-run errors, Legacy SQL, and session/transaction gating).
There was a problem hiding this comment.
Code Review
This pull request enhances the BigQuery JDBC driver's batch insertion capabilities using the Storage Write API. Key changes include validating stream table schemas, dynamically resolving target project IDs, and adding safety checks to prevent Write API usage during active transactions, legacy SQL execution, or incompatible session states. Additionally, the PR refactors parameter handling and improves robustness. Feedback on the changes suggests a safer way to iterate over batch parameters in getStandardBatchJobConfiguration to avoid a potential IndexOutOfBoundsException if the parameter list is not fully populated.
| for (int i = 0; i < this.parameterCount; i++) { | ||
| BigQueryJdbcParameter parameter = parameterList.get(i); |
There was a problem hiding this comment.
Using a hardcoded loop up to this.parameterCount can throw an IndexOutOfBoundsException if parameterList is not fully populated (e.g., if some parameters were not set). It is safer to limit the loop to the actual size of the parameter list.
| for (int i = 0; i < this.parameterCount; i++) { | |
| BigQueryJdbcParameter parameter = parameterList.get(i); | |
| int paramsToBind = Math.min(this.parameterCount, parameterList.size()); | |
| for (int i = 0; i < paramsToBind; i++) { | |
| BigQueryJdbcParameter parameter = parameterList.get(i); |
Stack: PR 5 of 6 (base:
fix/swa-v2-4-direct-insert-parser)Bug: b/587228731, b/587340667
Summary
Validate destination stream
TableSchemacompatibility before appending, propagateDefaultDatasettarget projects accurately, guard Legacy SQL and deferred-table retry dry runs, and gate out active SQL transactions and session temporary datasets.Design Decisions
TableSchemaValidation: Check the authoritativeTableSchemareturned bycreateWriteStream(isSupportedStreamTableSchemaandisWriteStreamCompatible) before pollingbatchParameters; if unreferenced columns (such as DDLDEFAULTorARRAY/STRUCT/RANGEcolumns) exist, return-1Land fall back cleanly to SQL DML withbatchParametersintact.DefaultDatasetinBigQueryStatement.generateBigQuerySettings()and applyDefaultDataset.getProject()inresolveTargetProjectstrictly to 1-part unqualified tables while resolving 2-partdataset.tabletargets againstcatalog/bigQuery.getOptions().getProjectId()._temporary datasets to SQL DML so pending stream commits cannot violate transactional/session visibility, skip positional dry runs under Legacy SQL, and retry unbound dry runs at most once (insertMetadataEvaluated) for tables created afterprepareStatement().