Skip to content

feat: report VARIANT type names in column metadata (#576) - #577

Merged
cathleeny merged 6 commits into
mainfrom
feat/variant-type-name
Nov 19, 2026
Merged

cathleeny merged 6 commits into
mainfrom
feat/variant-type-name

Conversation

@cathleeny

@cathleeny cathleeny commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Report VARIANT columns by name. sql.ColumnType.DatabaseTypeName() now returns VARIANT instead of STRING for top-level VARIANT columns on both the Thrift and kernel (SEA) backends, matching the Python connector (databricks/databricks-sql-python#560) and JDBC.

Fixes #576

How it works

The server sends VARIANT as a string column, so neither the Thrift type ID (STRING_TYPE) nor the Arrow physical type (Utf8) can tell it apart from STRING. The logical type name is in the Arrow field metadata: Spark:DataType:SqlName (Thrift result schema) or databricks.type_name (kernel, written from the SEA manifest for every column).

  • arrowscan.IsVariantField decides it once for both backends: only a string or large-string physical type qualifies, and the first non-blank of databricks.type_name and then Spark:DataType:SqlName must be VARIANT (case-insensitive). The same lookup now backs the existing TIMESTAMP_NTZ and TIME checks.
  • Kernel: ColumnTypeInfoForField reports VARIANT directly, so the kernel rows need no extra wiring.
  • Thrift: buildDatabaseTypeNameOverrides reports VARIANT whenever the result-set Arrow schema tags the column. VARIANT values are JSON text on every result format, so this also covers column-based results; TIMESTAMP_NTZ and TIME keep their Arrow-decoding requirement unchanged. Without a server-supplied Arrow schema, the name stays STRING.
  • Only the type name changes. Values (JSON text), ScanType (string) and Length stay the same. Nested VARIANT (inside ARRAY, MAP or STRUCT) is not reported by name, the same as TIMESTAMP_NTZ.

Compatibility

Behavior change, recorded in the changelog: callers that match DatabaseTypeName() == "STRING" will see VARIANT for VARIANT columns. Scanning is unaffected, since the scan type and length match a STRING column. There is no opt-in or opt-out option; this follows the TIME and TIMESTAMP_NTZ type-name changes already in the v2.0.0 notes, and the driver itself never branches on a VARIANT or STRING type name.

Testing

  • Regression probe: the kernel column mapping for 36 field kinds and Thrift column metadata for 10 column kinds across 7 result-format and schema paths were compared against the base commit. Only the VARIANT-tagged string columns changed name; every scan type, length and other column name, including TIMESTAMP_NTZ and TIME across result formats, is identical.
  • Unit (default build): IsVariantField table tests; ColumnTypeInfoForField VARIANT and look-alike string types; Thrift ColumnTypeDatabaseTypeName/ScanType/Length across Arrow, URL, column-based, Arrow-disabled, missing-schema and invalid-schema paths, including zero rows.
  • go test ./... (live warehouse credentials removed), go test -race on the touched packages, go vet ./..., go vet -tags e2e ./... and make lint are clean locally. The kernel-tagged e2e build is checked by the "Test (kernel backend)" CI job.
  • Live e2e tests TestE2EVariantTypeName (Thrift) and TestKernelE2EVariantTypeName (kernel) assert the VARIANT name, the STRING scan type and length, and the JSON value. They run in the nightly workflow with TestKernelThriftColumnTypeParity, which compares Thrift and kernel column metadata.

This pull request and its description were written by Isaac.

cathleeny and others added 2 commits November 18, 2026 17:08
Add WithEnableVariantTypeName / enableVariantTypeName=true. When enabled,
sql.ColumnType.DatabaseTypeName() reports "VARIANT" for top-level VARIANT
columns on both the Thrift and SEA (kernel) backends instead of "STRING".
Values remain JSON text, and ScanType and length are unchanged. The default
is off, so existing callers see no change.

Detection reads the Arrow field metadata (databricks.type_name, then
Spark:DataType:SqlName) and applies only to string physical types. On Thrift
it needs the server-supplied Arrow result schema, as TIMESTAMP_NTZ does.
Nested VARIANT is not reported by name.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Cathleen Yan <[email protected]>
Move the per-column type mapping used by the kernel rows into an untagged
columnTypeInfos helper, so the default build tests the VARIANT opt-in
directly. Also share the logical type name lookup in arrowscan, so the
databricks.type_name / Spark:DataType:SqlName precedence is defined once
for the NTZ, TIME and VARIANT checks. Behavior is unchanged.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Cathleen Yan <[email protected]>

@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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Terra), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

🔀 1 finding considered and dismissed by the judge
  • 🟡 Medium internal/rows/rows.go:502 — The VARIANT override is skipped for column-based results even when the server supplies a tagged Arrow schema, although those results also scan the value as a st
    Judge's evidence: // The override is only applied when the result set metadata indicates Arrow // decoding: columnar (TColumn) results kee…

Report top-level VARIANT columns as VARIANT on both backends without a connection option, matching the Python and JDBC drivers. Values, scan type and length are unchanged. Remove WithEnableVariantTypeName and the enableVariantTypeName DSN parameter, and map VARIANT in the shared kernel column mapping. On Thrift, report VARIANT whenever the result schema tags the column, including column-based results, since VARIANT values are JSON text on every result format; TIMESTAMP_NTZ and TIME keep their Arrow-decoding requirement.

Signed-off-by: Cathleen Yan <[email protected]>
Co-authored-by: Isaac <[email protected]>
@cathleeny cathleeny changed the title feat: opt-in VARIANT type name in column metadata (#576) feat: report VARIANT type names in column metadata (#576) Nov 19, 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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Terra), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Medium

Looks good, no findings. VARIANT detection is shared through IsVariantField, the Thrift override keeps the Arrow-decoding gate for TIMESTAMP_NTZ and TIME, and unit tests cover the result-format and schema paths. The new e2e tests are registered in the nightly -run filters.

This overview is Claude Opus 5.5's initial take; GPT-6.1 Terra added findings it doesn't mention — see the findings below.

Other findings

  • 🟡 Medium — The shared live test covers only a populated VARIANT, leaving empty and NULL-only result schemas unverified on both backends; the unit test supplies its own Arrow schema rather than exercising the server or kernel manifest. Add zero-row and NULL-only cases that assert the type name, scan type and length through both backends. (Found by GPT-6.1 Terra · the judge couldn't confirm it)

Assert the VARIANT type name, scan type and length for empty and NULL-only results on both backends, whose result schemas the server or kernel may build without row data.

Signed-off-by: Cathleen Yan <[email protected]>
Co-authored-by: Isaac <[email protected]>
@cathleeny

Copy link
Copy Markdown
Collaborator Author

Addressed the Medium finding in d61db77: the shared live assertion behind TestE2EVariantTypeName (Thrift) and TestKernelE2EVariantTypeName (kernel) now also runs an empty range, an empty filter and a NULL-only result, and asserts the VARIANT type name with the STRING scan type and length for each, plus NULL values for the NULL-only rows.

The unit tests already cover the Thrift metadata paths for zero-row results with a supplied schema. The live cases run in the nightly workflow. Note that the nightly e2e workflow currently fails on main for every test at session open (HTTP 403 from the configured warehouse credential), so these live cases will run once that is fixed.

@cathleeny cathleeny added the integration-test Preview the Go integration replay suite on this PR label Nov 19, 2026
@github-actions

Copy link
Copy Markdown

Go integration tests triggered (thrift+sea / replay). View workflow runs.

@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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Terra), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

Comment thread variant_e2e_test.go Resolved
Comment thread internal/arrowscan/coltype.go Resolved
Add a CloudFetch-sized case to the shared VARIANT e2e assertion, so the
Thrift and kernel tests both check a URL_BASED_SET result. On Thrift,
capture the result metadata the way TestE2ETimeArrowResults does and
require every Arrow schema the server sends to tag the column
Spark:DataType:SqlName=VARIANT, and a CloudFetch result to have been
returned.

Fix comments that still described VARIANT as collapsing to STRING or as
arriving nested, and the schema parse-failure comment, which now covers
VARIANT on column-based results.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Cathleen Yan <[email protected]>
@github-actions github-actions Bot removed the integration-test Preview the Go integration replay suite on this PR label Nov 19, 2026
@github-actions

Copy link
Copy Markdown

Integration test approval reset.

New commits were pushed to this PR. Label(s) integration-test were removed for security.

A maintainer must re-review and re-add a label to preview tests again. (The real gate runs in the merge queue.)

Latest commit: a7675b6

@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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Terra), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 High

Looks good, no findings. VARIANT detection lives in one shared place and only accepts string-typed columns, and TIMESTAMP_NTZ/TIME still require Arrow decoding as before. The unit tests cover the Thrift result formats and schema paths, and the e2e tests are registered in the nightly filters for both backends.

This overview is Claude Opus 5.5's initial take; GPT-6.1 Terra added findings it doesn't mention — see the findings below.

Comment thread variant_e2e_test.go Resolved
TestE2EVariantTypeName limits the pool to one connection for the wire
capture, and the populated query's rows were only closed by a defer, so
they held that connection while the CloudFetch subtest waited for it.
Drain and close them before the subtests run.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Cathleen Yan <[email protected]>

@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.

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Terra), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

@cathleeny
cathleeny added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit d034123 Nov 19, 2026
16 checks passed
@cathleeny
cathleeny deleted the feat/variant-type-name branch November 19, 2026 22:00
@cathleeny cathleeny mentioned this pull request Nov 19, 2026
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.

Support for VARIANT

2 participants