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
@Test
public void testTimestampAggregationIssue() throws IOException {
// Simple case - should work
JSONObject result = executeQuery(
"source=time_test | eval t = unix_timestamp(@timestamp) | stats count() by t"
);
// Bin case - should also work
JSONObject binResult = executeQuery(
"source=opensearch-sql_test_index_time_data | bin @timestamp span=4h | stats count() by @timestamp"
);
}
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
bincommand with timestamp aggregation and direct timestamp field manipulation.Steps to Reproduce
Minimal Reproduction Case
Original Failing Test Case
Current Behavior
Both queries fail with aggregation errors, indicating the problem is in the stats command aggregation logic,
Expected Behavior
stats count() by tshould successfully group by the timestamp-derived field and return aggregated countsbin @timestamp span=4h | stats count() by @timestampshould successfully bin timestamps into 4-hour intervals and aggregate countsTest Case for Verification