Skip to content

fix(thrift, kernel): report TIME logical type in cursor.description - #1084

Open
atharva18-hue wants to merge 1 commit into
databricks:mainfrom
atharva18-hue:fix/time-description-1075
Open

atharva18-hue wants to merge 1 commit into
databricks:mainfrom
atharva18-hue:fix/time-description-1075

Conversation

@atharva18-hue

Copy link
Copy Markdown

Fixes #1075 (DATATYPE-043, DATATYPE-044).

Problem

cursor.description reported the wrong type for TIME result columns:

  • Thrift: 'string' at every precision — the Spark:DataType:SqlName logical-type remap covered only variant/geometry/geography.
  • Kernel/SEA: the raw Arrow spelling 'time64[ns]' — the databricks.type_name allow-list in type_mapping.py omitted TIME.
  • NULL-only TIME columns and zero-row results lost the TIME logical type on both paths ('string' on Thrift; 'time64[ns]' / 'string' on SEA, where the empty manifest's physical schema is UTF-8).

Change

  • thrift_backend.py: add time to the SqlName remap regex, so TIME(0) / TIME(3) / TIME(6) report as time (same mechanism as variant/geometry/geography).
  • kernel/type_mapping.py: add "time" to the databricks.type_name allow-list (tolerating a declared precision, e.g. TIME(6)), and map Arrow time32 / time64 to the new SqlType.TIME. The metadata path is what preserves TIME for empty-result manifests whose physical schema is Utf8; the Arrow-shape path covers NULL-only columns with no metadata. Precision stays None, matching the Thrift backend.
  • Reference: Fix Arrow TIME results on Thrift and SEA databricks-sql-go#567 fixed the same gap in the Go driver.

Tests

  • New cases in test_col_to_description and test_hive_schema_to_description (Thrift), and in test_kernel_type_mapping.py (Arrow-shape mapping, metadata recovery incl. the empty-manifest Utf8 shape and TIME(6), and the precision-None contract for TIME).
  • Local: pytest tests/unit/test_thrift_backend.py 99 passed, 82 skipped (pyarrow-gated; pyarrow cannot import in this sandbox — it needs NumPy >= 2.0 and the sandbox has Debian numpy 1.26.4). The mapping logic was verified directly without pyarrow (29 checks: all precisions, NULL-only / zero-row shapes, fallbacks preserved). tests/unit/test_kernel_type_mapping.py fails collection in this sandbox for the same pre-existing pyarrow/numpy reason (verified identical on pristine main) — the new tests in it will run in CI.
  • End-to-end conformance (test_time_type_value_and_precision, test_null_time_and_zero_row_time_metadata in databricks-driver-test#2321) needs a live Databricks workspace, which I don't have — those tests are the tripwire for this fix.

DATATYPE-043: the Thrift SqlName remap covered only variant/geometry/geography, so TIME columns reported 'string'; the kernel type_mapping allow-list likewise omitted TIME, so SEA reported the raw Arrow spelling 'time64[ns]'. Add 'time' to both, map Arrow time32/time64 to the new SqlType.TIME, and honour a declared precision (TIME(6)) on either path. DATATYPE-044: the same remaps preserve the result-schema TIME logical type for NULL-only columns and zero-row results (including empty SEA manifests whose physical schema is Utf8).

Fixes databricks#1075

Signed-off-by: Atharva Chavhan <atharvachavhan18@gmail.com>

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.

[coverage] Conformance findings: DATATYPE-043,DATATYPE-044

1 participant