Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 对于子查询join的SQL解析出的字段所属表问题 #6209

Open
jianglianggithub opened this issue Oct 31, 2024 · 0 comments
Open

Comments

@jianglianggithub
Copy link

Database Type

MYSQL

Database Version

5.7

Druid Version

1.2.24

JDK Version

OPENjdk 8

Error SQL

select a.name1, b.* from (select id , name1 from a) a join (select b.id , name2 from b) b on a.id = b.id
对于该SQL使用如下代码把b.*进行处理的时候出现解析结果不符合实际情况

SQLStatement stmt = SQLUtils.parseSingleStatement(sql, DbType.mysql);
repository.resolve(stmt, ResolveAllColumn, ResolveIdentifierAlias);
System.out.println(stmt.toString());

控制台输出的结果为

SELECT a.name1, a.id, b.name2
FROM (
	SELECT id, name1
	FROM a
) a
	JOIN (
		SELECT b.id, name2
		FROM b
	) b
	ON a.id = b.id

正确的结果应该是

SELECT a.name1, b.id, b.name2
FROM (
	SELECT id, name1
	FROM a
) a
	JOIN (
		SELECT b.id, name2
		FROM b
	) b
	ON a.id = b.id

我认为这是一个SQL解析的BUG

Testcase Code

No response

Stacktrace Info

No response

Error Info

No response

jianglianggithub added a commit to jianglianggithub/druid that referenced this issue Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant