This is an automated email from the ASF dual-hosted git repository.

nic pushed a commit to branch 3.0.x
in repository https://gitbox.apache.org/repos/asf/kylin.git

commit a9945ca8d11ab0960c30ba9757425f006567db0a
Author: yaqian.zhang <598593...@qq.com>
AuthorDate: Mon Nov 4 19:50:20 2019 +0800

    KYLIN-4237 Return error when execute "explain plan for SQL" to get the 
execution plan of SQL
---
 .../org/apache/kylin/query/util/QueryUtil.java     | 16 ++++++----
 .../org/apache/kylin/query/util/QueryUtilTest.java | 35 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/query/src/main/java/org/apache/kylin/query/util/QueryUtil.java 
b/query/src/main/java/org/apache/kylin/query/util/QueryUtil.java
index 30db7e1..a17c578 100644
--- a/query/src/main/java/org/apache/kylin/query/util/QueryUtil.java
+++ b/query/src/main/java/org/apache/kylin/query/util/QueryUtil.java
@@ -52,15 +52,21 @@ public class QueryUtil {
     static final String KEYWORD_WITH = "with";
     static final String KEYWORD_EXPLAIN = "explain";
 
-    private static String appendLimitOffsetToSql(String sql, int limit, int 
offset) {
+    public static String appendLimitOffsetToSql(String sql, int limit, int 
offset) {
         String retSql = sql;
+        String prefixSql = "select * from (";
+        String suffixSql = ")";
+        if (sql.startsWith(KEYWORD_EXPLAIN)) {
+            prefixSql = "";
+            suffixSql = "";
+        }
         if (0 != limit && 0 != offset) {
-            retSql = "select * from (" + sql + ") limit " + 
String.valueOf(limit) +
-                    " offset " + String.valueOf(offset);
+            retSql = prefixSql + sql + suffixSql + " limit " + 
String.valueOf(limit) + " offset "
+                    + String.valueOf(offset);
         } else if (0 == limit && 0 != offset) {
-            retSql = "select * from (" + sql + ") offset " + 
String.valueOf(offset);
+            retSql = prefixSql + sql + suffixSql + " offset " + 
String.valueOf(offset);
         } else if (0 != limit && 0 == offset) {
-            retSql = "select * from (" + sql + ") limit " + 
String.valueOf(limit);
+            retSql = prefixSql + sql + suffixSql + " limit " + 
String.valueOf(limit);
         } else {
             // do nothing
         }
diff --git a/query/src/test/java/org/apache/kylin/query/util/QueryUtilTest.java 
b/query/src/test/java/org/apache/kylin/query/util/QueryUtilTest.java
index ffd169d..9b769b8 100644
--- a/query/src/test/java/org/apache/kylin/query/util/QueryUtilTest.java
+++ b/query/src/test/java/org/apache/kylin/query/util/QueryUtilTest.java
@@ -40,6 +40,41 @@ public class QueryUtilTest extends LocalFileMetadataTestCase 
{
     }
 
     @Test
+    public void testappendLimitOffsetToSql() {
+        {
+            String sql = "select ( date '2001-09-28' + interval floor(1.2) 
day) from test_kylin_fact";
+            String newsql = QueryUtil.appendLimitOffsetToSql(sql, 100, 100);
+            Assert.assertEquals(
+                    "select * from (select ( date '2001-09-28' + interval 
floor(1.2) day) from test_kylin_fact) limit 100 offset 100",
+                    newsql);
+        }
+
+        {
+            String sql = "select ( date '2001-09-28' + interval floor(1.2) 
day) from test_kylin_fact";
+            String newsql = QueryUtil.appendLimitOffsetToSql(sql, 0, 0);
+            Assert.assertEquals(
+                    "select ( date '2001-09-28' + interval floor(1.2) day) 
from test_kylin_fact",
+                    newsql);
+        }
+
+        {
+            String sql = "explain plan for select ( date '2001-09-28' + 
interval floor(1.2) day) from test_kylin_fact";
+            String newsql = QueryUtil.appendLimitOffsetToSql(sql, 100, 100);
+            Assert.assertEquals(
+                    "explain plan for select ( date '2001-09-28' + interval 
floor(1.2) day) from test_kylin_fact limit 100 offset 100",
+                    newsql);
+        }
+
+        {
+            String sql = "explain plan for select ( date '2001-09-28' + 
interval floor(1.2) day) from test_kylin_fact";
+            String newsql = QueryUtil.appendLimitOffsetToSql(sql, 0, 0);
+            Assert.assertEquals(
+                    "explain plan for select ( date '2001-09-28' + interval 
floor(1.2) day) from test_kylin_fact",
+                    newsql);
+        }
+    }
+
+    @Test
     public void testMassageSql() {
         {
             String sql = "select ( date '2001-09-28' + interval floor(1.2) 
day) from test_kylin_fact";

Reply via email to