[CT-3263] [Feature] User space Jinja macro for converting DB API 2.0 type_code
s into data_type
s
#8900
Open
3 tasks done
Labels
Is this your first time submitting a feature request?
Describe the feature
Different data platforms may have specialized or non-started data types (think
MONEY
,UUID
,GEOMETRY
,GEOGRAPHY
, etc.) This will cause issues when thetype_code
from the associated Python database driver is unrecognized.See below for a prototype that allows converting an unrecognized
type_code
into the desireddata_type
.Example prototype
#8887 (comment)
This prototype can be implemented directly by users. Alternatively, it could be re-written in such a way that it could be customized by adapter maintainers as-needed.
Decision criteria for where adapters-related logic should live
From @MichelleArk here:
One possible approach (to be refined)
type_code
→data_type
(within Python or Jinja)type_code
→data_type
(in user-space Jinja)data_type_code_to_name
(Python) implementations (see here and here)Alternative approach 1
get_column_schema_from_query
to take 1) and 2) into account (with the latter taking precedence)Alternative approaches 2 and 3
Same as the two approaches above, but with only a single adapter-specific lookup table (instead of separate base and supplemental lookup tables)
I haven't considered any of the above options deeply enough to have a preference yet.
Describe alternatives you've considered
The main alternative is doing these lookups with user-provided (or package-provided) macros.
The example prototype above can be entirely done by users without there being any interfaces added to dbt-core or adapters.
These macros can be defined in two places:
macros
directory of the user's dbt projectIt would be easier if dbt can provide base implementations and documentation though.
Who will this benefit?
A primary use-case is being able to properly display the actual/expected data types when contract enforcement fails (c.f. #8887).
A two-fer-one use-case is direct usage of
get_column_schema_from_query
(like described in #8877) so thatColumn.data_type
contains legit data types.This will benefit users of dbt-postgres that have data types like
money
,uuid
, etc that don't automatically have atype_code
lookup withinpsycopg2
. It also would cover the case ofgeometry
within the postgis distribution of postgres as well as user-defined types.There might be other adapters besides dbt-postgres that have similar needs.
Are you interested in contributing this feature?
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: