-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CT-3243] [Bug] Unrecognized data types break get_column_schema_from_query
macro (and contracts)
#8877
Comments
get_column_schema_from_query
macro (and contracts)
@rlh1994 Thanks for opening this issue, linking to other relevant issues, and laying out multiple potential options! Potential solutionFor dbt-postgres, we could replace this: dbt-core/plugins/postgres/dbt/adapters/postgres/connections.py Lines 205 to 207 in 35f46da
With this: @classmethod
def data_type_code_to_name(cls, type_code: int) -> str:
if type_code in string_types:
return string_types[type_code].name
else:
return f"unknown type_code {type_code}" Trade-offs👍 On the plus side:
👎 On the negative side:
In your particular use-case within ReprexThe following reproduction case builds on the example you provided and shows that the potential solution above appears to work with enforced contracts as well. Click to toggle a reproducible example
{{ config(materialized="table") }}
select
cast('12.34' as money) as money_col_22,
cast('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' as uuid) as uuid_col_23,
cast('192.168.100.128/25' as cidr) as cidr_col_24,
models:
- name: my_model
config:
contract:
enforced: true
columns:
- name: money_col_22
data_type: money
- name: uuid_col_23
data_type: uuid
- name: cidr_col_24
data_type: cidr dbt run -s my_model |
That works well enough for me, I hadn't looked into how the contracts actually validate but the fact that it still works using the type name is great! I even tested it with a custom user defined type and it works perfectly in contracts! |
I've only skimmed this but it's makes me think of the problem with Redshift Spectrum objects (mostly as This may or may not be a case to consider here. cc: @dataders |
Is this a new bug in dbt-core?
Current Behavior
Currently the
get_column_schema_from_query
macro, which is used as part of contracts, but also is available for any users to call (although not documented) will fail when it encounters an unknown data type code. This has already been raised as a specific case for postgresuuid
type in dbt-labs/dbt-postgres#54 and a fix is in place for both this and theip_address
type in #8357. However this issue is more generic to support any potential non-defined type rather than specifics.My concern is that if postgres adds any more types in the future this issue will persist and a new PR is going to need to be raised and merged in before this macro can be used or a contract can be enforced on the model. This may also impact other warehouses although I am not sure exactly how their column type mappings are implemented. Already in #8357 someone has mentioned the
money
type has the same issue.In addition to failing, it does so in a very unhelpful way, with the error message literally just being the type code from the warehouse, if the behaviour won't change it would be nice to have a more specific error message.
Expected Behavior
I see a few options that may be possible in the case of getting a type code that is not in the type dictionary that dbt is using.
Steps To Reproduce
dbt run
, get the2950
error despite no contract being used in the package.Relevant log output
Environment
Which database adapter are you using with dbt?
postgres
Additional Context
I think this was somewhat discussed in the original PR #6986 but it was decided to progress anyway.
For context the reason we use this macro in our packages explicitly is to get all the columns in a table so that we can rename some, but without having to manually list out all names (because postgres doesn't support
exclude
syntax, and we don't necessarily know all the columns in the table at this point). https://github.com/snowplow/dbt-snowplow-web/blob/e4ae6b297728abfb2dce5673d540e556b21f68df/models/base/scratch/default/snowplow_web_base_events_this_run.sql#L62The text was updated successfully, but these errors were encountered: