diff --git a/integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalcitePPLConditionBuiltinFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalcitePPLConditionBuiltinFunctionIT.java index d37adb4c32c..0c422cd271e 100644 --- a/integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalcitePPLConditionBuiltinFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalcitePPLConditionBuiltinFunctionIT.java @@ -194,6 +194,19 @@ public void testIfWithLike() throws IOException { actual, rows(0.0, "John"), rows(0.0, "Jane"), rows(0.0, "Jake"), rows(1.0, "Hello")); } + @Test + public void testIfWithEquals() throws IOException { + JSONObject actual = + executeQuery( + String.format( + "source=%s | eval jake = if(name='Jake', 1, 0) | fields name, jake", + TEST_INDEX_STATE_COUNTRY)); + + verifySchema(actual, schema("name", "string"), schema("jake", "int")); + + verifyDataRows(actual, rows("Jake", 1), rows("Hello", 0), rows("John", 0), rows("Jane", 0)); + } + @Test public void testIsPresent() throws IOException { JSONObject actual = diff --git a/ppl/src/main/antlr/OpenSearchPPLParser.g4 b/ppl/src/main/antlr/OpenSearchPPLParser.g4 index 2221a36da43..17498c201f5 100644 --- a/ppl/src/main/antlr/OpenSearchPPLParser.g4 +++ b/ppl/src/main/antlr/OpenSearchPPLParser.g4 @@ -522,7 +522,7 @@ tableSource ; tableFunction - : qualifiedName LT_PRTHS functionArgs RT_PRTHS + : qualifiedName LT_PRTHS namedFunctionArgs RT_PRTHS ; // fields @@ -597,10 +597,17 @@ functionArgs : (functionArg (COMMA functionArg)*)? ; +namedFunctionArgs + : (namedFunctionArg (COMMA namedFunctionArg)*)? + ; + functionArg - : (ident EQUAL)? functionArgExpression + : functionArgExpression ; +namedFunctionArg + : (ident EQUAL)? functionArgExpression + ; functionArgExpression : lambda diff --git a/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java b/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java index 84f241170b8..87db3a8e56d 100644 --- a/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java +++ b/ppl/src/main/java/org/opensearch/sql/ppl/parser/AstBuilder.java @@ -550,8 +550,8 @@ public UnresolvedPlan visitTableSourceClause(TableSourceClauseContext ctx) { @Override public UnresolvedPlan visitTableFunction(TableFunctionContext ctx) { ImmutableList.Builder builder = ImmutableList.builder(); - ctx.functionArgs() - .functionArg() + ctx.namedFunctionArgs() + .namedFunctionArg() .forEach( arg -> { String argName = (arg.ident() != null) ? arg.ident().getText() : null;