Skip to content

Commit

Permalink
3
Browse files Browse the repository at this point in the history
  • Loading branch information
morningman committed Sep 14, 2024
1 parent 5d58c26 commit 7674353
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,10 @@ public static LogicalPlan checkAndAddDeleteSignFilter(LogicalOlapScan scan, Conn
return scan;
}

private Optional<LogicalPlan> handleMetaTable(TableIf table, UnboundRelation unboundRelation) {
private Optional<LogicalPlan> handleMetaTable(TableIf table, UnboundRelation unboundRelation,
List<String> qualifiedTableName) {
Optional<TableValuedFunction> 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()));
}
Expand All @@ -385,15 +386,16 @@ private LogicalPlan getLogicalPlan(TableIf table, UnboundRelation unboundRelatio
statementContext.addIndexInSqlToString(pair,
Utils.qualifiedNameWithBackquote(qualifiedTableName));
});
List<String> qualifierWithoutTableName = Lists.newArrayList();
qualifierWithoutTableName.addAll(qualifiedTableName.subList(0, qualifiedTableName.size() - 1));

// Handle meta table like "table_name$partitions"
Optional<LogicalPlan> logicalPlan = handleMetaTable(table, unboundRelation);
// qualifiedTableName should be like "ctl.db.tbl$partitions"
Optional<LogicalPlan> logicalPlan = handleMetaTable(table, unboundRelation, qualifiedTableName);
if (logicalPlan.isPresent()) {
return logicalPlan.get();
}

List<String> qualifierWithoutTableName = Lists.newArrayList();
qualifierWithoutTableName.addAll(qualifiedTableName.subList(0, qualifiedTableName.size() - 1));
boolean isView = false;
try {
switch (table.getType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ private static TFetchSchemaTableDataResult partitionValuesMetadataResult(TMetada
String tblName = metaParams.getTable();
List<TRow> 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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public PartitionValuesTableValuedFunction(Map<String, String> 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;
Expand All @@ -93,14 +93,19 @@ public PartitionValuesTableValuedFunction(Map<String, String> 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) {
Expand Down

0 comments on commit 7674353

Please sign in to comment.