You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG]Aggregation fails when grouping by timestamp-derived fields #4063
Aggregation fails when grouping by timestamp-derived fields
Bug Description
There is an issue in the stats/aggregation logic when grouping by timestamp-related fields. This affects both the bin command with timestamp aggregation and direct timestamp field manipulation.
Steps to Reproduce
Minimal Reproduction Case
source=time_test | eval t = unix_timestamp(@timestamp) | stats count() by t
Original Failing Test Case
source=opensearch-sql_test_index_time_data | bin @timestamp span=4h | stats count() by @timestamp | sort @timestamp | head 3
Current Behavior
Both queries fail with aggregation errors, indicating the problem is in the stats command aggregation logic,
Expected Behavior
stats count() by t should successfully group by the timestamp-derived field and return aggregated counts
bin @timestamp span=4h | stats count() by @timestamp should successfully bin timestamps into 4-hour intervals and aggregate counts
Test Case for Verification
@TestpublicvoidtestTimestampAggregationIssue() throwsIOException {
// Simple case - should workJSONObjectresult = executeQuery(
"source=time_test | eval t = unix_timestamp(@timestamp) | stats count() by t"
);
// Bin case - should also work JSONObjectbinResult = executeQuery(
"source=opensearch-sql_test_index_time_data | bin @timestamp span=4h | stats count() by @timestamp"
);
}
@timestamp is of type TIMESTAMP, but when it reaches Expression level in UnixTimestampFunction, it is represented as an ExprStringValue instead of ExprTimestampValue.
source=time_test | eval t = unix_timestamp(@timestamp) | stats count() by t works with pushdown disabled. It might have something to do with pushdown.
{"error": {"reason": "Error occurred in OpenSearch engine: all shards failed","details": "Shard[0]: AggregationExecutionException[Unsupported script value [2023-01-01], expected a number, date, or boolean]\Shard[1]: AggregationExecutionException[Unsupported script value [2023-01-01], expected a number, date, or boolean]\Shard[2]: AggregationExecutionException[Unsupported script value [2023-01-01], expected a number, date, or boolean]\Shard[3]: AggregationExecutionException[Unsupported script value [2023-01-01], expected a number, date, or boolean]\Shard[4]: AggregationExecutionException[Unsupported script value [2023-01-01], expected a number, date, or boolean]\\For more details, please send request for Json format to see the raw response from OpenSearch engine.","type": "SearchPhaseExecutionException"},"status": 500}
The error implies that a date should work, but this error comes after casting:
Activity
yuancu commentedon Aug 19, 2025
@timestampis of typeTIMESTAMP, but when it reaches Expression level in UnixTimestampFunction, it is represented as anExprStringValueinstead ofExprTimestampValue.source=time_test | eval t = unix_timestamp(@timestamp) | stats count() by tworks with pushdown disabled. It might have something to do with pushdown.Swiddis commentedon Sep 19, 2025
The error implies that a
dateshould work, but this error comes after casting: