55
66package org .opensearch .sql .calcite .remote ;
77
8+ import static org .opensearch .sql .util .MatcherUtils .closeTo ;
89import static org .opensearch .sql .util .MatcherUtils .rows ;
910import static org .opensearch .sql .util .MatcherUtils .schema ;
1011import static org .opensearch .sql .util .MatcherUtils .verifyDataRows ;
1314import java .io .IOException ;
1415import org .json .JSONObject ;
1516import org .junit .jupiter .api .Test ;
17+ import org .opensearch .sql .common .utils .StringUtils ;
18+ import org .opensearch .sql .legacy .TestsConstants ;
1619import org .opensearch .sql .ppl .PPLIntegTestCase ;
1720
1821public class CalciteTimechartPerFunctionIT extends PPLIntegTestCase {
@@ -24,6 +27,7 @@ public void init() throws Exception {
2427 disallowCalciteFallback ();
2528
2629 loadIndex (Index .EVENTS_TRAFFIC );
30+ loadIndex (Index .BANK );
2731 }
2832
2933 @ Test
@@ -208,4 +212,26 @@ public void testTimechartPerDayWithByClause() throws IOException {
208212 rows ("2025-09-08 10:02:00" , "server1" , 43200.0 ), // 60 * 720
209213 rows ("2025-09-08 10:02:00" , "server2" , 129600.0 )); // 180 * 720
210214 }
215+
216+ @ Test
217+ public void testTimechartPerMonthWithSpecifiedSpan () throws IOException {
218+ JSONObject result =
219+ executeQuery (
220+ StringUtils .format (
221+ "source=%s | timechart timefield=birthdate span=1month per_day(balance) by gender" ,
222+ TestsConstants .TEST_INDEX_BANK ));
223+ verifySchema (
224+ result ,
225+ schema ("birthdate" , "timestamp" ),
226+ schema ("gender" , "string" ),
227+ schema ("per_day(balance)" , "double" ));
228+ verifyDataRows (
229+ result ,
230+ closeTo ("2017-10-01 00:00:00" , "M" , 1265.3225806451612 ),
231+ closeTo ("2017-11-01 00:00:00" , "M" , 189.53333333333333 ),
232+ closeTo ("2018-06-01 00:00:00" , "F" , 1094.6 ),
233+ closeTo ("2018-06-01 00:00:00" , "M" , 547.2666666666667 ),
234+ closeTo ("2018-08-01 00:00:00" , "F" , 2858.9032258064517 ),
235+ closeTo ("2018-11-01 00:00:00" , "M" , 139.33333333333334 ));
236+ }
211237}
0 commit comments