dbt-databricks icon indicating copy to clipboard operation
dbt-databricks copied to clipboard

fix: override is_string/is_number/is_float type classification for Databricks types

Open psaikaushik opened this issue 7 months ago • 4 comments

Summary

col.is_string(), col.is_number(), col.is_float(), and col.is_numeric() all return False for Databricks/Spark column types because the base Column class only recognizes PostgreSQL-style type names.

Closes #1380 Related: dbt-labs/dbt-spark#658

Root Cause

The base Column class from dbt-adapters defines is_string() etc. using type name sets that include PostgreSQL types (text, character varying, etc.) but not Spark/Databricks types (string, int, bigint, double, etc.).

DatabricksColumn inherits from SparkColumn which inherits from the base Column, but neither overrides these classification methods.

Fix

Override is_string(), is_number(), is_float(), is_integer(), and is_numeric() on DatabricksColumn with the complete set of Spark/Databricks type names:

  • String types: string, varchar, char, text, etc.
  • Numeric types: tinyint, smallint, int, integer, bigint, long, float, double, decimal, numeric, real (plus decimal(p,s) variants)
  • Float types: float, double, real
  • Integer types: tinyint, smallint, int, integer, bigint, long

Verification

Column: name03 | Data Type: string | Is String: True  (was: False)
Column: age    | Data Type: int    | Is Number: True  (was: False)

Checklist

  • [x] No breaking changes — only adds overrides, doesn't change any existing behavior for correctly-typed columns
  • [x] Covers all Spark/Databricks primitive types

psaikaushik avatar Apr 12 '26 22:04 psaikaushik

HI @psaikaushik can you select Allow edits from maintainers or do a rebase from main. The tests are failing because the branch is in an inconsistent state w.r.t CI and can 't review without it.

sd-db avatar Apr 21 '26 08:04 sd-db

HI @psaikaushik can you select Allow edits from maintainers or do a rebase from main. The tests are failing because the branch is in an inconsistent state w.r.t CI and can 't review without it.

Rebased and also allowed edits for maintainers. thanks for pointing it out! @sd-db

psaikaushik avatar Apr 21 '26 22:04 psaikaushik

Let us look to add tests + update CHANGELOG

Added tests and also updated changelog

psaikaushik avatar Apr 21 '26 22:04 psaikaushik

@sd-db : Fixed the broken formatting test. Please take a look now. thanks!

psaikaushik avatar Apr 22 '26 17:04 psaikaushik