You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/03/09 15:53:43 UTC
[doris] 05/10: [BugFix](PG catalog) fix that pg catalog can not get all schemas that a pg user can access. (#17517)
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 703877e20d8ed8b8bf8a306be9c37f2faf3f76ea
Author: Tiewei Fang <43...@users.noreply.github.com>
AuthorDate: Wed Mar 8 19:12:47 2023 +0800
[BugFix](PG catalog) fix that pg catalog can not get all schemas that a pg user can access. (#17517)
Describe your changes.
In the past, pg catalog use sql SELECT schema_name FROM information_schema.schemata where schema_owner='<UserName>'; to select schemas of an user. Howerver, this sql can not find all schemas that a user can access, that because:
A user may not be the owner of an schema, but may have read permission on the schema.
A user may inherit the permissions of its user group and thus have read permissions on one schema.
For these reasons, we replace the sql statement with select nspname from pg_namespace where has_schema_privilege('<UserName>', nspname, 'USAGE');
---
.../src/main/java/org/apache/doris/external/jdbc/JdbcClient.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
index c7170ca6fe..1196f67018 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java
@@ -24,6 +24,7 @@ import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.Config;
import org.apache.doris.common.DdlException;
+import org.apache.doris.common.util.Util;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -177,8 +178,8 @@ public class JdbcClient {
rs = stmt.executeQuery("SHOW DATABASES");
break;
case JdbcResource.POSTGRESQL:
- rs = stmt.executeQuery("SELECT schema_name FROM information_schema.schemata "
- + "where schema_owner='" + jdbcUser + "';");
+ rs = stmt.executeQuery("SELECT nspname FROM pg_namespace WHERE has_schema_privilege("
+ + "'" + jdbcUser + "', nspname, 'USAGE');");
break;
case JdbcResource.ORACLE:
rs = stmt.executeQuery("SELECT DISTINCT OWNER FROM all_tables");
@@ -373,7 +374,8 @@ public class JdbcClient {
tableSchema.add(field);
}
} catch (SQLException e) {
- throw new JdbcClientException("failed to get table name list from jdbc for table %s", e, tableName);
+ throw new JdbcClientException("failed to get table name list from jdbc for table %s:%s", e, tableName,
+ Util.getRootCauseMessage(e));
} finally {
close(rs, conn);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org