diff --git a/ppl-spark-integration/src/main/antlr4/OpenSearchPPLParser.g4 b/ppl-spark-integration/src/main/antlr4/OpenSearchPPLParser.g4 index 32b5f3f17..efeaac85f 100644 --- a/ppl-spark-integration/src/main/antlr4/OpenSearchPPLParser.g4 +++ b/ppl-spark-integration/src/main/antlr4/OpenSearchPPLParser.g4 @@ -87,7 +87,7 @@ mappingClause ; fieldsCommand - : FIELDS (PLUS | MINUS)? fieldList + : FIELDS (PLUS)? fieldList ; renameCommand diff --git a/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/utils/ArgumentFactory.java b/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/utils/ArgumentFactory.java index 43f696bcd..9fb97f4e7 100644 --- a/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/utils/ArgumentFactory.java +++ b/ppl-spark-integration/src/main/java/org/opensearch/sql/ppl/utils/ArgumentFactory.java @@ -25,10 +25,7 @@ public class ArgumentFactory { * @return the list of arguments fetched from the fields command */ public static List getArgumentList(OpenSearchPPLParser.FieldsCommandContext ctx) { - return Collections.singletonList( - ctx.MINUS() != null - ? new Argument("exclude", new Literal(true, DataType.BOOLEAN)) - : new Argument("exclude", new Literal(false, DataType.BOOLEAN))); + return Collections.singletonList(new Argument("exclude", new Literal(false, DataType.BOOLEAN))); } /** diff --git a/ppl-spark-integration/src/test/scala/org/opensearch/flint/spark/ppl/PPLLogicalPlanBasicQueriesTranslatorTestSuite.scala b/ppl-spark-integration/src/test/scala/org/opensearch/flint/spark/ppl/PPLLogicalPlanBasicQueriesTranslatorTestSuite.scala index 59f5e8eb6..59e755cb9 100644 --- a/ppl-spark-integration/src/test/scala/org/opensearch/flint/spark/ppl/PPLLogicalPlanBasicQueriesTranslatorTestSuite.scala +++ b/ppl-spark-integration/src/test/scala/org/opensearch/flint/spark/ppl/PPLLogicalPlanBasicQueriesTranslatorTestSuite.scala @@ -6,6 +6,7 @@ package org.opensearch.flint.spark.ppl import org.opensearch.flint.spark.ppl.PlaneUtils.plan +import org.opensearch.sql.common.antlr.SyntaxCheckException import org.opensearch.sql.ppl.{CatalystPlanContext, CatalystQueryPlanVisitor} import org.scalatest.matchers.should.Matchers @@ -293,4 +294,33 @@ class PPLLogicalPlanBasicQueriesTranslatorTestSuite comparePlans(expectedPlan, logPlan, false) } + + test("for 0.5-nexus: test fields minus one field") { + val context = new CatalystPlanContext + val thrown = intercept[SyntaxCheckException] { + planTransformer.visit(plan(pplParser, "source=table | fields - A", false), context) + } + + assert(thrown.getMessage.contains("Failed to parse query due to offending symbol [-]")) + } + + test("for 0.5-nexus: test fields minus multiple fields") { + val context = new CatalystPlanContext + val thrown = intercept[SyntaxCheckException] { + planTransformer.visit(plan(pplParser, "source=table | fields - A, B", false), context) + } + + assert(thrown.getMessage.contains("Failed to parse query due to offending symbol [-]")) + } + + test("for 0.5-nexus: test fields minus with other commands") { + val context = new CatalystPlanContext + val thrown = intercept[SyntaxCheckException] { + planTransformer.visit( + plan(pplParser, "source=table | sort - A | where B > 0 | fields - C | head 1", false), + context) + } + + assert(thrown.getMessage.contains("Failed to parse query due to offending symbol [-]")) + } }