Skip to content

fix(bigquery-jdbc): pass typed DataSource overrides and unify last-wins connect pipeline - #15290

Open
Neenu1995 wants to merge 5 commits into
mainfrom
fix/g01-structured-connect-and-datasource-overrides
Open

Neenu1995 wants to merge 5 commits into
mainfrom
fix/g01-structured-connect-and-datasource-overrides

Conversation

@Neenu1995

@Neenu1995 Neenu1995 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Stack: PR 2 of 3 (base: fix/g01-url-parsing-and-sanitization)
Bug: b/584840728, b/584841439, b/584840529, b/584839379

Summary

Eliminates URL string round-tripping in DataSource.getConnection() and BigQueryDriver.connect() by passing typed DataSource field snapshots and validated Properties directly into a unified last-wins connect pipeline.

What Changed & Why

  • Direct typed DataSource snapshot & overlay (b/584841439, b/584840529):
    • Boxes DataSource's three primitive boolean OTel flags (enableGcpTraceExporter, enableGcpLogExporter, useGlobalOpenTelemetry) internally while preserving public boolean getter/setter API signatures, allowing explicit false overrides to win over URL settings while leaving unset fields null.
    • Adds DataSource.fromCanonicalProperties(), snapshotConfiguredFields(), and applyConfiguredFieldsTo() covering every non-URL field (verified by a reflection parity test in DataSourceTest), fixing 15 previously dropped security bean properties (oAuthSAImpersonation*, privateServiceConnect, endpointOverrides, gcpTelemetry*, oAuthP12Password, byoid*) and preserving typed queryProperties / labels maps containing , or = without sibling-key injection.
    • Empty DataSource strings are treated as unset, matching the Properties path (previously setLogLevel("") made getConnection() fail).
    • EndpointOverrides and PrivateServiceConnectUris are aliases: a value for either, from a DataSource setter or from Properties, replaces both, so a URL-supplied alias can never shadow it. An empty alias is copied as unset.
    • Fixes DataSource.getConnection() URL TOCTOU via single getURL() read, redacts invalid-URL exception messages, and delegates directly to BigQueryDriver.connectWithDataSource().
  • Unified last-wins connect pipeline (b/584840728, b/584839379):
    • Adds BigQueryDriver.ValidatedConnectionProperties and validateAndCanonicalizeProperties() with a defensive Properties.clone() snapshot and deterministic two-pass Properties(defaults) handling (inherited String defaults in Pass 1, direct child String/non-String/case-variant overrides in Pass 2). Invalid keys are skipped, and one warning that does not echo the key is logged once logging is active.
    • Adds resolvePreConnectProperty() enforcing DataSource > Properties > URL precedence for pre-connect ("bootstrap") logging properties (LogLevel, LogPath, enableGcpLogExporter), while ensuring an explicit EnableDiagnosticTelemetry opt-out (0 / false) in any source always wins.
    • Wraps BigQueryJdbcRuntimeException | IllegalArgumentException thrown during URL/property parsing into BigQueryJdbcException (SQLException) while leaving new BigQueryConnection(...) outside that catch block (preserving ITProxyBigQueryTest).

How It Was Tested

  • JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 make lint — 0 reformatted.
  • mvn -B -ntp clean test — Enforcer, Checkstyle (0 violations), Java 8 animal-sniffer, and 1,485 unit tests (1 skipped, 0 errors; only the known pre-existing local failure BigQueryJdbcOAuthUtilityTest.testPrivateKeyFromP12Bytes).
  • Added unit tests in BigQueryDriverTest, DataSourceTest, and PooledConnectionDataSourceTest covering LogPath precedence (DataSource > Properties > URL), telemetry opt-out-always-wins across all sources, Properties(defaults) overrides, ignored injection keys (warning does not echo the key), endpoint-override aliases (setter and Properties), empty-string setters treated as unset, every-field snapshot parity, delimiter-bearing maps, PartnerToken overlay parity, and IllegalArgumentException wrapping.

@Neenu1995
Neenu1995 requested review from a team as code owners November 30, 2026 20:11

