This is an automated email from the ASF dual-hosted git repository.

dmsysolyatin 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 8dc4cbf2c1 [CALCITE-7080] Support unparse when operator is UPDATE
8dc4cbf2c1 is described below

commit 8dc4cbf2c128c1346f6af612907ffa6b6f20f69c
Author: Guillaume Massé (马赛卫) <[email protected]>
AuthorDate: Sun Jun 29 15:47:59 2025 -0400

    [CALCITE-7080] Support unparse when operator is UPDATE
---
 core/src/main/java/org/apache/calcite/sql/SqlUpdate.java | 16 +++++++++++++++-
 .../org/apache/calcite/sql/parser/SqlParserTest.java     | 16 ++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/SqlUpdate.java 
b/core/src/main/java/org/apache/calcite/sql/SqlUpdate.java
index a827e4ccbd..9c4d2a35b3 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlUpdate.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlUpdate.java
@@ -36,7 +36,21 @@
  */
 public class SqlUpdate extends SqlCall {
   public static final SqlSpecialOperator OPERATOR =
-      new SqlSpecialOperator("UPDATE", SqlKind.UPDATE);
+      new SqlSpecialOperator("UPDATE", SqlKind.UPDATE) {
+        @SuppressWarnings("argument.type.incompatible")
+        @Override public SqlCall createCall(@Nullable SqlLiteral 
functionQualifier,
+            SqlParserPos pos,
+            @Nullable SqlNode... operands) {
+          return new SqlUpdate(
+              pos,
+              operands[0],
+              (SqlNodeList) operands[1],
+              (SqlNodeList) operands[2],
+              operands[3],
+              null,
+              (SqlIdentifier) operands[4]);
+        }
+      };
 
   SqlNode targetTable;
   SqlNodeList targetColumnList;
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 f7704aa842..613fe9b7de 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
@@ -6576,6 +6576,22 @@ private static Matcher<SqlNode> isCharLiteral(String s) {
     assertThat(str1, is(toLinux(sqlNodeVisited1.toString())));
   }
 
+  @Test void testVisitSqlUpdateWithSqlShuttle() {
+    final String sql = "UPDATE emps AS e SET e.sal = 0 WHERE e.sal < 0";
+    final SqlNode sqlNode = sql(sql).node();
+    final SqlNode sqlNodeVisited = sqlNode.accept(new SqlShuttle() {
+      @Override public SqlNode visit(SqlIdentifier identifier) {
+        // Copy the identifier in order to return a new SqlUpdate.
+        return identifier.clone(identifier.getParserPosition());
+      }
+    });
+    assertNotSame(sqlNodeVisited, sqlNode);
+    assertThat(sqlNodeVisited.getKind(), is(SqlKind.UPDATE));
+    final String str1 = "UPDATE `EMPS` AS `E` SET `E`.`SAL` = 0\n"
+        + "WHERE `E`.`SAL` < 0";
+    assertThat(str1, is(toLinux(sqlNodeVisited.toString())));
+  }
+
   @Test void testVisitSqlMatchRecognizeWithSqlShuttle() {
     final String sql = "select *\n"
         + "from emp \n"

Reply via email to