Skip to content

Commit

Permalink
Make alias optional
Browse files Browse the repository at this point in the history
Signed-off-by: Hendrik Saly <hendrik.saly@eliatra.com>
  • Loading branch information
salyh committed Oct 30, 2024
1 parent 38a75a6 commit 2c04f75
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions docs/ppl-lang/ppl-trendline-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ Using ``trendline`` command to calculate moving averages of fields.


### Syntax
`TRENDLINE [sort <[+|-] sort-field>] SMA(number-of-datapoints, field) AS alias`
`TRENDLINE [sort <[+|-] sort-field>] SMA(number-of-datapoints, field) [AS alias]`

* [+|-]: optional. The plus [+] stands for ascending order and NULL/MISSING first and a minus [-] stands for descending order and NULL/MISSING last. **Default:** ascending order and NULL/MISSING first.
* sort-field: mandatory when sorting is used. The field used to sort.
* number-of-datapoints: mandatory. number of datapoints to calculate the moving average.
* number-of-datapoints: mandatory. number of datapoints to calculate the moving average (must be a positive integer).
* field: mandatory. the name of the field the moving average should be calculated for.
* alias: mandatory. the name of the resulting column containing the moving average.
* alias: optional. the name of the resulting column containing the moving average.

And the moment only the Simple Moving Average (SMA) type is supported.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ trendlineCommand
;

trendlineClause
: trendlineType LT_PRTHS numberOfDataPoints = integerLiteral COMMA field = fieldExpression RT_PRTHS AS alias = qualifiedName
: trendlineType LT_PRTHS numberOfDataPoints = integerLiteral COMMA field = fieldExpression RT_PRTHS (AS alias = qualifiedName)?
;

trendlineType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ private Trendline.TrendlineComputation toTrendlineComputation(OpenSearchPPLParse
throw new SyntaxCheckException("Number of trendline data-points must be greater than or equal to 0");
}
Field dataField = (Field) expressionBuilder.visitFieldExpression(ctx.field);
String alias = ctx.alias.getText();
String alias = ctx.alias == null?dataField.getField().toString()+"_trendline":ctx.alias.getText();
String computationType = ctx.trendlineType().getText();
return new Trendline.TrendlineComputation(numberOfDataPoints, dataField, alias, computationType);
}
Expand Down

0 comments on commit 2c04f75

Please sign in to comment.