@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 refactors connection property validation and normalization in the BigQuery JDBC driver. It introduces a structured validation phase that avoids flattening properties onto the JDBC URL, preserves inherited defaults, and handles custom OpenTelemetry instances. Additionally, DataSource is updated to use boxed Boolean fields to properly distinguish unset values, and configured fields are passed directly to the driver. The review feedback recommends improving the robustness of customOpenTelemetry validation by ensuring that invalid types are not silently ignored.

@Neenu1995
Neenu1995 added this pull request to stack #15292 November 30, 2026 20:14
@Neenu1995 Neenu1995 changed the title [WIP] fix(bigquery-jdbc): pass typed DataSource overrides and unify last-wins connect pipeline fix(bigquery-jdbc): pass typed DataSource overrides and unify last-wins connect pipeline Dec 1, 2026
* targetDataSource}, preserving typed {@link Map} values and explicit {@code false} flags without
* serializing back into a flat URL string.
*/
void applyConfiguredFieldsTo(DataSource targetDataSource) {

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.

That looks very fragile.

How can we ensure that when new property is added, we update it?

(note that maybe it is ok to keep as-is for this stack, but refactor it later. Right now we have like 7 different lists that should be updated when we add new property. We should have single source of truth instead)

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.

Agreed that the hand-maintained lists are fragile. For this PR, the guardrail DataSourceTest#testSnapshotConfiguredFields_coversEveryNonUrlDataSourceField fails CI if a non-URL DataSource field is not copied. The root fix is a single declarative property registry that replaces the seven hand-maintained lists; I filed b/592620248 for that and am keeping it out of this stack to limit scope.

String propertyValue,
Map<String, String> canonicalProperties,
List<String> unknownPropertyKeys) {
if (propertyValue == null || propertyValue.isEmpty()) {

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.

Do we want to allow empty strings? What would be an example when empty string is valid value?

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.

Empty means unset here, intentionally. It matches the legacy appendPropertiesToURL behaviour, which skipped empty values, and BI tools commonly send "" for fields the user left blank, so keeping it avoids a behaviour change for Properties callers. You did point at a real inconsistency on the DataSource path: setLogLevel("") used to make the connection fail. As of 0618a55 the DataSource path also treats empty strings as unset, covered by DataSourceTest#testGetConnection_emptyStringSettersAreTreatedAsUnset.

@Neenu1995
Neenu1995 requested a review from logachev December 2, 2026 19:48
Base automatically changed from fix/g01-url-parsing-and-sanitization to main December 3, 2026 03:39
…ns connect pipeline

Stack: PR 2 of 3 (base: fix/g01-url-parsing-and-sanitization)
Bug: b/584841439, b/584840529, b/584840728, b/584839495

- Replace DataSource.getConnection() createProperties/DriverManager URL round-trip with a defensive typed DataSource snapshot passed directly to BigQueryDriver.connectWithDataSource().
- Preserve all 15 previously dropped security bean fields, explicit false on boxed telemetry/OTel flags, unset enableDiagnosticTelemetry, and raw ImmutableMap queryProperties/labels.
- Unify BigQueryDriver.connect() onto two-phase single-pass tokenization with last-wins precedence (Properties/DataSource > URL) for LogLevel, LogPath, enableGcpLogExporter, and EnableDiagnosticTelemetry.
- Redact invalid-URL exceptions in DataSource.getConnection() and fix single-read URL TOCTOU.
…nd empty DataSource strings as unset

Address review feedback on #15290: an EndpointOverrides or PrivateServiceConnectUris value from a DataSource setter or Properties now replaces both aliases from the URL, empty-string DataSource setters are treated as unset like empty Properties values, and invalid Properties keys are ignored with a warning via extractValidPropertyKey.
When one EndpointOverrides/PrivateServiceConnectUris alias is configured and the other is an empty string, copy the empty alias as null so it is not surfaced in diagnostic logs.
@Neenu1995
Neenu1995 force-pushed the fix/g01-structured-connect-and-datasource-overrides branch from e5d9f1d to 91e68a2 Compare December 3, 2026 03:39

This branch has not been deployed

No deployments
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.

2 participants