Skip to content

Commit

Permalink
Disable unsupported PPL function expressions
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoyuki Morita <[email protected]>
  • Loading branch information
ykmr1224 committed Jul 25, 2024
1 parent 538dd54 commit eb36ede
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 31 deletions.
3 changes: 2 additions & 1 deletion ppl-spark-integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ The next samples of PPL queries are currently supported:
- `search` - [See details](https://github.com/opensearch-project/sql/blob/main/docs/user/ppl/cmd/search.rst)
- `where` - [See details](https://github.com/opensearch-project/sql/blob/main/docs/user/ppl/cmd/where.rst)
- `fields` - [See details](https://github.com/opensearch-project/sql/blob/main/docs/user/ppl/cmd/fields.rst)
- `rename` - [See details](https://github.com/opensearch-project/sql/blob/main/docs/user/ppl/cmd/rename.rst)
- `head` - [See details](https://github.com/opensearch-project/sql/blob/main/docs/user/ppl/cmd/head.rst)
- `stats` - [See details](https://github.com/opensearch-project/sql/blob/main/docs/user/ppl/cmd/stats.rst) (supports AVG, COUNT, MAX, MIN and SUM aggregation functions)
- `stats` - [See details](https://github.com/opensearch-project/sql/blob/main/docs/user/ppl/cmd/stats.rst) (supports AVG, COUNT, DISTINCT_COUNT, MAX, MIN and SUM aggregation functions)
- `sort` - [See details](https://github.com/opensearch-project/sql/blob/main/docs/user/ppl/cmd/sort.rst)
- `correlation` - [See details](../docs/PPL-Correlation-command.md)

Expand Down
8 changes: 1 addition & 7 deletions ppl-spark-integration/src/main/antlr4/OpenSearchPPLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ statsFunction
: statsFunctionName LT_PRTHS valueExpression RT_PRTHS # statsFunctionCall
| COUNT LT_PRTHS RT_PRTHS # countAllFunctionCall
| (DISTINCT_COUNT | DC) LT_PRTHS valueExpression RT_PRTHS # distinctCountFunctionCall
| percentileAggFunction # percentileAggFunctionCall
| takeAggFunction # takeAggFunctionCall
;

statsFunctionName
Expand Down Expand Up @@ -257,18 +255,14 @@ logicalExpression
| left = logicalExpression OR right = logicalExpression # logicalOr
| left = logicalExpression (AND)? right = logicalExpression # logicalAnd
| left = logicalExpression XOR right = logicalExpression # logicalXor
| booleanExpression # booleanExpr
| relevanceExpression # relevanceExpr
;

comparisonExpression
: left = valueExpression comparisonOperator right = valueExpression # compareExpr
;

valueExpression
: left = valueExpression binaryOperator = (STAR | DIVIDE | MODULE) right = valueExpression # binaryArithmetic
| left = valueExpression binaryOperator = (PLUS | MINUS) right = valueExpression # binaryArithmetic
| primaryExpression # valueExpressionDefault
: primaryExpression # valueExpressionDefault
| LT_PRTHS valueExpression RT_PRTHS # parentheticValueExpr
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,6 @@ public UnresolvedExpression visitCompareExpr(OpenSearchPPLParser.CompareExprCont
return new Compare(ctx.comparisonOperator().getText(), visit(ctx.left), visit(ctx.right));
}

/**
* Value Expression.
*/
@Override
public UnresolvedExpression visitBinaryArithmetic(OpenSearchPPLParser.BinaryArithmeticContext ctx) {
return new Function(
ctx.binaryOperator.getText(), Arrays.asList(visit(ctx.left), visit(ctx.right)));
}

@Override
public UnresolvedExpression visitParentheticValueExpr(OpenSearchPPLParser.ParentheticValueExprContext ctx) {
return visit(ctx.valueExpression()); // Discard parenthesis around
Expand Down Expand Up @@ -172,20 +163,6 @@ public UnresolvedExpression visitPercentileAggFunction(OpenSearchPPLParser.Perce
Collections.singletonList(new Argument("rank", (Literal) visit(ctx.value))));
}

@Override
public UnresolvedExpression visitTakeAggFunctionCall(
OpenSearchPPLParser.TakeAggFunctionCallContext ctx) {
ImmutableList.Builder<UnresolvedExpression> builder = ImmutableList.builder();
builder.add(
new UnresolvedArgument(
"size",
ctx.takeAggFunction().size != null
? visit(ctx.takeAggFunction().size)
: new Literal(DEFAULT_TAKE_FUNCTION_SIZE_VALUE, DataType.INTEGER)));
return new AggregateFunction(
"take", visit(ctx.takeAggFunction().fieldExpression()), builder.build());
}

/**
* Eval function.
*/
Expand Down

0 comments on commit eb36ede

Please sign in to comment.