alibaba / alibaba/druid

SqlSelectBuilder from块toString时on后面的部分显示引用地址且表别名丢失

Open
#3,192 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
28.2k
Forks
8.6k
PR merge metrics
No merged PRs in 30d

Description

------sql------
SELECT SUM(e.cost_total_new) AS sumCost_total_new, COUNT(DISTINCT USER.userid) AS custCount
FROM cf_cust e join app_dbm USER
on e.userid=USER.userid WHERE USER.day >= 1 AND USER.day <= 30 AND USER.city
IN ('北京市', '杭州市', '上海市', '广州市', '深圳市') AND e.gmt_create >= '2019-04-04' AND e.gmt_create <= '2019-04-04'

---------
已知以上sql,调用以下方法创建sqlBuilder
SQLSelectBuilder builder = SQLBuilderFactory.createSelectSQLBuilder(sql, JdbcConstants.MYSQL);
SQLSelectStatement statement = builder.getSQLSelectStatement();
SQLSelect sqlSelect = statement.getSelect();
MySqlSelectQueryBlock sqlQueryBlock = (MySqlSelectQueryBlock)sqlSelect.getQuery();
String from = sqlQueryBlock.getFrom().toString();

得到的from语句中,on之后的部分为一个引用地址,且表别名丢失,toString后的 from语句如下
cf_cust JOIN app_dbm
ON com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr@1a4c3d21

期望结果是:
cf_cust e join app_dbm USER
on e.userid=USER.userid

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the supplied SQL using SQLBuilderFactory.createSelectSQLBuilder(sql, JdbcConstants.MYSQL), then inspect MySqlSelectQueryBlock.getFrom().toString(). Check how the JOIN source, aliases, and ON expression are rendered. Done when the output preserves cf_cust e, app_dbm USER, and the e.userid=USER.userid condition instead of an object reference.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mysql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.