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

In schema tests, pass rendered items (#2149) #2220

Merged
merged 8 commits into from
Mar 25, 2020

Conversation

beckjake
Copy link
Contributor

@beckjake beckjake commented Mar 19, 2020

resolves #2149

Description

In schema tests, render parameters and pass them in as rendered items.
This PR formally splits data tests and schema tests - data tests don't get a column name or test metadata since that's nonsensical for them.

This PR includes some backwards compatibility changes, so there should be no regressions. Initially I was going to have the "legacy form" arguments (like ref("my_model") instead of {{ ref("my_model") }}) emit a deprecation warning, but it's actually really annoying and overly verbose, so I think I'd like to keep the shorthand form.

Edit: I added jinja2 2.11.x as a requirement for this PR, as it fixes some issues with quoting in the native renderer.

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
  • 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 Mar 19, 2020
@beckjake beckjake force-pushed the feature/schema-tests-pass-rendered branch from ad899d1 to 6308d08 Compare March 19, 2020 16:50
@beckjake
Copy link
Contributor Author

The azure tests are passing, I don't know why they're showing as failed. https://dev.azure.com/fishtown-analytics/dbt/_build/results?buildId=1658&view=results

Jacob Beck added 4 commits March 24, 2020 09:09
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.

Couple of questions and comments here, but overall this looks excellent and i'm excited to leverage the native jinja env in other parts of parsing :D

Nice work!

@@ -227,6 +227,12 @@ def list_relations_without_caching(
def quote(self, identifier):
return '"{}"'.format(identifier)

@classmethod
def unquote(cls, identifier: str) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels to me like plugins should specify a quote character so that we don't need to re-implement this method on BigQuery (or others). Agree/disagree?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We actually don't need this method at all, I think - I'll remove it.

if isinstance(value, str):
if re.match(looks_like_func, value) is not None:
# curly braces to make rendering happy
value = f'{{{{ {value} }}}}'
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have the ability to reach into the context and call these functions directly? I think the approach shown here is a-ok for now, but I'd like to remove this jinja hackery in the future if we can!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could, but it would be quite tricky to handle things like ref(var('foo')) because you have to recursively descend into the arguments

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, interesting - that's fair. Thanks!

)
# this is an ugly way of checking if the value was a quoted str
# (we don't want to unquote column names!)
if not (len(value) >= 2 and new_value == value[1:-1]):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think i understand what this check does -- how can get_rendered remove quotes around column names?

Copy link
Contributor Author

@beckjake beckjake Mar 25, 2020

Choose a reason for hiding this comment

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

If you take the string "my_str" and render it with jinja (edit: in the native context only!), jinja will strip the quotes as part of rendering.

@@ -160,33 +181,6 @@ def compile_node(self, node, manifest, extra_context=None):

injected_node, _ = prepend_ctes(compiled_node, manifest)

should_wrap = {NodeType.Test, NodeType.Operation}
Copy link
Contributor

Choose a reason for hiding this comment

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

ye shall not be missed

core/dbt/node_runners.py Outdated Show resolved Hide resolved
Co-Authored-By: Drew Banin <drew@fishtownanalytics.com>
@beckjake beckjake force-pushed the feature/schema-tests-pass-rendered branch from e9a053c to 701b3b4 Compare March 25, 2020 16:46
@beckjake beckjake force-pushed the feature/schema-tests-pass-rendered branch from 701b3b4 to 1268c11 Compare March 25, 2020 16:46
@drewbanin
Copy link
Contributor

I think #38bcc2b looks like it works really well here!

@beckjake
Copy link
Contributor Author

Yeah. playing around locally, it seems to behave like I'd expect.

@drewbanin drewbanin self-requested a review March 25, 2020 20:27
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.

This one LGTM now - let's ship it

@beckjake beckjake merged commit 7b6ea33 into dev/octavius-catto Mar 25, 2020
@beckjake
Copy link
Contributor Author

This PR also resolves #2227

@beckjake beckjake deleted the feature/schema-tests-pass-rendered branch April 23, 2020 20:33
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.

Test parsing overhaul
2 participants