Skip to content

Commit 9318f62

Browse files
committed
Omit by-timestamp clause in timechart command
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 6adb081 commit 9318f62

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

ppl/src/main/java/org/opensearch/sql/ppl/utils/PPLQueryDataAnonymizer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,11 @@ public String visitChart(Chart node, String context) {
522522
chartCommand.append(" ").append(visitExpression(node.getAggregationFunction()));
523523

524524
if (node.getRowSplit() != null && node.getColumnSplit() != null) {
525-
chartCommand
526-
.append(" by ")
527-
.append(visitExpression(node.getRowSplit()))
528-
.append(" ")
529-
.append(visitExpression(node.getColumnSplit()));
530-
} else if (node.getRowSplit() != null) {
525+
chartCommand.append(" by");
526+
// timechart command does not have to explicit the by-timestamp field clause
527+
if (!isTimechart) chartCommand.append(" ").append(visitExpression(node.getRowSplit()));
528+
chartCommand.append(" ").append(visitExpression(node.getColumnSplit()));
529+
} else if (node.getRowSplit() != null && !isTimechart) {
531530
chartCommand.append(" by ").append(visitExpression(node.getRowSplit()));
532531
} else if (node.getColumnSplit() != null) {
533532
chartCommand.append(" by ").append(visitExpression(node.getColumnSplit()));

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,12 @@ public void testReverseCommand() {
255255
@Test
256256
public void testTimechartCommand() {
257257
assertEquals(
258-
"source=table | timechart count() by span(time_identifier, *** m) identifier",
258+
"source=table | timechart count() by identifier",
259259
anonymize("source=t | timechart count() by host"));
260+
261+
assertEquals(
262+
"source=table | timechart max(identifier)",
263+
anonymize("source=t | timechart max(revenue)"));
260264
}
261265

262266
@Test

0 commit comments

Comments
 (0)