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

复杂sql解析不正确的问题 #1831

Closed
icanfly opened this issue Jul 14, 2017 · 3 comments
Closed

复杂sql解析不正确的问题 #1831

icanfly opened this issue Jul 14, 2017 · 3 comments
Labels
Milestone

Comments

@icanfly
Copy link

icanfly commented Jul 14, 2017

我有一个比较复杂一点的sql:

select sum(hd.paid_amount) from
(
SELECT 'fl',cast(a.hosted_ymd as date) as hosted_ymd,a.user_id,'boss1',a.paid_amount,m.user_id,m.create_date,m.pmcode,n.type_name,n.product_name,n.acctype_id,n.acctype_name,n.account_name,n.plan
FROM hive.bdc_dwd.dw_mk_copyright_order a
left join hive.bdc_dwd.dw_mk_chance b on (a.chance_id=b.chance_id and b.acct_day='03')
left join hive.bdc_dwd.dw_lg_stat_user m on (a.user_id =m.user_id and m.acct_day='03')
left join hive.bdc_dwd.dw_lg_pmcode n on (m.pmcode=n.id and n.acct_day='03')
where a.hosted_ymd between '2016-01-01' and '2017-06-30' and b.chance_type_group=3
and a.acct_day='03'
union
select 'fl',b.paid_date as hosted_ymd,b.user_id,'boss2',b.paid_amount,m.user_id,m.create_date,m.pmcode,n.type_name,n.product_name,n.acctype_id,n.acctype_name,n.account_name,n.plan
from hive.bdc_dwd.dw_fx_chance a
left join hive.bdc_dwd.dw_fx_chance_order b on (a.chance_id=b.chance_id and b.acct_day='03')
left join hive.bdc_dwd.dw_lg_stat_user m on (a.user_id =m.user_id and m.acct_day='03')
left join hive.bdc_dwd.dw_lg_pmcode n on (m.pmcode=n.id and n.acct_day='03')
where a.project_id=1 and b.paid_amount>0 and cast(b.paid_date as varchar(10))>='2016-01-01' and
cast(b.paid_date as varchar(10))<='2017-06-30' and b.state=1 and a.acct_day='03'
)hd

使用Druid Mysql语法解析后得到的结果不正确:

1、别名映射不对,在有union这种情况下,且union两边都有相同别名时,映射会出现覆盖和错乱
image

对于a和b两个别名,对于union来说在两个子句下面别名对应了不同的数据表。而aliasMap中只解析出了基中的一部分。

2、因上面别名映射错乱的原因,对于别名无法正确解析到字段上,可能导致字段与数据表的归属出现问题:
image

b.paid_date 实际上是 dw_fx_chance_order表(别名:b)的字段。 而解析引擎解析成另一张表的字段。猜想可能与别名重复和覆盖有关。

这也许是一个bug,温少可以看看。

@wenshao
Copy link
Member

wenshao commented Jul 15, 2017

什么版本?

@icanfly
Copy link
Author

icanfly commented Jul 19, 2017

@wenshao 1.1.0版本,以前的版本也应该存在。我试过1.0.29,也存在同样的问题

@wenshao wenshao added this to the 1.1.2 milestone Jul 23, 2017
@wenshao wenshao added Bug and removed Need Infos labels Jul 23, 2017
@wenshao
Copy link
Member

wenshao commented Jul 23, 2017

问题修复,请用新版本
https://github.com/alibaba/druid/releases/tag/1.1.2

@wenshao wenshao closed this as completed Jul 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants