This is an automated email from the ASF dual-hosted git repository.
jhyde 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 509e8c1712 [CALCITE-6003] JSON_ARRAY() with no arguments does not
unparse correctly
509e8c1712 is described below
commit 509e8c171268a0599d2612b74c608989cb1bc2ab
Author: Mihai Budiu <[email protected]>
AuthorDate: Tue Sep 26 16:16:41 2023 -0700
[CALCITE-6003] JSON_ARRAY() with no arguments does not unparse correctly
Signed-off-by: Mihai Budiu <[email protected]>
---
.../calcite/sql/fun/SqlJsonArrayFunction.java | 23 ++++++++++++----------
.../apache/calcite/sql/parser/SqlParserTest.java | 8 ++++++++
2 files changed, 21 insertions(+), 10 deletions(-)
diff --git
a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonArrayFunction.java
b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonArrayFunction.java
index f4d26d23e7..a0fa2f2766 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonArrayFunction.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlJsonArrayFunction.java
@@ -89,16 +89,19 @@ public class SqlJsonArrayFunction extends SqlFunction {
}
writer.endList(listFrame);
- SqlJsonConstructorNullClause nullClause = getEnumValue(call.operand(0));
- switch (nullClause) {
- case ABSENT_ON_NULL:
- writer.keyword("ABSENT ON NULL");
- break;
- case NULL_ON_NULL:
- writer.keyword("NULL ON NULL");
- break;
- default:
- throw new IllegalStateException("unreachable code");
+ if (call.operandCount() > 1) {
+ // If we have only 1 operand the value of 'ON NULL' does not matter.
+ SqlJsonConstructorNullClause nullClause = getEnumValue(call.operand(0));
+ switch (nullClause) {
+ case ABSENT_ON_NULL:
+ writer.keyword("ABSENT ON NULL");
+ break;
+ case NULL_ON_NULL:
+ writer.keyword("NULL ON NULL");
+ break;
+ default:
+ throw new IllegalStateException("unreachable code");
+ }
}
writer.endFunCall(frame);
}
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 edda041414..d12b7394c2 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
@@ -8762,6 +8762,14 @@ public class SqlParserTest {
+ "FORMAT JSON NULL ON NULL)");
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6003">[CALCITE-6003]
+ * JSON_ARRAY() with no arguments does not unparse correctly</a>. */
+ @Test void testEmptyJsonArray() {
+ expr("json_array()")
+ .ok("JSON_ARRAY()");
+ }
+
@Test void testJsonArray() {
expr("json_array('foo')")
.ok("JSON_ARRAY('foo' ABSENT ON NULL)");