Skip to content
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

Merged
merged 2 commits into from
Apr 16, 2020

Conversation

beckjake
Copy link
Contributor

resolves #2260

Description

Use describe table to get the columns in a relation on snowflake. This requires doing some extra parsing to interpret varchars and numerics (with a regex...), but that's really all we get with describe table.

Checklist

  • I have signed the CLA
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR - existing tests all pass!
  • I have updated the CHANGELOG.md and added information about my change to the "dbt next" section.

@cla-bot cla-bot bot added the cla:yes label Apr 14, 2020
@beckjake beckjake requested a review from drewbanin April 14, 2020 20:37
Copy link
Contributor

@drewbanin drewbanin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One quick comment here - curious what you think about it

{% if (result | length) >= maximum %}
{% set msg %}
Too many columns in relation {{ relation }}! dbt can only get
information about relations with fewer than {{ maximum }} columns.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i hope nobody ever sees this error message :p

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 :)

@@ -108,3 +110,46 @@ def numeric_type(cls, dtype: str, precision: Any, scale: Any) -> str:

def __repr__(self) -> str:
return "<Column {} ({})>".format(self.name, self.data_type)

@classmethod
Copy link
Contributor

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 the SnowflakeColumn class? I think right now, the base logic looks like:

    def string_size(self) -> int:
        if not self.is_string():
            raise RuntimeException("Called string_size() on non-string field!")

        if self.dtype == 'text' or self.char_size is None:
            # char_size should never be None. Handle it reasonably just in case
            return 256
        else:
            return int(self.char_size)

But on Snowflake, we want to map TEXT, STRING, or VARCHAR (with no size specified) to VARCHAR(MAX), which is 16777216.

@beckjake beckjake requested a review from drewbanin April 15, 2020 21:22
Copy link
Contributor

@drewbanin drewbanin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@beckjake beckjake merged commit 59477a3 into dev/octavius-catto Apr 16, 2020
@beckjake beckjake deleted the feature/sf-describe-columns-in-table branch April 16, 2020 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Snowflake Describe queries to show columns in a table
2 participants