You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "georgereuben (via GitHub)" <gi...@apache.org> on 2025/08/10 08:41:37 UTC

[PR] [#7979] Improvement [Catalog]: Add reserved words check for MySQL/Postgres [gravitino]

georgereuben opened a new pull request, #8002:
URL: https://github.com/apache/gravitino/pull/8002

   <!--
   1. Title: [#<issue>] <type>(<scope>): <subject>
      Examples:
        - "[#123] feat(operator): support xxx"
        - "[#233] fix: check null before access result in xxx"
        - "[MINOR] refactor: fix typo in variable name"
        - "[MINOR] docs: fix typo in README"
        - "[#255] test: fix flaky test NameOfTheTest"
      Reference: https://www.conventionalcommits.org/en/v1.0.0/
   2. If the PR is unfinished, please mark this PR as draft.
   -->
   
   ### What changes were proposed in this pull request?
   - Added validation for reserved words in PostgreSQL catalog capability.
   - Reserved words (like pg_catalog, information_schema) are now checked for both schema and table scopes to prevent naming conflicts.
   
   ### Why are the changes needed?
   
   Prevents users from creating schemas or tables with names that conflict with system catalogs or schemas.
   
   Fix: #7979 
   
   ### Does this PR introduce _any_ user-facing change?
   Users will receive an error if they attempt to use reserved names for schemas or tables in PostgreSQL catalogs.
   
   ### How was this patch tested?
   UTs


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7979] Improvement [Catalog]: Add reserved words check for MySQL/Postgres [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #8002:
URL: https://github.com/apache/gravitino/pull/8002#issuecomment-3177431004

   Since those names are protected, I believe that MySQL & PG will throw exceptions if we attempt to create a schema with that name. So why do we check it again? Is it just to throw an exception early?
   
   


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7979] Improvement [Catalog]: Add reserved words check for MySQL/Postgres [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #8002:
URL: https://github.com/apache/gravitino/pull/8002#issuecomment-3177525032

   > > Since those names are protected, I believe that MySQL & PG will throw exceptions if we attempt to create a schema with that name. So why do we check it again? Is it just to throw an exception early?
   > 
   > Yes, it would provide early validation and fail-fast before db operations, and clearer error logs for users that we can make consistent across the different db catalogs.
   
   I see. This PR is acceptable to me, and I'm going to merge it today. By the way, could you also raise other PRs to solve similar problems in other catalogs , such as StarRocks, Doris, Hive , etc. 


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7979] Improvement [Catalog]: Add reserved words check for MySQL/Postgres [gravitino]

Posted by "georgereuben (via GitHub)" <gi...@apache.org>.
georgereuben commented on PR #8002:
URL: https://github.com/apache/gravitino/pull/8002#issuecomment-3174472514

   > @georgereuben , could you please add some UTs or ITs to cover the changes?
   
   Added UTs and ITs, please let me know if any changes are needed


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7979] Improvement [Catalog]: Add reserved words check for MySQL/Postgres [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #8002:
URL: https://github.com/apache/gravitino/pull/8002#issuecomment-3173043403

   @georgereuben , could you please add some UTs or ITs to cover the changes?


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7979] Improvement [Catalog]: Add reserved words check for MySQL/Postgres [gravitino]

Posted by "georgereuben (via GitHub)" <gi...@apache.org>.
georgereuben commented on code in PR #8002:
URL: https://github.com/apache/gravitino/pull/8002#discussion_r2266660068


