-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Use "describe table" to get the columns in a relation on snowflake (#2260) #2324
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,31 +52,25 @@ | |
{% endmacro %} | ||
|
||
{% macro snowflake__get_columns_in_relation(relation) -%} | ||
{% call statement('get_columns_in_relation', fetch_result=True) %} | ||
select | ||
column_name, | ||
data_type, | ||
character_maximum_length, | ||
numeric_precision, | ||
numeric_scale | ||
|
||
from | ||
{{ relation.information_schema('columns') }} | ||
|
||
where table_name ilike '{{ relation.identifier }}' | ||
{% if relation.schema %} | ||
and table_schema ilike '{{ relation.schema }}' | ||
{% endif %} | ||
{% if relation.database %} | ||
and table_catalog ilike '{{ relation.database }}' | ||
{% endif %} | ||
order by ordinal_position | ||
{%- set sql -%} | ||
describe table {{ relation }} | ||
{%- endset -%} | ||
{%- set result = run_query(sql) -%} | ||
|
||
{% endcall %} | ||
|
||
{% set table = load_result('get_columns_in_relation').table %} | ||
{{ return(sql_convert_columns_in_relation(table)) }} | ||
{% set maximum = 10000 %} | ||
{% if (result | length) >= maximum %} | ||
{% set msg %} | ||
Too many columns in relation {{ relation }}! dbt can only get | ||
information about relations with fewer than {{ maximum }} columns. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i hope nobody ever sees this error message :p There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually don't know for sure that this is a limit, I just assumed it based on all the other commands. I'm comfortable saying that if someone has 10k columns in a table, we can revisit this then :) |
||
{% endset %} | ||
{% do exceptions.raise_compiler_error(msg) %} | ||
{% endif %} | ||
|
||
{% set columns = [] %} | ||
{% for row in result %} | ||
{% do columns.append(api.Column.from_description(row['name'], row['type'])) %} | ||
{% endfor %} | ||
{% do return(columns) %} | ||
{% endmacro %} | ||
|
||
{% macro snowflake__list_schemas(database) -%} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're in here, can we override the
string_size
on theSnowflakeColumn
class? I think right now, the base logic looks like:But on Snowflake, we want to map
TEXT
,STRING
, orVARCHAR
(with no size specified) toVARCHAR(MAX)
, which is 16777216.