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

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

commit 2561a21bd3d04b58706fc2444d7597a0a0271db6
Author: Pengfei Zhan <dethr...@gmail.com>
AuthorDate: Thu Nov 9 10:42:47 2023 +0800

    KYLIN-5869 Column ACL missing alias while reusing with-items
---
 .../query/security/HackSelectStarWithColumnACL.java    |  4 +++-
 .../security/HackSelectStarWithColumnACLTest.java      | 18 +++++++++++++++---
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git 
a/src/query-common/src/main/java/org/apache/kylin/query/security/HackSelectStarWithColumnACL.java
 
b/src/query-common/src/main/java/org/apache/kylin/query/security/HackSelectStarWithColumnACL.java
index a6112e47fa..11c424161f 100644
--- 
a/src/query-common/src/main/java/org/apache/kylin/query/security/HackSelectStarWithColumnACL.java
+++ 
b/src/query-common/src/main/java/org/apache/kylin/query/security/HackSelectStarWithColumnACL.java
@@ -198,7 +198,9 @@ public class HackSelectStarWithColumnACL implements 
IQueryTransformer, IPushDown
 
         private String markTableIdentifier(SqlIdentifier operand, SqlNode 
alias) {
             if (namesOfWithItems.contains(operand.toString())) {
-                return operand.toString();
+                String withItemName = 
StringHelper.doubleQuote(operand.toString());
+                return alias == null ? withItemName
+                        : withItemName + " as " + 
StringHelper.doubleQuote(alias.toString());
             }
             List<String> names = operand.names;
             String schema = names.size() == 1 ? defaultSchema : names.get(0);
diff --git 
a/src/query/src/test/java/org/apache/kylin/query/security/HackSelectStarWithColumnACLTest.java
 
b/src/query/src/test/java/org/apache/kylin/query/security/HackSelectStarWithColumnACLTest.java
index 4ed0a797d1..4346b5c4c7 100644
--- 
a/src/query/src/test/java/org/apache/kylin/query/security/HackSelectStarWithColumnACLTest.java
+++ 
b/src/query/src/test/java/org/apache/kylin/query/security/HackSelectStarWithColumnACLTest.java
@@ -116,7 +116,19 @@ class HackSelectStarWithColumnACLTest {
                     + "select \"TEST_KYLIN_FACT\".\"ORDER_ID\", 
\"TEST_KYLIN_FACT\".\"PRICE\", "
                     + "\"TEST_KYLIN_FACT\".\"ITEM_COUNT\" "
                     + "from \"DEFAULT\".\"TEST_KYLIN_FACT\") as 
\"TEST_KYLIN_FACT\" "
-                    + "join TEST_ORDER on TEST_KYLIN_FACT.ORDER_ID = 
TEST_ORDER.ORDER_ID";
+                    + "join \"TEST_ORDER\" on TEST_KYLIN_FACT.ORDER_ID = 
TEST_ORDER.ORDER_ID";
+            Assertions.assertEquals(expected, converted);
+        }
+        // with-item has alias in with-body
+        {
+            String sql = "with \"TEMP_DEPT\" as (select fpd.order_id, 
fpd.buyer_id "
+                    + "from test_order as fpd group by fpd.order_id, 
fpd.buyer_id)\n"
+                    + "select fpd.order_id, fpd.buyer_id from temp_dept as 
fpd";
+            String converted = TRANSFORMER.convert(sql, PROJECT, SCHEMA);
+            String expected = "with \"TEMP_DEPT\" as (select fpd.order_id, 
fpd.buyer_id from ( "
+                    + "select \"TEST_ORDER\".\"ORDER_ID\", 
\"TEST_ORDER\".\"BUYER_ID\", \"TEST_ORDER\".\"TEST_DATE_ENC\" "
+                    + "from \"DEFAULT\".\"TEST_ORDER\") as \"FPD\" group by 
fpd.order_id, fpd.buyer_id)\n"
+                    + "select fpd.order_id, fpd.buyer_id from \"TEMP_DEPT\" as 
\"FPD\"";
             Assertions.assertEquals(expected, converted);
         }
         // some content of with-body reuse with-items
@@ -132,7 +144,7 @@ class HackSelectStarWithColumnACLTest {
                     + "select \"TEST_KYLIN_FACT\".\"ORDER_ID\", 
\"TEST_KYLIN_FACT\".\"PRICE\", "
                     + "\"TEST_KYLIN_FACT\".\"ITEM_COUNT\" "
                     + "from \"DEFAULT\".\"TEST_KYLIN_FACT\") as 
\"TEST_KYLIN_FACT\" "
-                    + "join (select * from TEST_ORDER) TEST_ORDER on 
TEST_KYLIN_FACT.ORDER_ID = TEST_ORDER.ORDER_ID";
+                    + "join (select * from \"TEST_ORDER\") TEST_ORDER on 
TEST_KYLIN_FACT.ORDER_ID = TEST_ORDER.ORDER_ID";
             Assertions.assertEquals(expected, converted);
         }
         // all contexts of with-body do not reuse any with-items
@@ -170,7 +182,7 @@ class HackSelectStarWithColumnACLTest {
                     + "select * from ( select 
\"TEST_KYLIN_FACT\".\"ORDER_ID\", \"TEST_KYLIN_FACT\".\"PRICE\", "
                     + "\"TEST_KYLIN_FACT\".\"ITEM_COUNT\" "
                     + "from \"DEFAULT\".\"TEST_KYLIN_FACT\") as 
\"TEST_KYLIN_FACT\")\n"
-                    + "select * from TEST_KYLIN_FACT join (select * from 
TEST_ORDER) TEST_ORDER "
+                    + "select * from \"TEST_KYLIN_FACT\" join (select * from 
\"TEST_ORDER\") TEST_ORDER "
                     + "on TEST_KYLIN_FACT.ORDER_ID = TEST_ORDER.ORDER_ID";
             Assertions.assertEquals(expected, converted);
         }

Reply via email to