rogercloud commented on a change in pull request #107: kylin-3119
URL: https://github.com/apache/kylin/pull/107#discussion_r170827219
##########
File path: query/src/main/java/org/apache/kylin/query/util/QueryUtil.java
##########
@@ -50,32 +50,39 @@ public static String massageSql(String sql, String
project, int limit, int offse
ProjectManager projectManager =
ProjectManager.getInstance(KylinConfig.getInstanceFromEnv());
ProjectInstance projectInstance = projectManager.getProject(project);
KylinConfig kylinConfig = projectInstance.getConfig();
-
+ sql = removeCommentInSql(sql);
while (sql.endsWith(";"))
sql = sql.substring(0, sql.length() - 1);
- if (limit > 0 && !sql.toLowerCase().contains("limit")) {
- sql += ("\nLIMIT " + limit);
- }
+ String sql1=sql;
+ final String suffixPattern =
"^.+?\\s(limit\\s\\d+)?\\s(offset\\s\\d+)?\\s*$";
+ sql = sql.replaceAll("\\s+", " ");
+ Pattern pattern = Pattern.compile(suffixPattern);
+ Matcher matcher = pattern.matcher(sql.toLowerCase() + " ");
- if (offset > 0 && !sql.toLowerCase().contains("offset")) {
- sql += ("\nOFFSET " + offset);
+ if (matcher.find()) {
+ if (limit > 0 && matcher.group(1) == null) {
+ sql1 += ("\nLIMIT " + limit);
+ }
+ if (offset > 0 && matcher.group(2) == null) {
+ sql1 += ("\nOFFSET " + offset);
+ }
}
// https://issues.apache.org/jira/browse/KYLIN-2649
- if (kylinConfig.getForceLimit() > 0 &&
!sql.toLowerCase().contains("limit")
- && sql.toLowerCase().matches("^select\\s+\\*\\p{all}*")) {
- sql += ("\nLIMIT " + kylinConfig.getForceLimit());
+ if (kylinConfig.getForceLimit() > 0 &&
!sql1.toLowerCase().contains("limit")
Review comment:
Here's another place that check "limit", would you please consider it in
this fix?
A possible fix is record the previous match result, telling whether the SQL
contains limit or not.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services