morningman commented on code in PR #9206:
URL: https://github.com/apache/incubator-doris/pull/9206#discussion_r868859258
##########
docs/zh-CN/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-POLICY.md:
##########
@@ -0,0 +1,84 @@
+---
+{
Review Comment:
Add document to sidebar
##########
fe/fe-core/src/main/java/org/apache/doris/analysis/StmtRewriter.java:
##########
@@ -1141,5 +1154,52 @@ private static Expr createJoinConjunct(Expr
exprWithSubquery, InlineViewRef inli
smap.put(subquery, subquerySubstitute);
return exprWithSubquery.substitute(smap, analyzer, false);
}
+
+ public static boolean rewriteByPolicy(StatementBase statementBase,
Analyzer analyzer) throws UserException {
+ Catalog currentCatalog = Catalog.getCurrentCatalog();
+ if (!(statementBase instanceof SelectStmt)) {
+ return false;
+ }
+ SelectStmt selectStmt = (SelectStmt) statementBase;
+ boolean reAnalyze = false;
+ for (int i = 0; i < selectStmt.fromClause_.size(); i++) {
+ TableRef tableRef = selectStmt.fromClause_.get(i);
+ // Recursively rewrite subquery
+ if (tableRef instanceof InlineViewRef) {
+ InlineViewRef viewRef = (InlineViewRef) tableRef;
+ if (rewriteByPolicy(viewRef.getQueryStmt(), analyzer)) {
+ reAnalyze = true;
+ }
+ continue;
+ }
+ Table table = tableRef.getTable();
+ String dbName = tableRef.getName().getDb();
+ if (dbName == null) {
+ dbName = analyzer.getDefaultDb();
+ }
+ Database db = currentCatalog.getDbOrAnalysisException(dbName);
+ long dbId = db.getId();
+ long tableId = table.getId();
+ String user = analyzer.getQualifiedUser();
+ Policy matchPolicy =
currentCatalog.getPolicyMgr().getMatchRowPolicy(dbId, tableId, user);
Review Comment:
I think we can move this check in front of the method, so that if there is
no policy at all, the method can be returned directly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]