From 071b8520f21ddc0db7d13813ddd33e79ddacb13b Mon Sep 17 00:00:00 2001 From: Tomoyuki MORITA Date: Thu, 25 Jul 2024 18:08:25 -0700 Subject: [PATCH] Disable unsupported PPL function expressions (#478) Signed-off-by: Tomoyuki Morita (cherry picked from commit 98bd79a6ea1d9587d67ae761d417b0db4242a815) --- ppl-spark-integration/README.md | 2 +- .../src/main/antlr4/OpenSearchPPLParser.g4 | 9 +------- .../sql/ppl/parser/AstExpressionBuilder.java | 23 ------------------- 3 files changed, 2 insertions(+), 32 deletions(-) diff --git a/ppl-spark-integration/README.md b/ppl-spark-integration/README.md index ecd043acd..61ef5b670 100644 --- a/ppl-spark-integration/README.md +++ b/ppl-spark-integration/README.md @@ -262,7 +262,7 @@ The next samples of PPL queries are currently supported: - `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) - `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) diff --git a/ppl-spark-integration/src/main/antlr4/OpenSearchPPLParser.g4 b/ppl-spark-integration/src/main/antlr4/OpenSearchPPLParser.g4 index f6cd0d4ee..086413ca4 100644 --- a/ppl-spark-integration/src/main/antlr4/OpenSearchPPLParser.g4 +++ b/ppl-spark-integration/src/main/antlr4/OpenSearchPPLParser.g4 @@ -33,7 +33,6 @@ commands : whereCommand | correlateCommand | fieldsCommand - | renameCommand | statsCommand | sortCommand | headCommand @@ -224,8 +223,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 @@ -257,8 +254,6 @@ logicalExpression | left = logicalExpression OR right = logicalExpression # logicalOr | left = logicalExpression (AND)? right = logicalExpression # logicalAnd | left = logicalExpression XOR right = logicalExpression # logicalXor - | booleanExpression # booleanExpr - | relevanceExpression # relevanceExpr ; comparisonExpression @@ -266,9 +261,7 @@ comparisonExpression ; 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 ; diff --git a/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java b/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java index 8cfbc15d5..501ddb6ea 100644 --- a/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java +++ b/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java @@ -111,15 +111,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 @@ -171,20 +162,6 @@ public UnresolvedExpression visitPercentileAggFunction(OpenSearchPPLParser.Perce Collections.singletonList(new Argument("rank", (Literal) visit(ctx.value)))); } - @Override - public UnresolvedExpression visitTakeAggFunctionCall( - OpenSearchPPLParser.TakeAggFunctionCallContext ctx) { - ImmutableList.Builder 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. */