Skip to content

fix(metadata): normalize native metadata to public schema - #364

Merged
vuanhphung merged 3 commits into
mainfrom
fix/native-metadata-type-casting
Sep 24, 2026
Merged

vuanhphung merged 3 commits into
mainfrom
fix/native-metadata-type-casting

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Native Thrift metadata can differ from the public JDBC contract in both physical Arrow types and values.

Cast arrays to the public schema while preserving already-matching arrays. Reject unexpected column counts and cast failures as DataLoss. Normalize native ORDINAL_POSITION values from zero-based to one-based, matching JDBC and the non-native SHOW COLUMNS path; preserve nulls and reject overflow.

Tests:

  • cargo +stable fmt --all -- --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Low

Looks good — a clean, well-tested fix that casts native Thrift metadata columns to the public JDBC schema with proper DataLoss handling for count mismatches and lossy/out-of-range casts. One low observation: the per-column cast is purely positional and doesn't verify field-name agreement, so it depends entirely on the documented canonical-order invariant.

Comment thread src/metadata_v0.rs Resolved
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
@vuanhphung vuanhphung changed the title fix(metadata): cast native metadata to public schema fix(metadata): normalize native metadata to public schema Sep 24, 2026

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Low

Looks good — the fix is correct and well-tested. Verified against the JDBC reference driver (MetadataResultSetBuilder.java:1686 increments native GetColumns ordinals by one on the thrift-copy path), so the zero-based→one-based +1 direction is right; the safe:false cast is strictly more permissive than the previous try_new type check, and overflow/column-count/out-of-range cases are all unit-tested. One Low note about the shared helper dispatching the ordinal fix by field name. No wiremock/e2e test exercises the is_native routing end-to-end, but the direct unit tests on normalize_native_metadata_batch cover the core logic adequately.

Comment thread src/metadata_v0.rs Resolved
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Low

Looks good — solid change with thorough unit + wiremock coverage (width cast, Utf8/LargeUtf8/View cast, one-based ordinal, overflow, column-count and narrowing-cast rejection). One low observation: the ordinal increment is dispatched by the public schema's field name over a purely positional zip, which is safe today but couples to the canonical-order invariant and to the fact that only GetColumns currently carries ORDINAL_POSITION among native-routed schemas.

Comment thread src/metadata_v0.rs
})?
};

if field.name() != "ORDINAL_POSITION" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low — normalize_native_metadata_batch zips columns to the public schema positionally and decides the zero→one-based increment purely from the public schema's field.name() == "ORDINAL_POSITION" — it never checks the native column's own name/order. Two consequences worth noting:

  1. Correctness rests entirely on the documented "native metadata already has the canonical Thrift column order" invariant. Column count is validated, but a divergence in column order would silently cast one native column into a differently-meaning public column (and, at the ORDINAL_POSITION slot, +1 a value that isn't actually the ordinal). Consider asserting the native field name matches at each position, or at least at the ORDINAL_POSITION slot, so a contract drift fails loudly as DataLoss rather than corrupting values.

  2. Latent coupling: GET_PROCEDURE_COLUMNS_SCHEMA also declares an ORDINAL_POSITION field. It's safe today because list_procedure_columns routes through ThriftReshapingReader and never calls this normalizer — but if a native path is added for procedure columns later, this name-based increment would fire there too (JDBC getProcedureColumns ordinals are not the same zero-based case), silently off-by-one-ing them. A brief comment scoping this increment to GetColumns, or gating on the operation type rather than the field name, would prevent that.

Neither is an active bug; filing as low for the maintainability/robustness angle.

@vuanhphung
vuanhphung added this pull request to the merge queue Sep 24, 2026
Merged via the queue into main with commit 80f2aee Sep 24, 2026
24 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — c291041e Deployed Sep 24, 2026 by oss-reviewer-bot[bot] via followup #1611
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.

1 participant