This is an automated email from the ASF dual-hosted git repository.
libenchao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new 3731206c1c [CALCITE-4802] Babel parser doesn't parse IF(condition,
then, else) statements
3731206c1c is described below
commit 3731206c1c360f7803955e60929063496b7e4164
Author: xiejiajun <[email protected]>
AuthorDate: Sat Jun 18 17:20:58 2022 +0800
[CALCITE-4802] Babel parser doesn't parse IF(condition, then, else)
statements
This closes #2835
---
babel/src/main/codegen/config.fmpp | 2 +-
.../java/org/apache/calcite/sql/parser/SqlParserTest.java | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/babel/src/main/codegen/config.fmpp
b/babel/src/main/codegen/config.fmpp
index f75631e739..3562e254dc 100644
--- a/babel/src/main/codegen/config.fmpp
+++ b/babel/src/main/codegen/config.fmpp
@@ -45,6 +45,7 @@ data: {
# items in this list become non-reserved
nonReservedKeywordsToAdd: [
# not in core, added in babel
+ "IF"
"SEMI"
# The following keywords are reserved in core Calcite,
@@ -236,7 +237,6 @@ data: {
"HOLD"
"HOUR"
"IDENTITY"
-# "IF" # not a keyword in Calcite
"ILIKE"
"IMMEDIATE"
"IMMEDIATELY"
diff --git
a/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
b/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
index 38da13a74c..e692dfaee2 100644
--- a/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
+++ b/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
@@ -4915,6 +4915,18 @@ public class SqlParserTest {
.fails("(?s).*when1.*");
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-4802">[CALCITE-4802]
+ * Babel parser doesn't parse IF(condition, then, else) statements </a>.
+ */
+ @Test void testIf() {
+ expr("if(true, 1, 0)")
+ .ok("`IF`(TRUE, 1, 0)");
+
+ sql("select 1 as if")
+ .ok("SELECT 1 AS `IF`");
+ }
+
@Test void testNullIf() {
expr("nullif(v1,v2)")
.ok("NULLIF(`V1`, `V2`)");