##########
catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/MysqlCatalogCapability.java:
##########
@@ -39,13 +40,23 @@ public class MysqlCatalogCapability implements Capability {
    */
   public static final String MYSQL_NAME_PATTERN = "^[\\w\\p{L}-$/=]{1,64}$";
 
+  /** Reserved schema andtable names in MySQL that cannot be used for user-defined schemas. */
+  private static final Set<String> MYSQL_RESERVED_SCHEMAS =
+      Set.of("mysql", "information_schema", "performance_schema", "sys");
+
   @Override
   public CapabilityResult specificationOnName(Scope scope, String name) {
-    // TODO: Validate the name against reserved words
     if (!name.matches(MYSQL_NAME_PATTERN)) {
       return CapabilityResult.unsupported(
           String.format("The %s name '%s' is illegal.", scope, name));
     }
+
+    if ((scope == Scope.SCHEMA || scope == Scope.TABLE)
+        && MYSQL_RESERVED_SCHEMAS.contains(name.toLowerCase())) {
+      return CapabilityResult.unsupported(

Review Comment:
   Thanks for pointing this out. My initial intention was to prevent conflicts by restricting both schema and table names, but I see now that restricting reserved schema names like the ones above won't be needed for tables. I'll update the validation so that only schema names are checked against MYSQL_RESERVED_SCHEMAS.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7979] Improvement [Catalog]: Add reserved words check for MySQL/Postgres [gravitino]

Posted by "georgereuben (via GitHub)" <gi...@apache.org>.
georgereuben commented on PR #8002:
URL: https://github.com/apache/gravitino/pull/8002#issuecomment-3177535639

   > > > Since those names are protected, I believe that MySQL & PG will throw exceptions if we attempt to create a schema with that name. So why do we check it again? Is it just to throw an exception early?
   > > 
   > > 
   > > Yes, it would provide early validation and fail-fast before db operations, and clearer error logs for users that we can make consistent across the different db catalogs.
   > 
   > I see. This PR is acceptable to me, and I'm going to merge it today. By the way, could you also raise other PRs to solve similar problems in other catalogs , such as StarRocks, Doris, Hive , etc.
   
   Sure, I'll look into it


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7979] Improvement [Catalog]: Add reserved words check for MySQL/Postgres [gravitino]

Posted by "georgereuben (via GitHub)" <gi...@apache.org>.
georgereuben commented on PR #8002:
URL: https://github.com/apache/gravitino/pull/8002#issuecomment-3177498631

   > Since those names are protected, I believe that MySQL & PG will throw exceptions if we attempt to create a schema with that name. So why do we check it again? Is it just to throw an exception early?
   
   Yes, it would provide early validation and fail-fast before db operations, and clearer error logs for users that we can make consistent across the different db catalogs.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7979] Improvement(catalogs): Add reserved words check for MySQL and Postgres [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 merged PR #8002:
URL: https://github.com/apache/gravitino/pull/8002


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7979] Improvement [Catalog]: Add reserved words check for MySQL/Postgres [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #8002:
URL: https://github.com/apache/gravitino/pull/8002#discussion_r2266544176


##########
catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/MysqlCatalogCapability.java:
##########
@@ -39,13 +40,23 @@ public class MysqlCatalogCapability implements Capability {
    */
   public static final String MYSQL_NAME_PATTERN = "^[\\w\\p{L}-$/=]{1,64}$";
 
+  /** Reserved schema andtable names in MySQL that cannot be used for user-defined schemas. */
+  private static final Set<String> MYSQL_RESERVED_SCHEMAS =
+      Set.of("mysql", "information_schema", "performance_schema", "sys");
+
   @Override
   public CapabilityResult specificationOnName(Scope scope, String name) {
-    // TODO: Validate the name against reserved words
     if (!name.matches(MYSQL_NAME_PATTERN)) {
       return CapabilityResult.unsupported(
           String.format("The %s name '%s' is illegal.", scope, name));
     }
+
+    if ((scope == Scope.SCHEMA || scope == Scope.TABLE)
+        && MYSQL_RESERVED_SCHEMAS.contains(name.toLowerCase())) {
+      return CapabilityResult.unsupported(

Review Comment:
   I can't get why tables name like `performance_schema` and `sys` are also not supported. 



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#7979] Improvement [Catalog]: Add reserved words check for MySQL/Postgres [gravitino]

Posted by "georgereuben (via GitHub)" <gi...@apache.org>.
georgereuben commented on code in PR #8002:
URL: https://github.com/apache/gravitino/pull/8002#discussion_r2266660068


##########
catalogs/catalog-jdbc-mysql/src/main/java/org/apache/gravitino/catalog/mysql/MysqlCatalogCapability.java:
##########
@@ -39,13 +40,23 @@ public class MysqlCatalogCapability implements Capability {
    */
   public static final String MYSQL_NAME_PATTERN = "^[\\w\\p{L}-$/=]{1,64}$";
 
+  /** Reserved schema andtable names in MySQL that cannot be used for user-defined schemas. */
+  private static final Set<String> MYSQL_RESERVED_SCHEMAS =
+      Set.of("mysql", "information_schema", "performance_schema", "sys");
+
   @Override
   public CapabilityResult specificationOnName(Scope scope, String name) {
-    // TODO: Validate the name against reserved words
     if (!name.matches(MYSQL_NAME_PATTERN)) {
       return CapabilityResult.unsupported(
           String.format("The %s name '%s' is illegal.", scope, name));
     }
+
+    if ((scope == Scope.SCHEMA || scope == Scope.TABLE)
+        && MYSQL_RESERVED_SCHEMAS.contains(name.toLowerCase())) {
+      return CapabilityResult.unsupported(

Review Comment:
   Thanks for pointing this out. My initial intention was to prevent conflicts by restricting both schema and table names, but I see now that reserved schema names like the ones above won't be needed for tables. I'll update the validation so that only schema names are checked against MYSQL_RESERVED_SCHEMAS.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org