Repository navigation
Closed
Labels
PPLPiped processing languagecalcitecalcite migration releatedenhancementNew feature or requestpushdownpushdown related issuesv3.3.0
Description
Is your feature request related to a problem?
Currently, PPL's span() function with fixed intervals doesn't provide the same flexibility as OpenSearch's native auto_date_histogram aggregation. This leads to:
- Suboptimal bucket distribution for time series analysis (as 1000 fixed)
- Need for manual tuning of time intervals
- Potential for too many or too few buckets
- Inconsistent results between PPL and DSL queries
For example, this PPL query uses a fixed 1-hour interval:
source = custom-big5
| eval range_bucket = case(
`metrics.size` < -10, 'range_1',
`metrics.size` >= -10 and `metrics.size` < 10, 'range_2',
`metrics.size` >= 10 and `metrics.size` < 100, 'range_3',
`metrics.size` >= 100 and `metrics.size` < 1000, 'range_4',
`metrics.size` >= 1000 and `metrics.size` < 2000, 'range_5',
`metrics.size` >= 2000, 'range_6'
)
| stats min(`metrics.tmin`) as tmin, avg(`metrics.size`) as tavg, max(`metrics.size`) as tmax
by range_bucket, span(`@timestamp`, 1h) as auto_spanWhile the equivalent DSL query uses auto_date_histogram for optimal bucket distribution:
{
"aggs": {
"tmax": {
"range": {
"field": "metrics.size",
"ranges": [...]
},
"aggs": {
"date": {
"auto_date_histogram": {
"field": "@timestamp",
"buckets": 20
}
}
}
}
}
}
What solution would you like?
Implement auto_date_histogram support in PPL with:
New function syntax for auto-bucketing:
source = custom-big5
| stats count() by auto_span(`@timestamp`, buckets=20)
Key features:
- Dynamic interval selection based on data range
- Target bucket count specification
- Automatic interval rounding to human-readable values
- Consistent bucket count regardless of time range
What alternatives have you considered?
Enhanced span() function with auto mode:
span(`@timestamp`, 'auto', target_buckets=20)
Hybrid approach with min/max intervals:
adaptive_span(`@timestamp`, buckets=20, min_interval='1m', max_interval='1d')
Metadata
Metadata
Assignees
Labels
PPLPiped processing languagecalcitecalcite migration releatedenhancementNew feature or requestpushdownpushdown related issuesv3.3.0
Type
Projects
- StatusShow more project fieldsNew
- StatusShow more project fieldsDone
Activity
[-][FEATURE][/-][+][FEATURE] Span() should support auto_date_histogram aggregation[/+][-][FEATURE] Span() should support auto_date_histogram aggregation[/-][+][FEATURE] Span() / bin should support auto_date_histogram aggregation[/+]qianheng-aws commentedon Sep 18, 2025
The testing data:
The behavior between
auto_date_histogramandbinsin SPL has gaps:auto_date_histogramstarts with the value rounded by oneunit, whilebinsstarts with the value rounded byspan. For example:auto_date_histogramgets results:2025-09-18 03:23:00is rounded by1minwhile
binsgets results:2025/09/18 03:20:00is rounded by5minauto_date_histogramalways follows the policy thatThe actual number of buckets returned is always less than or equal to the number of buckets you specify., whilebingets number of buckets exceeding that parameter. For exmaple:auto_date_histogramkeep the same results as above, whilebinsget 11 buckets, which is greater than 10.auto_date_histogramwill keep the empty buckets whilebinswill only show non-empty buckets. For example:auto_date_histogramgets results:while
bingets results:This gap could be addressed by adding an additional
FILTER(COUNT() > 0).qianheng-aws commentedon Sep 18, 2025
Is it still appropriate to push down
bin .. bins=..intoauto_date_histogramwith these gaps? Another choice is addingauto_spanspecific for stats command as said in the description.Another blocking issue is our current implemention for
bincommand doesn't supportbin .. bins=..on non-numeric fields, #4317. Shall we only support push down case first to close this issue? Otherwise we also need to immitate the similar implementation ofauto_date_histogramwith Calcite.@LantaoJin @penghuo