|
56 | 56 | import org.opensearch.sql.ast.tree.Append; |
57 | 57 | import org.opensearch.sql.ast.tree.AppendCol; |
58 | 58 | import org.opensearch.sql.ast.tree.Bin; |
| 59 | +import org.opensearch.sql.ast.tree.Chart; |
59 | 60 | import org.opensearch.sql.ast.tree.CountBin; |
60 | 61 | import org.opensearch.sql.ast.tree.Dedupe; |
61 | 62 | import org.opensearch.sql.ast.tree.DefaultBin; |
@@ -520,6 +521,42 @@ public String visitTimechart(Timechart node, String context) { |
520 | 521 | return StringUtils.format("%s%s", child, timechartCommand.toString()); |
521 | 522 | } |
522 | 523 |
|
| 524 | + @Override |
| 525 | + public String visitChart(Chart node, String context) { |
| 526 | + String child = node.getChild().get(0).accept(this, context); |
| 527 | + StringBuilder chartCommand = new StringBuilder(); |
| 528 | + chartCommand.append(" | chart"); |
| 529 | + |
| 530 | + for (Argument arg : node.getArguments()) { |
| 531 | + String argName = arg.getArgName(); |
| 532 | + // Skip the auto-generated "top" parameter that's added when limit is specified |
| 533 | + if ("top".equals(argName)) { |
| 534 | + continue; |
| 535 | + } |
| 536 | + if ("limit".equals(argName) || "useother".equals(argName) || "usenull".equals(argName)) { |
| 537 | + chartCommand.append(" ").append(argName).append("=").append(MASK_LITERAL); |
| 538 | + } else if ("otherstr".equals(argName) || "nullstr".equals(argName)) { |
| 539 | + chartCommand.append(" ").append(argName).append("=").append(MASK_LITERAL); |
| 540 | + } |
| 541 | + } |
| 542 | + |
| 543 | + chartCommand.append(" ").append(visitExpression(node.getAggregationFunction())); |
| 544 | + |
| 545 | + if (node.getRowSplit() != null && node.getColumnSplit() != null) { |
| 546 | + chartCommand |
| 547 | + .append(" by ") |
| 548 | + .append(visitExpression(node.getRowSplit())) |
| 549 | + .append(" ") |
| 550 | + .append(visitExpression(node.getColumnSplit())); |
| 551 | + } else if (node.getRowSplit() != null) { |
| 552 | + chartCommand.append(" by ").append(visitExpression(node.getRowSplit())); |
| 553 | + } else if (node.getColumnSplit() != null) { |
| 554 | + chartCommand.append(" by ").append(visitExpression(node.getColumnSplit())); |
| 555 | + } |
| 556 | + |
| 557 | + return StringUtils.format("%s%s", child, chartCommand.toString()); |
| 558 | + } |
| 559 | + |
523 | 560 | public String visitRex(Rex node, String context) { |
524 | 561 | String child = node.getChild().get(0).accept(this, context); |
525 | 562 | String field = visitExpression(node.getField()); |
|
0 commit comments