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

[Bug] Fix scenarios where --empty flag pushes limit 0 into metadata queries #1100

Merged
merged 5 commits into from
Jul 3, 2024

Conversation

mikealfare
Copy link
Contributor

@mikealfare mikealfare commented Jun 28, 2024

resolves #1033

Problem

We use {{ relation }} to render the relation name in metadata queries. However, we implemented the --empty flag to add limit 0 when {{ relation }} is used. We wind up with queries like:

describe table (select * from my_relation limit 0)

which is not valid sql.

Solution

  • Use {{ relation.render() }} in these scenarios (there are many)
  • Add a test case that confirms we can use these macros while using the --empty flag

Implementation

  1. Merge this PR demonstrating that these tests work (we`re here)
  2. Move the bulk of this PR into dbt-tests-adapter
  3. Create a final PR that removes most of this and uses the dbt-tests-adapter tests

Checklist

  • I have read the contributing guide and understand what's expected of me
  • 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
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX

@cla-bot cla-bot bot added the cla:yes label Jun 28, 2024
Copy link
Contributor

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the dbt-snowflake contributing guide.

@mikealfare mikealfare changed the title [ [Bug] Fix scenarios where --empty flag pushes limit 0 into metadata queries Jun 28, 2024
@mikealfare mikealfare self-assigned this Jun 28, 2024
@mikealfare mikealfare marked this pull request as ready for review July 2, 2024 19:41
@mikealfare mikealfare requested a review from a team as a code owner July 2, 2024 19:41
"truncate_relation",
],
)
def test_run(self, project, model):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of these tests pass even without fixing {{ relation }} to be {{ relation.render() }}. I think it has something to do with whether the template returns just the sql or whether it does the call. I added the tests in case this changes in the future, and updated the macros to use {{ relation.render() }}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of this will move into dbt-tests-adapter and then imported here afterwards.

Copy link
Contributor

@McKnight-42 McKnight-42 left a comment

Choose a reason for hiding this comment

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

This is looking good to me

@mikealfare mikealfare merged commit 13970da into main Jul 3, 2024
18 checks passed
@mikealfare mikealfare deleted the bug/1033-fix-empty-flag branch July 3, 2024 14:48
@pempey
Copy link

pempey commented Aug 7, 2024

@mikealfare When might one expect these change in a release? Or is there a way to test these changes on our system before a release?

@pempey
Copy link

pempey commented Aug 29, 2024

I will ask my question to a larger audience: @colin-rogers-dbt @McKnight-42 @jtcohen6 When might one expect these change in a release? Or is there a way to test these changes on our system before a release?

github-actions bot pushed a commit that referenced this pull request Oct 11, 2024
…ta queries (#1100)

* fix get_columns_in_relation
* add render to relation in other metadata queries
* add tests for all render instances

(cherry picked from commit 13970da)
colin-rogers-dbt pushed a commit that referenced this pull request Oct 11, 2024
…ta queries (#1100) (#1204)

* fix get_columns_in_relation
* add render to relation in other metadata queries
* add tests for all render instances

(cherry picked from commit 13970da)

Co-authored-by: Mike Alfare <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] --empty doesn't work when using get_columns_in_relation
4 participants