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

fix(sql_parse): Support Jinja format() filter when extracting latest[_sub]_partition #28117

Conversation

john-bodley
Copy link
Member

SUMMARY

One can specify either a Jinja filter or Python str function to dynamically define the table referenced by the latest[_sub]_partition macros. Cases like trino.latest_partition("foo.%s"|format("bar")) and trino.latest_partition("foo.{}".format("bar")) resulted in errors of the form,

AttributeError: 'Filter' object has no attribute 'value'

or

AttributeError: 'Call' object has no attribute 'value'

respectively.

I went through numerous rabbit holes to try to have the Jinja environment render the AST subtree in a generic way, but alas I wasn't able find an elegant solution—especially when it comes to the Call node.

The fix—which only works for the Filter node—is to use the as_const() method as opposed to the value attribute to ensure the filter is rendered. Note that one can always rewrite the str.format using the Jinja format() filter.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

CI.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@john-bodley john-bodley merged commit 2f11f66 into apache:master Apr 18, 2024
29 of 30 checks passed
@john-bodley john-bodley deleted the john-bodley--fix-extract_tables_from_jinja_sql branch April 19, 2024 04:33
@michael-s-molina michael-s-molina added v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch v3.1 Label added by the release manager to track PRs to be included in the 3.1 branch labels Apr 19, 2024
michael-s-molina pushed a commit that referenced this pull request Apr 19, 2024
michael-s-molina pushed a commit that referenced this pull request Apr 19, 2024
qleroy pushed a commit to qleroy/superset that referenced this pull request Apr 28, 2024
jzhao62 pushed a commit to jzhao62/superset that referenced this pull request May 16, 2024
@mistercrunch mistercrunch added 🍒 3.1.3 🍒 4.0.1 🍒 4.0.2 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels labels Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XS v3.1 Label added by the release manager to track PRs to be included in the 3.1 branch v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch 🍒 3.1.3 🍒 4.0.1 🍒 4.0.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants