-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
feat(jinja): add advanced temporal filter functionality #30142
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #30142 +/- ##
===========================================
+ Coverage 60.48% 83.67% +23.18%
===========================================
Files 1931 529 -1402
Lines 76236 38334 -37902
Branches 8568 0 -8568
===========================================
- Hits 46114 32075 -14039
+ Misses 28017 6259 -21758
+ Partials 2105 0 -2105
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
04e2cff
to
bb73f1a
Compare
62df6e0
to
a3fbd5d
Compare
a3fbd5d
to
e6620ce
Compare
So something that comes up often in the templateized datasets using these filter values is having defaults so that users can run the "sync columns from source" action and have their query execute. The dataset modal does have "Template parameters" setting but that actually ends up overriding anything set at the dashboard or chart level which is kind of unexpected. I've been advising users to always use if/else to check if the filter values are defined otherwise fallback to a reasonable default (eg last week or day), so that their query is valid even if not run in a dashboard or chart context. It would be good to bake this default behavior into the jinja expression so that expressing this is a little less verbose. Something like:
|
That's a really good idea 👍 To keep things simple, I would prefer only having def get_time_filter(
self,
column: str | None = None,
default: str | None = None,
target_type: str | None = None,
remove_filter: bool = False,
) -> TimeFilter:
...
# logic to populate time_range from filter value
...
if time_range == NO_TIME_RANGE and default:
time_range = default
... |
8c89902
to
288e6af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
45bde42
to
d01e3fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs & comments: A few documentation language suggestions and I pointed out a place where a sentence stops halfway.
Code: I glanced at the code, it's mostly beyond me so I'll defer to others there.
Overall: seems like a nice improvement in functionality, I appreciate the complete documentation to go with it 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I added a self-assigned task for removing docs for |
SUMMARY
Currently the
from_dttm
andto_dttm
Jinja variables make it possible to reference the time range endpoints from within the Jinja context. However, they have some shortcomings:to_dttm
always points to the current day, even if there's no time range present in the query (this appears to be a quirk of how theget_since_until
helper function works)..isoformat()
method. This means that it's difficult to use them for database-specific formatting that's readily available inBaseEngineSpec.convert_dttm
.filter_value
andget_filters
macros).This PR adds a new Jinja macro called
get_time_filter
, which returns a dataclass with the following properties:from_expr
: The SQL expression representing the start of the time range, if availableto_expr
: The SQL expression representing the end of the time range, if availabletime_range
: The (usually) human readable raw value of the time filter (e.g. "No filter", "Last week" etc)Please refer to the added docs for how the feature works in practice:
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION