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

danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/master by this push:
     new 8a459d9  [CALCITE-4022] Support unparse special syntax for INSERT (Xu 
Zhaohui)
8a459d9 is described below

commit 8a459d9b17a9403e4e1539ea1c3c8d8f39e30a12
Author: xzh <[email protected]>
AuthorDate: Sun Jul 26 11:16:14 2020 +0800

    [CALCITE-4022] Support unparse special syntax for INSERT (Xu Zhaohui)
    
    close apache/calcite#2082
---
 .../java/org/apache/calcite/sql/SqlInsert.java     | 12 +++++++++-
 .../apache/calcite/sql/parser/SqlParserTest.java   | 28 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/SqlInsert.java 
b/core/src/main/java/org/apache/calcite/sql/SqlInsert.java
index dbcf53c..722d0ce 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlInsert.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlInsert.java
@@ -29,7 +29,17 @@ import java.util.List;
  */
 public class SqlInsert extends SqlCall {
   public static final SqlSpecialOperator OPERATOR =
-      new SqlSpecialOperator("INSERT", SqlKind.INSERT);
+      new SqlSpecialOperator("INSERT", SqlKind.INSERT) {
+        @Override public SqlCall createCall(SqlLiteral functionQualifier, 
SqlParserPos pos,
+            SqlNode... operands) {
+          return new SqlInsert(
+              pos,
+              (SqlNodeList) operands[0],
+              operands[1],
+              operands[2],
+              (SqlNodeList) operands[3]);
+        }
+      };
 
   SqlNodeList keywords;
   SqlNode targetTable;
diff --git 
a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java 
b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
index c7d9ffd..badb4ce 100644
--- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
@@ -5818,6 +5818,34 @@ public class SqlParserTest {
     assertTrue(sqlNodeVisited.getKind() == SqlKind.INSERT);
   }
 
+  @Test void testSqlInsertSqlBasicCallToString() throws Exception {
+    final String sql0 = "insert into emps select * from emps";
+    final SqlNode sqlNode0 = getSqlParser(sql0).parseStmt();
+    final SqlNode sqlNodeVisited0 = sqlNode0.accept(new SqlShuttle() {
+      @Override public SqlNode visit(SqlIdentifier identifier) {
+        return new SqlIdentifier(identifier.names,
+            identifier.getParserPosition());
+      }
+    });
+    final String str0 = "INSERT INTO `EMPS`\n"
+        + "(SELECT *\n"
+        + "FROM `EMPS`)";
+    assertEquals(linux(sqlNodeVisited0.toString()), str0);
+
+    final String sql1 = "insert into emps select empno from emps";
+    final SqlNode sqlNode1 = getSqlParser(sql1).parseStmt();
+    final SqlNode sqlNodeVisited1 = sqlNode1.accept(new SqlShuttle() {
+      @Override public SqlNode visit(SqlIdentifier identifier) {
+        return new SqlIdentifier(identifier.names,
+            identifier.getParserPosition());
+      }
+    });
+    final String str1 = "INSERT INTO `EMPS`\n"
+        + "(SELECT `EMPNO`\n"
+        + "FROM `EMPS`)";
+    assertEquals(linux(sqlNodeVisited1.toString()), str1);
+  }
+
   /**
    * Runs tests for INTERVAL... DAY TO HOUR that should pass parser but fail
    * validator. A substantially identical set of tests exists in

Reply via email to