From 7674353943403f2b74defd6fedb1c24ff8b75da2 Mon Sep 17 00:00:00 2001 From: morningman Date: Sat, 14 Sep 2024 10:48:35 +0800 Subject: [PATCH] 3 --- .../nereids/rules/analysis/BindRelation.java | 12 ++++++---- .../tablefunction/MetadataGenerator.java | 2 +- .../PartitionValuesTableValuedFunction.java | 23 +++++++++++-------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java index 0f4fad8b321a5ad..74411dfef1e0bdb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java @@ -368,9 +368,10 @@ public static LogicalPlan checkAndAddDeleteSignFilter(LogicalOlapScan scan, Conn return scan; } - private Optional handleMetaTable(TableIf table, UnboundRelation unboundRelation) { + private Optional handleMetaTable(TableIf table, UnboundRelation unboundRelation, + List qualifiedTableName) { Optional tvf = table.getDatabase().getCatalog().getMetaTableFunction( - table, unboundRelation.getNameParts().get(2)); + table, qualifiedTableName.get(2)); if (tvf.isPresent()) { return Optional.of(new LogicalTVFRelation(unboundRelation.getRelationId(), tvf.get())); } @@ -385,15 +386,16 @@ private LogicalPlan getLogicalPlan(TableIf table, UnboundRelation unboundRelatio statementContext.addIndexInSqlToString(pair, Utils.qualifiedNameWithBackquote(qualifiedTableName)); }); - List qualifierWithoutTableName = Lists.newArrayList(); - qualifierWithoutTableName.addAll(qualifiedTableName.subList(0, qualifiedTableName.size() - 1)); // Handle meta table like "table_name$partitions" - Optional logicalPlan = handleMetaTable(table, unboundRelation); + // qualifiedTableName should be like "ctl.db.tbl$partitions" + Optional logicalPlan = handleMetaTable(table, unboundRelation, qualifiedTableName); if (logicalPlan.isPresent()) { return logicalPlan.get(); } + List qualifierWithoutTableName = Lists.newArrayList(); + qualifierWithoutTableName.addAll(qualifiedTableName.subList(0, qualifiedTableName.size() - 1)); boolean isView = false; try { switch (table.getType()) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java index c0dd9cdc7af870f..d66650c1083c9eb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/MetadataGenerator.java @@ -1482,7 +1482,7 @@ private static TFetchSchemaTableDataResult partitionValuesMetadataResult(TMetada String tblName = metaParams.getTable(); List dataBatch; try { - TableIf table = PartitionValuesTableValuedFunction.analyzeAndGetTable(ctlName, dbName, tblName); + TableIf table = PartitionValuesTableValuedFunction.analyzeAndGetTable(ctlName, dbName, tblName, false); TableType tableType = table.getType(); switch (tableType) { case HMS_EXTERNAL_TABLE: diff --git a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/PartitionValuesTableValuedFunction.java b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/PartitionValuesTableValuedFunction.java index 49a4287e54939ab..01eebbc2fef2a70 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/tablefunction/PartitionValuesTableValuedFunction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/tablefunction/PartitionValuesTableValuedFunction.java @@ -84,7 +84,7 @@ public PartitionValuesTableValuedFunction(Map params) throws Ana if (StringUtils.isEmpty(catalogName) || StringUtils.isEmpty(dbName) || StringUtils.isEmpty(tableName)) { throw new AnalysisException("catalog, database and table are required"); } - this.table = analyzeAndGetTable(catalogName, dbName, tableName); + this.table = analyzeAndGetTable(catalogName, dbName, tableName, true); this.catalogName = catalogName; this.databaseName = dbName; this.tableName = tableName; @@ -93,14 +93,19 @@ public PartitionValuesTableValuedFunction(Map params) throws Ana } } - public static TableIf analyzeAndGetTable(String catalogName, String dbName, String tableName) { - if (!Env.getCurrentEnv().getAccessManager() - .checkTblPriv(ConnectContext.get(), catalogName, dbName, - tableName, PrivPredicate.SHOW)) { - String message = ErrorCode.ERR_TABLEACCESS_DENIED_ERROR.formatErrorMsg("SHOW PARTITIONS", - ConnectContext.get().getQualifiedUser(), ConnectContext.get().getRemoteIP(), - catalogName + ": " + dbName + ": " + tableName); - throw new AnalysisException(message); + public static TableIf analyzeAndGetTable(String catalogName, String dbName, String tableName, boolean checkAuth) { + if (checkAuth) { + // This method will be called at 2 places: + // One is when planing the query, which should check the privilege of the user. + // the other is when BE call FE to fetch partition values, which should not check the privilege. + if (!Env.getCurrentEnv().getAccessManager() + .checkTblPriv(ConnectContext.get(), catalogName, dbName, + tableName, PrivPredicate.SHOW)) { + String message = ErrorCode.ERR_TABLEACCESS_DENIED_ERROR.formatErrorMsg("SHOW PARTITIONS", + ConnectContext.get().getQualifiedUser(), ConnectContext.get().getRemoteIP(), + catalogName + ": " + dbName + ": " + tableName); + throw new AnalysisException(message); + } } CatalogIf catalog = Env.getCurrentEnv().getCatalogMgr().getCatalog(catalogName); if (catalog == null) {