This is an automated email from the ASF dual-hosted git repository.
mbudiu 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 22b424e5f2 [CALCITE-6178] WITH RECURSIVE query when cloned using
sqlshuttle looses RECURSIVE property
22b424e5f2 is described below
commit 22b424e5f2084dd1c352ddeb752a8fd8bfa288b0
Author: Hanumath Maduri <[email protected]>
AuthorDate: Sat Dec 23 17:04:08 2023 -0800
[CALCITE-6178] WITH RECURSIVE query when cloned using sqlshuttle looses
RECURSIVE property
---
.../main/java/org/apache/calcite/sql/SqlWithItem.java | 10 ++++++----
.../org/apache/calcite/sql/parser/SqlParserTest.java | 16 ++++++++++++++++
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlWithItem.java
b/core/src/main/java/org/apache/calcite/sql/SqlWithItem.java
index db99e3f5fe..89fe2e8d9c 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlWithItem.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlWithItem.java
@@ -58,7 +58,7 @@ public class SqlWithItem extends SqlCall {
@SuppressWarnings("nullness")
@Override public List<SqlNode> getOperandList() {
- return ImmutableNullableList.of(name, columnList, query);
+ return ImmutableNullableList.of(name, columnList, query, recursive);
}
@SuppressWarnings("assignment.type.incompatible")
@@ -73,6 +73,9 @@ public class SqlWithItem extends SqlCall {
case 2:
query = operand;
break;
+ case 3:
+ recursive = (SqlLiteral) operand;
+ break;
default:
throw new AssertionError(i);
}
@@ -114,10 +117,9 @@ public class SqlWithItem extends SqlCall {
@Override public SqlCall createCall(@Nullable SqlLiteral functionQualifier,
SqlParserPos pos, @Nullable SqlNode... operands) {
assert functionQualifier == null;
- assert operands.length == 3;
+ assert operands.length == 4;
return new SqlWithItem(pos, (SqlIdentifier) operands[0],
- (SqlNodeList) operands[1], operands[2],
- SqlLiteral.createBoolean(false, SqlParserPos.ZERO));
+ (SqlNodeList) operands[1], operands[2], (SqlLiteral) operands[3]);
}
}
}
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 00426dd1d4..ac15c0c16e 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
@@ -43,6 +43,7 @@ import org.apache.calcite.test.IntervalTest;
import org.apache.calcite.tools.Hoist;
import org.apache.calcite.util.Bug;
import org.apache.calcite.util.ConversionUtil;
+import org.apache.calcite.util.Litmus;
import org.apache.calcite.util.Pair;
import org.apache.calcite.util.TestUtil;
import org.apache.calcite.util.Util;
@@ -82,6 +83,7 @@ import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.hasToString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
/**
@@ -1233,6 +1235,20 @@ public class SqlParserTest {
.fails("Bang equal '!=' is not allowed under the current SQL
conformance level");
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6178">[CALCITE-6178]
+ * WITH RECURSIVE query when cloned using sqlshuttle looses RECURSIVE
property</a>. */
+ @Test void testRecursiveQueryCloned() throws Exception {
+ SqlNode sqlNode = sql("with RECURSIVE emp2 as "
+ + "(select * from emp union select * from emp2) select * from
emp2").parser().parseStmt();
+ SqlNode sqlNode1 = sqlNode.accept(new SqlShuttle() {
+ @Override public SqlNode visit(SqlIdentifier identifier) {
+ return new SqlIdentifier(identifier.names,
identifier.getParserPosition());
+ }
+ });
+ assertTrue(sqlNode.equalsDeep(sqlNode1, Litmus.IGNORE));
+ }
+
@Test void testBetween() {
sql("select * from t where price between 1 and 2")
.ok("SELECT *\n"