Repository navigation
feat: report VARIANT type names in column metadata (#576) - #577
Conversation
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]>
There was a problem hiding this comment.
🔀 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]>
There was a problem hiding this comment.
🔀 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]>
|
Addressed the Medium finding in d61db77: the shared live assertion behind 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 |
|
Go integration tests triggered ( |
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]>
|
Integration test approval reset. New commits were pushed to this PR. Label(s) 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 |
There was a problem hiding this comment.
🔀 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.
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]>
Summary
Report VARIANT columns by name.
sql.ColumnType.DatabaseTypeName()now returnsVARIANTinstead ofSTRINGfor 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) ordatabricks.type_name(kernel, written from the SEA manifest for every column).arrowscan.IsVariantFielddecides it once for both backends: only a string or large-string physical type qualifies, and the first non-blank ofdatabricks.type_nameand thenSpark:DataType:SqlNamemust beVARIANT(case-insensitive). The same lookup now backs the existing TIMESTAMP_NTZ and TIME checks.ColumnTypeInfoForFieldreports VARIANT directly, so the kernel rows need no extra wiring.buildDatabaseTypeNameOverridesreports 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 staysSTRING.ScanType(string) andLengthstay 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 seeVARIANTfor 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
IsVariantFieldtable tests;ColumnTypeInfoForFieldVARIANT and look-alike string types; ThriftColumnTypeDatabaseTypeName/ScanType/Lengthacross Arrow, URL, column-based, Arrow-disabled, missing-schema and invalid-schema paths, including zero rows.go test ./...(live warehouse credentials removed),go test -raceon the touched packages,go vet ./...,go vet -tags e2e ./...andmake lintare clean locally. The kernel-tagged e2e build is checked by the "Test (kernel backend)" CI job.TestE2EVariantTypeName(Thrift) andTestKernelE2EVariantTypeName(kernel) assert the VARIANT name, the STRING scan type and length, and the JSON value. They run in the nightly workflow withTestKernelThriftColumnTypeParity, which compares Thrift and kernel column metadata.This pull request and its description were written by Isaac.