You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by mb...@apache.org on 2025/04/22 00:03:22 UTC

(calcite) branch main updated: [CALCITE-6964] SqlDelete#getOperandList return operands' both order and size not match with SqlDelete#setOperand

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 b96fa39e65 [CALCITE-6964] SqlDelete#getOperandList return operands' both order and size not match with SqlDelete#setOperand
b96fa39e65 is described below

commit b96fa39e657103cdcdcbc6088d9b2e4518f49de2
Author: wei.zhou <we...@cisdi.com.cn>
AuthorDate: Fri Apr 18 14:54:48 2025 +0800

    [CALCITE-6964] SqlDelete#getOperandList return operands' both order and size not match with SqlDelete#setOperand
---
 .../java/org/apache/calcite/sql/SqlDelete.java     |  2 +-
 .../apache/calcite/sql/SqlCallOperandsTest.java    | 73 ++++++++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDelete.java b/core/src/main/java/org/apache/calcite/sql/SqlDelete.java
index 6332c1126b..04eeeab35f 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlDelete.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlDelete.java
@@ -66,7 +66,7 @@ public SqlDelete(
 
   @SuppressWarnings("nullness")
   @Override public List<SqlNode> getOperandList() {
-    return ImmutableNullableList.of(targetTable, condition, alias);
+    return ImmutableNullableList.of(targetTable, condition, sourceSelect, alias);
   }
 
   @SuppressWarnings("assignment.type.incompatible")
diff --git a/core/src/test/java/org/apache/calcite/sql/SqlCallOperandsTest.java b/core/src/test/java/org/apache/calcite/sql/SqlCallOperandsTest.java
new file mode 100644
index 0000000000..f829b805ce
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/sql/SqlCallOperandsTest.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql;
+
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParserPos;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+
+/**
+ * Tests for SqlCall operands' order and size match with set.
+ * See <a href="https://issues.apache.org/jira/browse/CALCITE-6964">[CALCITE-6964]</a>
+ *
+ */
+public class SqlCallOperandsTest {
+  @Test void testSqlDeleteGetOperandsMatchWithSetOperand() {
+    SqlDelete sqlDelete =
+        new SqlDelete(SqlParserPos.ZERO, new SqlIdentifier("table1", SqlParserPos.ZERO),
+            null,
+            null,
+            null);
+    SqlNode targetTable = new SqlIdentifier("table2", SqlParserPos.ZERO);
+    final SqlIdentifier field1 = new SqlIdentifier("field1", SqlParserPos.ZERO);
+    SqlNode condition =
+        SqlStdOperatorTable.EQUALS.createCall(SqlParserPos.ZERO, field1,
+            SqlLiteral.createCharString("field1Value", SqlParserPos.ZERO));
+    SqlSelect sourceSelect =
+        new SqlSelect(SqlParserPos.ZERO, null,
+            SqlNodeList.of(field1),
+            null,
+            null,
+            null,
+            null,
+            null,
+            null,
+            null,
+            null,
+            null,
+            null);
+    SqlIdentifier alias = new SqlIdentifier("alias", SqlParserPos.ZERO);
+    sqlDelete.setOperand(0, targetTable);
+    sqlDelete.setOperand(1, condition);
+    sqlDelete.setOperand(2, sourceSelect);
+    sqlDelete.setOperand(3, alias);
+    final List<SqlNode> operandList = sqlDelete.getOperandList();
+    // Verify if the operands are in the correct position in the operandList
+    assertThat(operandList, hasSize(4));
+    assertThat(sqlDelete.getTargetTable(), equalTo(operandList.get(0)));
+    assertThat(sqlDelete.getCondition(), equalTo(operandList.get(1)));
+    assertThat(sqlDelete.getSourceSelect(), equalTo(operandList.get(2)));
+    assertThat(sqlDelete.getAlias(), equalTo(operandList.get(3)));
+  }
+}