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

xxyu pushed a commit to branch kylin5
in repository https://gitbox.apache.org/repos/asf/kylin.git

commit 8e3844653a754b12c3bc9083dd5185819dfa45f1
Author: Pengfei Zhan <pengfei.z...@kyligence.io>
AuthorDate: Sat Nov 19 00:06:49 2022 +0800

    [DIRTY] adapt sql hint of CubePriority when transforming sql
---
 .../org/apache/kylin/query/util/EscapeParser.jj       | 17 ++++++++++++++---
 .../org/apache/kylin/query/util/RawSqlParser.jj       |  7 ++++++-
 .../kylin/query/util/EscapeTransformerTest.java       |  3 +--
 .../org/apache/kylin/query/util/QueryUtilTest.java    | 19 +++++++++++++++++++
 4 files changed, 40 insertions(+), 6 deletions(-)

diff --git 
a/src/query-common/src/main/codegen/javacc/org/apache/kylin/query/util/EscapeParser.jj
 
b/src/query-common/src/main/codegen/javacc/org/apache/kylin/query/util/EscapeParser.jj
index 5dcd133f23..d09a3cfb32 100644
--- 
a/src/query-common/src/main/codegen/javacc/org/apache/kylin/query/util/EscapeParser.jj
+++ 
b/src/query-common/src/main/codegen/javacc/org/apache/kylin/query/util/EscapeParser.jj
@@ -119,9 +119,8 @@ TOKEN :
     >
 | < DOUBLE_QUOTE : "\"">
 | < QUOTED_IDENTIFIER: <DOUBLE_QUOTE> ( (~["\"","\n","\r"]) | ("\"\"") )+ 
<DOUBLE_QUOTE> >
-| < HINT_BEG: "/*" >
-| < HINT_END: "*/" >
-| < HINT: <HINT_BEG> (~["\n", "\r"])* <HINT_END> >
+| < HINT: "/*" (~["\n", "\r"])* "*/" >
+| < CUBE_PRIORITY: "--" ([" "])* "CubePriority(" (~["\n", "\r", ")"])* ")" ([" 
"])* "\n" >
 | < UNSIGNED_INTEGER_LITERAL: (["0"-"9"])+ >
 | < APPROX_NUMERIC_LITERAL:(<UNSIGNED_INTEGER_LITERAL> | 
<DECIMAL_NUMERIC_LITERAL>) <EXPONENT> >
 | < DECIMAL_NUMERIC_LITERAL:(["0"-"9"])+(".")?(["0"-"9"])*| "."(["0"-"9"])+>
@@ -233,6 +232,7 @@ String Expression() :
     | innerString = GroupingSetsExpression()
     | innerString = TsDiffOrAddExpression()
     | innerString = Hint()
+    | innerString = CubePriority()
     | innerString = Numeric()
     | innerString = CastExpression()
     | innerString = ExtractExpression()
@@ -683,6 +683,16 @@ String Hint():
     }
 }
 
+String CubePriority():
+{}
+{
+    <CUBE_PRIORITY>
+    {
+        log.trace("meet token <CubePriority>");
+        return getToken(0).image;
+    }
+}
+
 String Numeric():
 {}
 {
@@ -758,6 +768,7 @@ String ParameterExpression() :
     | innerString = CeilFloorExpress()
     | innerString = Numeric()
     | innerString = Hint()
+    | innerString = CubePriority()
     | innerString = ParenExpress()
     | innerString = QuotedString()
     | innerString = DoubleQuotedString()
diff --git 
a/src/query-common/src/main/codegen/javacc/org/apache/kylin/query/util/RawSqlParser.jj
 
b/src/query-common/src/main/codegen/javacc/org/apache/kylin/query/util/RawSqlParser.jj
index f2219ce3b7..b92340d8da 100644
--- 
a/src/query-common/src/main/codegen/javacc/org/apache/kylin/query/util/RawSqlParser.jj
+++ 
b/src/query-common/src/main/codegen/javacc/org/apache/kylin/query/util/RawSqlParser.jj
@@ -139,7 +139,12 @@ private void DoParse(List<RawSqlBlock> stmtBlockList, 
List<RawSqlBlock> allBlock
             }
         }
         block = Comment()
-        { allBlockList.add(block); }
+        {
+            if (block.getText().contains("CubePriority(")) {
+                stmtBlockList.add(block);
+            }
+            allBlockList.add(block);
+        }
         | block = Stmt()
         {
             stmtBlockList.add(block);
diff --git 
a/src/query/src/test/java/org/apache/kylin/query/util/EscapeTransformerTest.java
 
b/src/query/src/test/java/org/apache/kylin/query/util/EscapeTransformerTest.java
index 2808e5993f..75b52a057c 100644
--- 
a/src/query/src/test/java/org/apache/kylin/query/util/EscapeTransformerTest.java
+++ 
b/src/query/src/test/java/org/apache/kylin/query/util/EscapeTransformerTest.java
@@ -307,8 +307,7 @@ public class EscapeTransformerTest {
                 + " from tbl where a in ('a--b') and c in (\"a---b\", 'a--b', 
'')";
         String transformedSQL = (new 
RawSqlParser(originalSQL)).parse().getStatementString();
 
-        String expectedSQL =
-                "select 'a---b'+\"a--b\", 'ab''cd', \"abc\"\"cd\" , 
'abc\"def', \"abc'def\"\n"
+        String expectedSQL = "select 'a---b'+\"a--b\", 'ab''cd', \"abc\"\"cd\" 
, 'abc\"def', \"abc'def\"\n"
                 + "\"--won't remove in quote, /*test*/\", { fn count(*) } from 
tbl where a in ('a--b') and c in (\"a---b\", 'a--b', '')";
         Assert.assertEquals(expectedSQL, transformedSQL);
     }
diff --git 
a/src/query/src/test/java/org/apache/kylin/query/util/QueryUtilTest.java 
b/src/query/src/test/java/org/apache/kylin/query/util/QueryUtilTest.java
index af76c793af..8a703d262a 100644
--- a/src/query/src/test/java/org/apache/kylin/query/util/QueryUtilTest.java
+++ b/src/query/src/test/java/org/apache/kylin/query/util/QueryUtilTest.java
@@ -98,6 +98,25 @@ public class QueryUtilTest extends 
NLocalFileMetadataTestCase {
         }
     }
 
+    @Test
+    public void testAdaptCubePriority() {
+        {
+            String sql = "--CubePriority(m)\nselect price from 
test_kylin_fact";
+            QueryParams queryParams1 = new 
QueryParams(KylinConfig.getInstanceFromEnv(), sql, "default", 0, 0,
+                    "DEFAULT", true);
+            String transformed = QueryUtil.massageSql(queryParams1);
+            Assert.assertEquals(sql, transformed);
+        }
+
+        {
+            String sql = "-- CubePriority(m)\nselect price from 
test_kylin_fact";
+            QueryParams queryParams1 = new 
QueryParams(KylinConfig.getInstanceFromEnv(), sql, "default", 0, 0,
+                    "DEFAULT", true);
+            String transformed = QueryUtil.massageSql(queryParams1);
+            Assert.assertEquals(sql, transformed);
+        }
+    }
+
     @Test
     public void testMassageWithoutConvertToComputedColumn() {
         KylinConfig config = KylinConfig.getInstanceFromEnv();

Reply via email to