[alibaba/druid]关于sqlutil 解析hive 多层with嵌套失败的问题

2025-11-11 778 views
7

版本是1.2.5 也试过1.1.23 都不行 sql语句hive可以正常执行的 已验证 String s7 = "WITH A AS (\r\n"

" WITH A1 AS (\r\n" " SELECT *\r\n" " FROM aaa1226.123\r\n" " LIMIT 1\r\n" " )\r\n" " SELECT *\r\n" " FROM A1\r\n" " ), \r\n" " B AS (\r\n" " SELECT *\r\n" " FROM aaa1226.123\r\n" " LIMIT 1\r\n" " )\r\n" "SELECT *\r\n" "FROM A, B"; Assert.assertEquals(s7, SQLUtils.formatHive(s7)); 警告: format error com.alibaba.druid.sql.parser.ParserException: syntax error, error in :'( WITH A1 AS ( SELECT * ', expect RPAREN, actual WITH pos 19, line 1, column 12, token WITH at com.alibaba.druid.sql.parser.SQLParser.printError(SQLParser.java:344) at com.alibaba.druid.sql.parser.SQLParser.accept(SQLParser.java:352) at com.alibaba.druid.sql.parser.SQLStatementParser.parseWithQuery(SQLStatementParser.java:3311) at com.alibaba.druid.sql.parser.SQLStatementParser.parseWith(SQLStatementParser.java:3327) at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:242) at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:171) at com.alibaba.druid.sql.SQLUtils.format(SQLUtils.java:280) at com.alibaba.druid.sql.SQLUtils.format(SQLUtils.java:266) at com.alibaba.druid.sql.SQLUtils.formatHive(SQLUtils.java:161) at DruidTestSql.main(DruidTestSql.java:79)

回答

4

@Arbow @argan @septer @zhuzhaoyuan

7

@wenshao帮忙看看 在线等

7
WITH A AS (
 WITH A1 AS (
 SELECT *
 FROM aaa1226.123
 LIMIT 1
 )
 SELECT *
 FROM A1
 ), 
 B AS (
 SELECT *
 FROM aaa1226.123
 LIMIT 1
 )
SELECT *
FROM A, B

这里的表名aaa1226.123比较奇怪,这个确实是生产环境的表么?

9

首先感谢您的回答 表名是测试环境的 跟这个有关系嘛?

6

方便加微信沟通嘛?17303101158

8

去掉也不好使

9

提示解析到第二层with就报错了

2

@wenshao 还在看吗???

1

你更新到1.2.5版本,将其中两处的表名改一下,就可以了

0

@wenshao String name = lexer.stringVal(); lexer.nextToken(); accept(Token.EQ); SQLExpr value = this.exprParser.primary(); 1.2.5报错 stmt 是HiveCreateTableStatement stmt.getTableOptions().put(name, value); if (lexer.token() == Token.COMMA) { lexer.nextToken(); continue; } 这块的代码应该如何改?

0

String name = lexer.stringVal(); lexer.nextToken(); accept(Token.EQ); SQLExpr value = this.exprParser.primary(); stmt.getTableOptions().add(new SQLAssignItem(value, value)); 上边这个name怎么放到SQLAssignItem进去?