You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
get_columns_in_query retrieves a list of column names from a model's sql by running an inexpensive select * from {{ sql }} where false limit 0 query. Currently, this macro is leveraged to efficiently enforce that a model's contracted names match with what its sql would actually produce.
However, we'll need to be able to retrieve column data types in addition to column names from a model's sql in order to enforce a model contract complete with data types.
Let's create a new macro, get_column_schema_from_query with a default implementation that returns a list of Column objects with column name and type. This macro will need to rely on adapter-specific implementations to data type off the connection cursor/API. Because aapter-specific connections may return data type representations that do not match up with user-provided values, we’ll need to use dbt adapters’ type translation (aliases → standard), to match up data types with user-provided values.
get_columns_in_query
retrieves a list of column names from a model's sql by running an inexpensiveselect * from {{ sql }} where false limit 0
query. Currently, this macro is leveraged to efficiently enforce that a model's contracted names match with what its sql would actually produce.However, we'll need to be able to retrieve column data types in addition to column names from a model's sql in order to enforce a model contract complete with data types.
Let's create a new macro,
get_column_schema_from_query
with a default implementation that returns a list ofColumn
objects with column name and type. This macro will need to rely on adapter-specific implementations to data type off the connection cursor/API. Because aapter-specific connections may return data type representations that do not match up with user-provided values, we’ll need to use dbt adapters’ type translation (aliases → standard), to match up data types with user-provided values.@jtcohen6 has taken a very thorough first stab at validating this approach in jerco/get-column-schema-from-query
The text was updated successfully, but these errors were encountered: