This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit 88668ec8caf1dc93dde9932726631fd85b3480c2 Author: zhangdong <[email protected]> AuthorDate: Thu May 25 09:10:31 2023 +0800 [fix](auth)fix row policy use alias error (#19976) Issue Number: close #19975 --- .../org/apache/doris/analysis/StmtRewriter.java | 2 +- .../java/org/apache/doris/policy/PolicyTest.java | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/StmtRewriter.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/StmtRewriter.java index 9aa9162ff5..5ee0c2d97d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/StmtRewriter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/StmtRewriter.java @@ -1321,7 +1321,7 @@ public class StmtRewriter { SelectStmt stmt = new SelectStmt(selectList, new FromClause(Lists.newArrayList(tableRef)), - matchPolicy.getWherePredicate(), + matchPolicy.getWherePredicate().clone(), null, null, null, diff --git a/fe/fe-core/src/test/java/org/apache/doris/policy/PolicyTest.java b/fe/fe-core/src/test/java/org/apache/doris/policy/PolicyTest.java index e57953af61..f4453a9568 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/policy/PolicyTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/policy/PolicyTest.java @@ -104,6 +104,33 @@ public class PolicyTest extends TestWithFeService { dropPolicy("DROP ROW POLICY test_row_policy ON test.table1 FOR test_policy"); } + @Test + public void testAliasSql() throws Exception { + createPolicy("CREATE ROW POLICY test_row_policy ON test.table1 AS PERMISSIVE TO test_policy USING (k1 = 1)"); + String queryStr = "EXPLAIN select * from test.table1 a"; + String explainString = getSQLPlanOrErrorMsg(queryStr); + Assertions.assertTrue(explainString.contains("`a`.`k1` = 1")); + queryStr = "EXPLAIN select * from test.table1 b"; + explainString = getSQLPlanOrErrorMsg(queryStr); + Assertions.assertTrue(explainString.contains("`b`.`k1` = 1")); + dropPolicy("DROP ROW POLICY test_row_policy ON test.table1 FOR test_policy"); + } + + @Test + public void testAliasSqlNereidsPlanner() throws Exception { + boolean beforeConfig = connectContext.getSessionVariable().isEnableNereidsPlanner(); + connectContext.getSessionVariable().setEnableNereidsPlanner(true); + createPolicy("CREATE ROW POLICY test_row_policy ON test.table1 AS PERMISSIVE TO test_policy USING (k1 = 1)"); + String queryStr = "EXPLAIN select * from test.table1 a"; + String explainString = getSQLPlanOrErrorMsg(queryStr); + Assertions.assertTrue(explainString.contains("`a`.`k1` = 1")); + queryStr = "EXPLAIN select * from test.table1 b"; + explainString = getSQLPlanOrErrorMsg(queryStr); + Assertions.assertTrue(explainString.contains("`b`.`k1` = 1")); + dropPolicy("DROP ROW POLICY test_row_policy ON test.table1 FOR test_policy"); + connectContext.getSessionVariable().setEnableNereidsPlanner(beforeConfig); + } + @Test public void testUnionSql() throws Exception { createPolicy("CREATE ROW POLICY test_row_policy ON test.table1 AS PERMISSIVE TO test_policy USING (k1 = 1)"); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
