Skip to content

Commit

Permalink
[CALCITE-4022] Support unparse special syntax for INSERT (Xu Zhaohui)
Browse files Browse the repository at this point in the history
  • Loading branch information
xy2953396112 authored and danny0405 committed Jul 27, 2020
1 parent 4d345a6 commit 8a459d9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/src/main/java/org/apache/calcite/sql/SqlInsert.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a459d9

Please sign in to comment.