yuqi1129 / calcite-test

Test code for apache calcite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Insert语句转换存在ROW关键词问题

tangyibo opened this issue · comments

commented

您好,请教下下面的这个代码转换后的Insert语句存在row关键词,而当前大多数的oracle/mysql/postgresql数据库都不支持,请指教:

	public static void main(String[] args) {
		String sql="insert into dept (name, deptno) values ('a', 123) ,('b',345) ";
        SqlParser.Config config =SqlParser.configBuilder().setCaseSensitive(true).build();
        SqlParser parser = SqlParser.create(sql, config);
        SqlNode sqlNode =null;
        try {
				sqlNode=parser.parseStmt();
        }catch(SqlParseException e) {
        	e.printStackTrace();
        }
        System.out.println(sqlNode.toSqlString(OracleSqlDialect.DEFAULT));
        System.out.println("========================");
        System.out.println(sqlNode.toSqlString(PostgresqlSqlDialect.DEFAULT));
        System.out.println("========================");
        System.out.println(sqlNode.toSqlString(MysqlSqlDialect.DEFAULT));
	}

结果输出为:

INSERT INTO "DEPT" ("NAME", "DEPTNO")
VALUES ROW('a', 123),
ROW('b', 345)
========================
INSERT INTO "DEPT" ("NAME", "DEPTNO")
VALUES ROW('a', 123),
ROW('b', 345)
========================
INSERT INTO `DEPT` (`NAME`, `DEPTNO`)
VALUES ROW('a', 123),
ROW('b', 345)

但我期望的是:

INSERT INTO "DEPT" ("NAME", "DEPTNO")
VALUES ('a', 123),('b', 345)
========================
INSERT INTO "DEPT" ("NAME", "DEPTNO")
VALUES ('a', 123),('b', 345)
========================
INSERT INTO `DEPT` (`NAME`, `DEPTNO`)
VALUES ('a', 123),('b', 345)
commented

这是SqlRowOperatorunparse的默认行为, 默认会将方法名ROW带进去, 在calcite中 value后面是一个Row方法, 如果不想输出, 可以覆写该方法

commented

@yuqi1129 多谢,按照您的覆写已经成功实现。

commented