fix(sql_parse): Support Jinja format() filter when extracting latest[_sub]_partition #28117
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SUMMARY
One can specify either a Jinja filter or Python
str
function to dynamically define the table referenced by thelatest[_sub]_partition
macros. Cases liketrino.latest_partition("foo.%s"|format("bar"))
andtrino.latest_partition("foo.{}".format("bar"))
resulted in errors of the form,or
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 theas_const()
method as opposed to thevalue
attribute to ensure the filter is rendered. Note that one can always rewrite thestr.format
using the Jinjaformat()
filter.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
CI.
ADDITIONAL INFORMATION