Repository navigation
feat(timeshift): Add support for date range timeshifts - #34375
Conversation
There was a problem hiding this comment.
I've completed my review and didn't find any issues.
Files scanned
| File Path | Reviewed |
|---|---|
| superset/common/query_context_processor.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
|
I like the idea behind this implementation but probably better to have this behind a feature flag? also, adding some tests would be great so we ensure nothing is breaking |
8aa9f3c to
3bfb6da
Compare
There was a problem hiding this comment.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status |
|---|---|---|
| Incomplete Time Offsets Validation Docstring ▹ view | 🧠 Incorrect | |
| Missing Date Range Order Validation ▹ view | 🧠 Incorrect | |
| Vague Cleanup Logic Documentation ▹ view | 🧠 Not in scope | |
| Conflicting Time Range Bounds ▹ view | 🧠 Not in standard |
Files scanned
| File Path | Reviewed |
|---|---|
| superset/common/query_object.py | ✅ |
| superset/common/query_context_processor.py | ✅ |
| superset/config.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
| def _validate_time_offsets(self) -> None: | ||
| """Validate time_offsets configuration""" | ||
| if not self.time_offsets: | ||
| return | ||
|
|
||
| for offset in self.time_offsets: | ||
| # Check if this is a date range offset (YYYY-MM-DD : YYYY-MM-DD format) | ||
| if self._is_valid_date_range(offset): | ||
| if not feature_flag_manager.is_feature_enabled( | ||
| "DATE_RANGE_TIMESHIFTS_ENABLED" | ||
| ): | ||
| raise QueryObjectValidationError( |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| start_date, end_date = date_range.split(":") | ||
| datetime.strptime(start_date.strip(), "%Y-%m-%d") | ||
| datetime.strptime(end_date.strip(), "%Y-%m-%d") |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| def _apply_cleanup_logic( | ||
| self, | ||
| df: pd.DataFrame, | ||
| offset: str, | ||
| time_grain: str | None, | ||
| join_keys: list[str], | ||
| is_date_range_offset: bool, | ||
| ) -> pd.DataFrame: |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| query_object_clone.inner_from_dttm = query_object_clone.from_dttm | ||
| query_object_clone.inner_to_dttm = query_object_clone.to_dttm |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| for offset_key, offset_df in offset_dfs.items(): | ||
| logger.info(f"Offset '{offset_key}' DataFrame shape: {offset_df.shape}") | ||
| logger.info( | ||
| f"Offset '{offset_key}' DataFrame:\n{offset_df.to_string()}" | ||
| ) |
There was a problem hiding this comment.
Let's remove all these logs for readability
| offset, outer_to_dttm | ||
| ) | ||
|
|
||
| # For relative offsets, keep the original behavior |
There was a problem hiding this comment.
Not quite sure why altering the existing behavior, if we go this path then the FF doesn't guarantee we're not affecting the existing API
There was a problem hiding this comment.
I am not really altering the existing behaviour just moving it into the else block for feature flag.
| ) | ||
|
|
||
| else: | ||
| # RELATIVE OFFSETS: Original logic but fixed |
There was a problem hiding this comment.
Wondering if the fix should live on a different PR (and probably be shipped before this one?) otherwise your PR is not "just adding feature behind a FF"
There was a problem hiding this comment.
Same here, I am not really altering the existing behaviour just moving it into the else block for feature flag.
|
@msyavuz Could you add some screenshots demonstrating the new filters? |
|
Hey, this is a multi part implementation, frontend might be contributed later |
Antonio-RiveroMartnez
left a comment
There was a problem hiding this comment.
Please let's add the Feature flag here: https://github.com/apache/superset/blob/master/RESOURCES/FEATURE_FLAGS.md too
Antonio-RiveroMartnez
left a comment
There was a problem hiding this comment.
lgtm -- comments addressed and all changes behind a feature flag so no unexpected changes to existing APIs. Thanks for this
Summary
This PR adds support for date range timeshifts in addition to the existing relative time offsets (like "1 year ago"). Users can now specify explicit date ranges in the timeshift field (e.g., "2015-01-03 : 2015-01-04") to compare data from specific time periods.
Here's a comparison table highlighting the new flag:
Key Changes
1. Enhanced Time Offset Processing (
processing_time_offsets)is_valid_date_range()method to detect date range format timeshiftsinner_from_dttm/inner_to_dttmbounds for different offset types2. Improved Join Logic (
join_offset_dfs)3. Updated Time Delta Normalization (
normalize_time_delta)Usage Examples
Relative Offsets (existing functionality):
Date Range Offsets (new functionality):
Testing
Backward Compatibility
This change is fully backward compatible. All existing timeshift functionality continues to work exactly as before. The new date range format is additive and doesn't affect existing usage patterns.
ADDITIONAL INFORMATION