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 dbcf53c3b697..722d0ceb41fc 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 @@ */ 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 c7d9ffd185cc..badb4ce071a3 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 void subTestIntervalDayFailsValidation() { 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