Skip to content

Commit 2527522

Browse files
committed
Fix AST relevant tests
Signed-off-by: Yuanchun Shen <[email protected]>
1 parent 2030961 commit 2527522

File tree

3 files changed

+178
-100
lines changed

3 files changed

+178
-100
lines changed

ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest.java

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
import org.opensearch.sql.ast.tree.Kmeans;
8080
import org.opensearch.sql.ast.tree.ML;
8181
import org.opensearch.sql.ast.tree.RareTopN.CommandType;
82-
import org.opensearch.sql.ast.tree.Timechart;
8382
import org.opensearch.sql.common.antlr.SyntaxCheckException;
8483
import org.opensearch.sql.common.setting.Settings;
8584
import org.opensearch.sql.common.setting.Settings.Key;
@@ -1229,10 +1228,17 @@ public void testTimechartWithPerSecondFunction() {
12291228
assertEqual(
12301229
"source=t | timechart per_second(a)",
12311230
eval(
1232-
new Timechart(relation("t"), alias("per_second(a)", aggregate("sum", field("a"))))
1233-
.span(span(field("@timestamp"), intLiteral(1), SpanUnit.of("m")))
1234-
.limit(10)
1235-
.useOther(true),
1231+
Chart.builder()
1232+
.child(relation("t"))
1233+
.rowSplit(
1234+
alias("@timestamp", span(field("@timestamp"), intLiteral(1), SpanUnit.of("m"))))
1235+
.columnSplit(null)
1236+
.aggregationFunction(alias("per_second(a)", aggregate("sum", field("a"))))
1237+
.arguments(
1238+
exprList(
1239+
argument("limit", intLiteral(10)),
1240+
argument("useother", booleanLiteral(true))))
1241+
.build(),
12361242
let(
12371243
field("per_second(a)"),
12381244
function(
@@ -1254,10 +1260,17 @@ public void testTimechartWithPerMinuteFunction() {
12541260
assertEqual(
12551261
"source=t | timechart per_minute(a)",
12561262
eval(
1257-
new Timechart(relation("t"), alias("per_minute(a)", aggregate("sum", field("a"))))
1258-
.span(span(field("@timestamp"), intLiteral(1), SpanUnit.of("m")))
1259-
.limit(10)
1260-
.useOther(true),
1263+
Chart.builder()
1264+
.child(relation("t"))
1265+
.rowSplit(
1266+
alias("@timestamp", span(field("@timestamp"), intLiteral(1), SpanUnit.of("m"))))
1267+
.columnSplit(null)
1268+
.aggregationFunction(alias("per_minute(a)", aggregate("sum", field("a"))))
1269+
.arguments(
1270+
exprList(
1271+
argument("limit", intLiteral(10)),
1272+
argument("useother", booleanLiteral(true))))
1273+
.build(),
12611274
let(
12621275
field("per_minute(a)"),
12631276
function(
@@ -1279,10 +1292,17 @@ public void testTimechartWithPerHourFunction() {
12791292
assertEqual(
12801293
"source=t | timechart per_hour(a)",
12811294
eval(
1282-
new Timechart(relation("t"), alias("per_hour(a)", aggregate("sum", field("a"))))
1283-
.span(span(field("@timestamp"), intLiteral(1), SpanUnit.of("m")))
1284-
.limit(10)
1285-
.useOther(true),
1295+
Chart.builder()
1296+
.child(relation("t"))
1297+
.rowSplit(
1298+
alias("@timestamp", span(field("@timestamp"), intLiteral(1), SpanUnit.of("m"))))
1299+
.columnSplit(null)
1300+
.aggregationFunction(alias("per_hour(a)", aggregate("sum", field("a"))))
1301+
.arguments(
1302+
exprList(
1303+
argument("limit", intLiteral(10)),
1304+
argument("useother", booleanLiteral(true))))
1305+
.build(),
12861306
let(
12871307
field("per_hour(a)"),
12881308
function(
@@ -1304,10 +1324,17 @@ public void testTimechartWithPerDayFunction() {
13041324
assertEqual(
13051325
"source=t | timechart per_day(a)",
13061326
eval(
1307-
new Timechart(relation("t"), alias("per_day(a)", aggregate("sum", field("a"))))
1308-
.span(span(field("@timestamp"), intLiteral(1), SpanUnit.of("m")))
1309-
.limit(10)
1310-
.useOther(true),
1327+
Chart.builder()
1328+
.child(relation("t"))
1329+
.rowSplit(
1330+
alias("@timestamp", span(field("@timestamp"), intLiteral(1), SpanUnit.of("m"))))
1331+
.columnSplit(null)
1332+
.aggregationFunction(alias("per_day(a)", aggregate("sum", field("a"))))
1333+
.arguments(
1334+
exprList(
1335+
argument("limit", intLiteral(10)),
1336+
argument("useother", booleanLiteral(true))))
1337+
.build(),
13111338
let(
13121339
field("per_day(a)"),
13131340
function(

ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java

Lines changed: 133 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
import org.opensearch.sql.ast.expression.DataType;
6464
import org.opensearch.sql.ast.expression.RelevanceFieldList;
6565
import org.opensearch.sql.ast.expression.SpanUnit;
66-
import org.opensearch.sql.ast.tree.Timechart;
66+
import org.opensearch.sql.ast.tree.Chart;
6767
import org.opensearch.sql.calcite.plan.OpenSearchConstants;
6868
import 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

ppl/src/test/java/org/opensearch/sql/ppl/utils/PPLQueryDataAnonymizerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public void testReverseCommand() {
255255
@Test
256256
public void testTimechartCommand() {
257257
assertEquals(
258-
"source=table | timechart span=span(identifier, *** m) limit=10 useother=true count() by"
258+
"source=table | timechart limit=*** useother=*** count() by span(identifier, *** m)"
259259
+ " identifier",
260260
anonymize("source=t | timechart count() by host"));
261261
}

0 commit comments

Comments
 (0)