6363import org .opensearch .sql .ast .expression .DataType ;
6464import org .opensearch .sql .ast .expression .RelevanceFieldList ;
6565import org .opensearch .sql .ast .expression .SpanUnit ;
66- import org .opensearch .sql .ast .tree .Timechart ;
66+ import org .opensearch .sql .ast .tree .Chart ;
6767import org .opensearch .sql .calcite .plan .OpenSearchConstants ;
6868import org .opensearch .sql .common .antlr .SyntaxCheckException ;
6969
@@ -1395,31 +1395,39 @@ public void testTimeModifierEarliestWithStringValue() {
13951395 public void testTimechartSpanParameter () {
13961396 assertEqual (
13971397 "source=t | timechart span=30m count()" ,
1398- Timechart .builder ()
1398+ Chart .builder ()
13991399 .child (relation ("t" ))
1400- .binExpression (
1401- span (
1402- field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ),
1403- intLiteral (30 ),
1404- SpanUnit .m ))
1405- .aggregateFunction (aggregate ("count" , allFields ()))
1406- .limit (10 )
1407- .useOther (true )
1400+ .rowSplit (
1401+ alias (
1402+ "@timestamp" ,
1403+ span (
1404+ field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ),
1405+ intLiteral (30 ),
1406+ SpanUnit .m )))
1407+ .aggregationFunction (alias ("count()" , aggregate ("count" , allFields ())))
1408+ .arguments (
1409+ exprList (
1410+ argument ("limit" , intLiteral (10 )), argument ("useother" , booleanLiteral (true ))))
14081411 .build ());
14091412 }
14101413
14111414 @ Test
14121415 public void testTimechartLimitParameter () {
14131416 assertEqual (
14141417 "source=t | timechart limit=100 count()" ,
1415- Timechart .builder ()
1418+ Chart .builder ()
14161419 .child (relation ("t" ))
1417- .binExpression (
1418- span (
1419- field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ), intLiteral (1 ), SpanUnit .m ))
1420- .aggregateFunction (aggregate ("count" , allFields ()))
1421- .limit (100 )
1422- .useOther (true )
1420+ .rowSplit (
1421+ alias (
1422+ "@timestamp" ,
1423+ span (
1424+ field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ),
1425+ intLiteral (1 ),
1426+ SpanUnit .m )))
1427+ .aggregationFunction (alias ("count()" , aggregate ("count" , allFields ())))
1428+ .arguments (
1429+ exprList (
1430+ argument ("limit" , intLiteral (100 )), argument ("useother" , booleanLiteral (true ))))
14231431 .build ());
14241432 }
14251433
@@ -1434,77 +1442,107 @@ public void testTimechartNegativeLimitParameter() {
14341442 public void testTimechartUseOtherWithBooleanLiteral () {
14351443 assertEqual (
14361444 "source=t | timechart useother=true count()" ,
1437- Timechart .builder ()
1445+ Chart .builder ()
14381446 .child (relation ("t" ))
1439- .binExpression (
1440- span (
1441- field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ), intLiteral (1 ), SpanUnit .m ))
1442- .aggregateFunction (aggregate ("count" , allFields ()))
1443- .limit (10 )
1444- .useOther (true )
1447+ .rowSplit (
1448+ alias (
1449+ "@timestamp" ,
1450+ span (
1451+ field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ),
1452+ intLiteral (1 ),
1453+ SpanUnit .m )))
1454+ .aggregationFunction (alias ("count()" , aggregate ("count" , allFields ())))
1455+ .arguments (
1456+ exprList (
1457+ argument ("limit" , intLiteral (10 )), argument ("useother" , booleanLiteral (true ))))
14451458 .build ());
14461459
14471460 assertEqual (
14481461 "source=t | timechart useother=false count()" ,
1449- Timechart .builder ()
1462+ Chart .builder ()
14501463 .child (relation ("t" ))
1451- .binExpression (
1452- span (
1453- field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ), intLiteral (1 ), SpanUnit .m ))
1454- .aggregateFunction (aggregate ("count" , allFields ()))
1455- .limit (10 )
1456- .useOther (false )
1464+ .rowSplit (
1465+ alias (
1466+ "@timestamp" ,
1467+ span (
1468+ field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ),
1469+ intLiteral (1 ),
1470+ SpanUnit .m )))
1471+ .aggregationFunction (alias ("count()" , aggregate ("count" , allFields ())))
1472+ .arguments (
1473+ exprList (
1474+ argument ("limit" , intLiteral (10 )), argument ("useother" , booleanLiteral (false ))))
14571475 .build ());
14581476 }
14591477
14601478 @ Test
14611479 public void testTimechartUseOtherWithIdentifier () {
14621480 assertEqual (
14631481 "source=t | timechart useother=t count()" ,
1464- Timechart .builder ()
1482+ Chart .builder ()
14651483 .child (relation ("t" ))
1466- .binExpression (
1467- span (
1468- field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ), intLiteral (1 ), SpanUnit .m ))
1469- .aggregateFunction (aggregate ("count" , allFields ()))
1470- .limit (10 )
1471- .useOther (true )
1484+ .rowSplit (
1485+ alias (
1486+ "@timestamp" ,
1487+ span (
1488+ field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ),
1489+ intLiteral (1 ),
1490+ SpanUnit .m )))
1491+ .aggregationFunction (alias ("count()" , aggregate ("count" , allFields ())))
1492+ .arguments (
1493+ exprList (
1494+ argument ("limit" , intLiteral (10 )), argument ("useother" , booleanLiteral (true ))))
14721495 .build ());
14731496
14741497 assertEqual (
14751498 "source=t | timechart useother=f count()" ,
1476- Timechart .builder ()
1499+ Chart .builder ()
14771500 .child (relation ("t" ))
1478- .binExpression (
1479- span (
1480- field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ), intLiteral (1 ), SpanUnit .m ))
1481- .aggregateFunction (aggregate ("count" , allFields ()))
1482- .limit (10 )
1483- .useOther (false )
1501+ .rowSplit (
1502+ alias (
1503+ "@timestamp" ,
1504+ span (
1505+ field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ),
1506+ intLiteral (1 ),
1507+ SpanUnit .m )))
1508+ .aggregationFunction (alias ("count()" , aggregate ("count" , allFields ())))
1509+ .arguments (
1510+ exprList (
1511+ argument ("limit" , intLiteral (10 )), argument ("useother" , booleanLiteral (false ))))
14841512 .build ());
14851513
14861514 assertEqual (
14871515 "source=t | timechart useother=TRUE count()" ,
1488- Timechart .builder ()
1516+ Chart .builder ()
14891517 .child (relation ("t" ))
1490- .binExpression (
1491- span (
1492- field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ), intLiteral (1 ), SpanUnit .m ))
1493- .aggregateFunction (aggregate ("count" , allFields ()))
1494- .limit (10 )
1495- .useOther (true )
1518+ .rowSplit (
1519+ alias (
1520+ "@timestamp" ,
1521+ span (
1522+ field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ),
1523+ intLiteral (1 ),
1524+ SpanUnit .m )))
1525+ .aggregationFunction (alias ("count()" , aggregate ("count" , allFields ())))
1526+ .arguments (
1527+ exprList (
1528+ argument ("limit" , intLiteral (10 )), argument ("useother" , booleanLiteral (true ))))
14961529 .build ());
14971530
14981531 assertEqual (
14991532 "source=t | timechart useother=FALSE count()" ,
1500- Timechart .builder ()
1533+ Chart .builder ()
15011534 .child (relation ("t" ))
1502- .binExpression (
1503- span (
1504- field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ), intLiteral (1 ), SpanUnit .m ))
1505- .aggregateFunction (aggregate ("count" , allFields ()))
1506- .limit (10 )
1507- .useOther (false )
1535+ .rowSplit (
1536+ alias (
1537+ "@timestamp" ,
1538+ span (
1539+ field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ),
1540+ intLiteral (1 ),
1541+ SpanUnit .m )))
1542+ .aggregationFunction (alias ("count()" , aggregate ("count" , allFields ())))
1543+ .arguments (
1544+ exprList (
1545+ argument ("limit" , intLiteral (10 )), argument ("useother" , booleanLiteral (false ))))
15081546 .build ());
15091547 }
15101548
@@ -1568,42 +1606,55 @@ public void testVisitSpanLiteral() {
15681606 // Test span literal with integer value and hour unit
15691607 assertEqual (
15701608 "source=t | timechart span=1h count()" ,
1571- Timechart .builder ()
1609+ Chart .builder ()
15721610 .child (relation ("t" ))
1573- .binExpression (
1574- span (
1575- field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ), intLiteral (1 ), SpanUnit .H ))
1576- .aggregateFunction (aggregate ("count" , allFields ()))
1577- .limit (10 )
1578- .useOther (true )
1611+ .rowSplit (
1612+ alias (
1613+ "@timestamp" ,
1614+ span (
1615+ field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ),
1616+ intLiteral (1 ),
1617+ SpanUnit .H )))
1618+ .aggregationFunction (alias ("count()" , aggregate ("count" , allFields ())))
1619+ .arguments (
1620+ exprList (
1621+ argument ("limit" , intLiteral (10 )), argument ("useother" , booleanLiteral (true ))))
15791622 .build ());
15801623
15811624 // Test span literal with decimal value and minute unit
15821625 assertEqual (
15831626 "source=t | timechart span=2m count()" ,
1584- Timechart .builder ()
1627+ Chart .builder ()
15851628 .child (relation ("t" ))
1586- .binExpression (
1587- span (
1588- field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ), intLiteral (2 ), SpanUnit .m ))
1589- .aggregateFunction (aggregate ("count" , allFields ()))
1590- .limit (10 )
1591- .useOther (true )
1629+ .rowSplit (
1630+ alias (
1631+ "@timestamp" ,
1632+ span (
1633+ field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ),
1634+ intLiteral (2 ),
1635+ SpanUnit .m )))
1636+ .aggregationFunction (alias ("count()" , aggregate ("count" , allFields ())))
1637+ .arguments (
1638+ exprList (
1639+ argument ("limit" , intLiteral (10 )), argument ("useother" , booleanLiteral (true ))))
15921640 .build ());
15931641
15941642 // Test span literal without unit (should use NONE unit)
15951643 assertEqual (
15961644 "source=t | timechart span=10 count()" ,
1597- Timechart .builder ()
1645+ Chart .builder ()
15981646 .child (relation ("t" ))
1599- .binExpression (
1600- span (
1601- field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ),
1602- intLiteral (10 ),
1603- SpanUnit .NONE ))
1604- .aggregateFunction (aggregate ("count" , allFields ()))
1605- .limit (10 )
1606- .useOther (true )
1647+ .rowSplit (
1648+ alias (
1649+ "@timestamp" ,
1650+ span (
1651+ field (OpenSearchConstants .IMPLICIT_FIELD_TIMESTAMP ),
1652+ intLiteral (10 ),
1653+ SpanUnit .NONE )))
1654+ .aggregationFunction (alias ("count()" , aggregate ("count" , allFields ())))
1655+ .arguments (
1656+ exprList (
1657+ argument ("limit" , intLiteral (10 )), argument ("useother" , booleanLiteral (true ))))
16071658 .build ());
16081659 }
16091660
0 commit comments