Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
in the function 'massageSql' of 'QueryUtil.java',there are a few bugs:
01:
while (sql.endsWith(";")) sql = sql.substring(0, sql.length() - 1);
if the sql end with ';' and after the ';' still has comments,will be error.Because the sql will add ("\nLIMIT " + limit) at the end.
02:
if (limit > 0 && !sql.toLowerCase().contains("limit")) { sql += ("\nLIMIT " + limit); } if (offset > 0 && !sql.toLowerCase().contains("offset")) { sql += ("\nOFFSET " + offset); }
if the sql already has word 'limit' in it,such as Alias,Subquery,Comments,the ‘limit’ in the Input box will be invalid.
for example,the sql has subquery,and there is 'limit' in subquery.
select KYLIN_SALES.PART_DT, count(KYLIN_SALES.PRICE) from KYLIN_SALES inner join (select ACCOUNT_ID, ACCOUNT_BUYER_LEVEL from KYLIN_ACCOUNT where ACCOUNT_COUNTRY = 'US' limit 10000) as TT on KYLIN_SALES.BUYER_ID = TT.ACCOUNT_ID group by KYLIN_SALES.PART_DT
the ‘limit’ in the Input box will be invalid.please refer to 01.png and 02.png.
03:
// https://issues.apache.org/jira/browse/KYLIN-2649 if (kylinConfig.getForceLimit() > 0 && !sql.toLowerCase().contains("limit") && sql.toLowerCase().contains("*")) { sql += ("\nLIMIT " + kylinConfig.getForceLimit()); }
Because KYLIN-2649 is still unresolved,so I didn't change the code,but it has same 'limit' word bugs like above.
And there are some situations that the sql contains *,such as
count(*),kylin_sales.*
Maybe the * in subquery too.
it seems improperly to deal with the sql just use
sql.toLowerCase().contains("*")