|
5 | 5 |
|
6 | 6 | package org.opensearch.sql.calcite.remote; |
7 | 7 |
|
| 8 | +import static org.junit.Assert.assertThrows; |
8 | 9 | import static org.junit.Assert.assertTrue; |
9 | 10 | import static org.junit.jupiter.api.Assertions.assertThrows; |
10 | 11 | import static org.opensearch.sql.legacy.TestsConstants.*; |
@@ -988,6 +989,33 @@ public void testStatsWithBinsOnTimeAndTermField_Avg() throws IOException { |
988 | 989 | rows(40.25, "us-west", "2024-07-01 00:01:00")); |
989 | 990 | } |
990 | 991 |
|
| 992 | + @Test |
| 993 | + public void testBinsOnTimeFieldWithPushdownDisabled_ShouldFail() throws IOException { |
| 994 | + // Verify that bins parameter on timestamp fields fails with clear error when pushdown disabled |
| 995 | + enabledOnlyWhenPushdownIsDisabled(); |
| 996 | + |
| 997 | + ResponseException exception = |
| 998 | + assertThrows( |
| 999 | + ResponseException.class, |
| 1000 | + () -> |
| 1001 | + executeQuery( |
| 1002 | + "source=events_null | bin @timestamp bins=3 | stats count() by @timestamp")); |
| 1003 | + |
| 1004 | + // Verify the error message clearly explains the limitation and suggests solutions |
| 1005 | + // Note: bins parameter on timestamp fields requires BOTH: |
| 1006 | + // 1. Pushdown to be enabled (plugins.calcite.pushdown.enabled=true, enabled by default) |
| 1007 | + // 2. The timestamp field to be used as an aggregation bucket (e.g., stats count() by |
| 1008 | + // @timestamp) |
| 1009 | + String errorMessage = exception.getMessage(); |
| 1010 | + assertTrue( |
| 1011 | + "Expected clear error message about bins parameter requirements on timestamp fields, but" |
| 1012 | + + " got: " |
| 1013 | + + errorMessage, |
| 1014 | + errorMessage.contains("bins' parameter on timestamp fields requires") |
| 1015 | + && errorMessage.contains("pushdown to be enabled") |
| 1016 | + && errorMessage.contains("aggregation bucket")); |
| 1017 | + } |
| 1018 | + |
991 | 1019 | @Test |
992 | 1020 | public void testBinWithNestedFieldWithoutExplicitProjection() throws IOException { |
993 | 1021 | // Test bin command on nested field without explicit fields projection |
|
0 commit comments