|
63 | 63 | import org.opensearch.sql.ast.expression.SearchAnd; |
64 | 64 | import org.opensearch.sql.ast.expression.SearchExpression; |
65 | 65 | import org.opensearch.sql.ast.expression.SearchGroup; |
66 | | -import org.opensearch.sql.ast.expression.Span; |
67 | | -import org.opensearch.sql.ast.expression.SpanUnit; |
68 | 66 | import org.opensearch.sql.ast.expression.UnresolvedArgument; |
69 | 67 | import org.opensearch.sql.ast.expression.UnresolvedExpression; |
70 | 68 | import org.opensearch.sql.ast.expression.WindowFrame; |
@@ -743,41 +741,28 @@ private List<UnresolvedExpression> parseAggTerms( |
743 | 741 | /** Timechart command. */ |
744 | 742 | @Override |
745 | 743 | public UnresolvedPlan visitTimechartCommand(OpenSearchPPLParser.TimechartCommandContext ctx) { |
746 | | - UnresolvedExpression binExpression = |
747 | | - AstDSL.span(AstDSL.implicitTimestampField(), AstDSL.intLiteral(1), SpanUnit.m); |
748 | | - Integer limit = 10; |
749 | | - Boolean useOther = true; |
750 | | - // Process timechart parameters |
751 | | - for (OpenSearchPPLParser.TimechartParameterContext paramCtx : ctx.timechartParameter()) { |
752 | | - UnresolvedExpression param = internalVisitExpression(paramCtx); |
753 | | - if (param instanceof Span) { |
754 | | - binExpression = param; |
755 | | - } else if (param instanceof Literal literal) { |
756 | | - if (DataType.BOOLEAN.equals(literal.getType())) { |
757 | | - useOther = (Boolean) literal.getValue(); |
758 | | - } else if (DataType.INTEGER.equals(literal.getType()) |
759 | | - || DataType.LONG.equals(literal.getType())) { |
760 | | - limit = (Integer) literal.getValue(); |
761 | | - } |
762 | | - } |
763 | | - } |
| 744 | + List<Argument> arguments = ArgumentFactory.getArgumentList(ctx, expressionBuilder); |
| 745 | + ArgumentMap argMap = ArgumentMap.of(arguments); |
| 746 | + Literal spanLiteral = argMap.getOrDefault("spanliteral", AstDSL.stringLiteral("1m")); |
| 747 | + String timeFieldName = |
| 748 | + Optional.ofNullable(argMap.get("timefield")) |
| 749 | + .map(l -> (String) l.getValue()) |
| 750 | + .orElse(OpenSearchConstants.IMPLICIT_FIELD_TIMESTAMP); |
| 751 | + Field spanField = AstDSL.field(timeFieldName); |
| 752 | + Alias span = |
| 753 | + AstDSL.alias(timeFieldName, AstDSL.spanFromSpanLengthLiteral(spanField, spanLiteral)); |
764 | 754 | UnresolvedExpression aggregateFunction = parseAggTerms(List.of(ctx.statsAggTerm())).getFirst(); |
765 | | - |
766 | 755 | UnresolvedExpression byField = |
767 | | - ctx.fieldExpression() != null ? internalVisitExpression(ctx.fieldExpression()) : null; |
768 | | - List<Argument> arguments = |
769 | | - List.of( |
770 | | - new Argument("limit", AstDSL.intLiteral(limit)), |
771 | | - new Argument("useother", AstDSL.booleanLiteral(useOther))); |
772 | | - binExpression = AstDSL.alias(OpenSearchConstants.IMPLICIT_FIELD_TIMESTAMP, binExpression); |
773 | | - if (byField != null) { |
774 | | - byField = |
775 | | - AstDSL.alias( |
776 | | - StringUtils.unquoteIdentifier(getTextInQuery(ctx.fieldExpression())), byField); |
777 | | - } |
| 756 | + Optional.ofNullable(ctx.fieldExpression()) |
| 757 | + .map( |
| 758 | + f -> |
| 759 | + AstDSL.alias( |
| 760 | + StringUtils.unquoteIdentifier(getTextInQuery(f)), |
| 761 | + internalVisitExpression(f))) |
| 762 | + .orElse(null); |
778 | 763 | return Chart.builder() |
779 | 764 | .aggregationFunction(aggregateFunction) |
780 | | - .rowSplit(binExpression) |
| 765 | + .rowSplit(span) |
781 | 766 | .columnSplit(byField) |
782 | 767 | .arguments(arguments) |
783 | 768 | .build(); |
|
0 commit comments