Skip to content

[BUG]Aggregation fails when grouping by timestamp-derived fields #4063

@ahkcs

Description

@ahkcs

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"
    );
}

Metadata

Metadata

Assignees

Labels

PPLPiped processing languagebugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions