You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/12/21 09:47:32 UTC

[GitHub] [shardingsphere] MingxingLAI opened a new pull request #14197: 14101 ignore case when execute show tables statement

MingxingLAI opened a new pull request #14197:
URL: https://github.com/apache/shardingsphere/pull/14197


   Fixes #14101 .
   
   Changes proposed in this pull request:
   - ignore case when execute show tables statement
   - Add more unit test for ShowTablesExecutor
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #14197: 14101 ignore case when execute show tables statement

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #14197:
URL: https://github.com/apache/shardingsphere/pull/14197#discussion_r774825970



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java
##########
@@ -78,7 +78,7 @@ private QueryResult getQueryResult(final String schemaName) {
     private Collection<String> getAllTableNames(final String schemaName) {
         Collection<String> allTableNames = ProxyContext.getInstance().getMetaData(schemaName).getSchema().getAllTableNames();
         if (showTablesStatement.getFilter().isPresent()) {
-            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern()));
+            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern().toLowerCase()));
             return pattern.isPresent() ? allTableNames.stream().filter(each -> each.matches(pattern.get())).collect(Collectors.toList()) : allTableNames;

Review comment:
       Hi @MingxingLAI, does this pr has any progress?




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] MingxingLAI commented on a change in pull request #14197: 14101 ignore case when execute show tables statement

Posted by GitBox <gi...@apache.org>.
MingxingLAI commented on a change in pull request #14197:
URL: https://github.com/apache/shardingsphere/pull/14197#discussion_r773042643



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java
##########
@@ -78,7 +78,7 @@ private QueryResult getQueryResult(final String schemaName) {
     private Collection<String> getAllTableNames(final String schemaName) {
         Collection<String> allTableNames = ProxyContext.getInstance().getMetaData(schemaName).getSchema().getAllTableNames();
         if (showTablesStatement.getFilter().isPresent()) {
-            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern()));
+            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern().toLowerCase()));
             return pattern.isPresent() ? allTableNames.stream().filter(each -> each.matches(pattern.get())).collect(Collectors.toList()) : allTableNames;

Review comment:
       I think there are three ways to slove this problem:
   
   1. Treat all table names in lower case(like this pull request)
   2. Distinguish case of table name
   3. Ignore uppercase table names
   
   Which solution do you think is the most proper ?
   
   If we use the second solution, it may cause compatibility problems for many users who has use ShardingSphere and threat all table names in lower case. So, I think the first solution is proper.




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] MingxingLAI commented on a change in pull request #14197: 14101 ignore case when execute show tables statement

Posted by GitBox <gi...@apache.org>.
MingxingLAI commented on a change in pull request #14197:
URL: https://github.com/apache/shardingsphere/pull/14197#discussion_r773042643



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java
##########
@@ -78,7 +78,7 @@ private QueryResult getQueryResult(final String schemaName) {
     private Collection<String> getAllTableNames(final String schemaName) {
         Collection<String> allTableNames = ProxyContext.getInstance().getMetaData(schemaName).getSchema().getAllTableNames();
         if (showTablesStatement.getFilter().isPresent()) {
-            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern()));
+            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern().toLowerCase()));
             return pattern.isPresent() ? allTableNames.stream().filter(each -> each.matches(pattern.get())).collect(Collectors.toList()) : allTableNames;

Review comment:
       I think there are three ways to slove this problem:
   
   1. Treat all table names in lower case(like this pull request)
   2. Distinguish case of table name
   3. Ignore uppercase table names
   
   Which solution do you think is the most proper ?
   
   If we use the second solution, it may cause compatibility problems for many users who has use ShardingSphere and thread all table names in lower case. So, I this the first solution is proper.




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] MingxingLAI closed pull request #14197: 14101 ignore case when execute show tables statement

Posted by GitBox <gi...@apache.org>.
MingxingLAI closed pull request #14197:
URL: https://github.com/apache/shardingsphere/pull/14197


   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] MingxingLAI commented on a change in pull request #14197: 14101 ignore case when execute show tables statement

Posted by GitBox <gi...@apache.org>.
MingxingLAI commented on a change in pull request #14197:
URL: https://github.com/apache/shardingsphere/pull/14197#discussion_r773047528



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java
##########
@@ -78,7 +78,7 @@ private QueryResult getQueryResult(final String schemaName) {
     private Collection<String> getAllTableNames(final String schemaName) {
         Collection<String> allTableNames = ProxyContext.getInstance().getMetaData(schemaName).getSchema().getAllTableNames();
         if (showTablesStatement.getFilter().isPresent()) {
-            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern()));
+            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern().toLowerCase()));
             return pattern.isPresent() ? allTableNames.stream().filter(each -> each.matches(pattern.get())).collect(Collectors.toList()) : allTableNames;

Review comment:
       In addition,In the implement of ShardingSphere, treat all table names in lower case.
   
   ```java
   
   public final class ShardingSphereSchema {
       
       private final Map<String, TableMetaData> tables;
       
       @SuppressWarnings("CollectionWithoutInitialCapacity")
       public ShardingSphereSchema() {
           tables = new ConcurrentHashMap<>();
       }
       
       public ShardingSphereSchema(final Map<String, TableMetaData> tables) {
           this.tables = new ConcurrentHashMap<>(tables.size(), 1);
           tables.forEach((key, value) -> this.tables.put(key.toLowerCase(), value));
       }
   ```




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #14197: 14101 ignore case when execute show tables statement

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #14197:
URL: https://github.com/apache/shardingsphere/pull/14197#discussion_r773001682



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java
##########
@@ -78,7 +78,7 @@ private QueryResult getQueryResult(final String schemaName) {
     private Collection<String> getAllTableNames(final String schemaName) {
         Collection<String> allTableNames = ProxyContext.getInstance().getMetaData(schemaName).getSchema().getAllTableNames();
         if (showTablesStatement.getFilter().isPresent()) {
-            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern()));
+            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern().toLowerCase()));
             return pattern.isPresent() ? allTableNames.stream().filter(each -> each.matches(pattern.get())).collect(Collectors.toList()) : allTableNames;

Review comment:
       Hi @MingxingLAI, `allTableNames` returns lowercase table names now, which is the cause of confusion for users.




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] MingxingLAI commented on a change in pull request #14197: 14101 ignore case when execute show tables statement

Posted by GitBox <gi...@apache.org>.
MingxingLAI commented on a change in pull request #14197:
URL: https://github.com/apache/shardingsphere/pull/14197#discussion_r773056820



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java
##########
@@ -78,7 +78,7 @@ private QueryResult getQueryResult(final String schemaName) {
     private Collection<String> getAllTableNames(final String schemaName) {
         Collection<String> allTableNames = ProxyContext.getInstance().getMetaData(schemaName).getSchema().getAllTableNames();
         if (showTablesStatement.getFilter().isPresent()) {
-            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern()));
+            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern().toLowerCase()));
             return pattern.isPresent() ? allTableNames.stream().filter(each -> each.matches(pattern.get())).collect(Collectors.toList()) : allTableNames;

Review comment:
       I also think distinguish case of table name is more accurate, but I am still more worried about compatibility problem, or we invite more people to participate in this discussion?




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] MingxingLAI commented on a change in pull request #14197: 14101 ignore case when execute show tables statement

Posted by GitBox <gi...@apache.org>.
MingxingLAI commented on a change in pull request #14197:
URL: https://github.com/apache/shardingsphere/pull/14197#discussion_r773155492



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java
##########
@@ -78,7 +78,7 @@ private QueryResult getQueryResult(final String schemaName) {
     private Collection<String> getAllTableNames(final String schemaName) {
         Collection<String> allTableNames = ProxyContext.getInstance().getMetaData(schemaName).getSchema().getAllTableNames();
         if (showTablesStatement.getFilter().isPresent()) {
-            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern()));
+            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern().toLowerCase()));
             return pattern.isPresent() ? allTableNames.stream().filter(each -> each.matches(pattern.get())).collect(Collectors.toList()) : allTableNames;

Review comment:
       good idea, I will change the implement.




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #14197: 14101 ignore case when execute show tables statement

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #14197:
URL: https://github.com/apache/shardingsphere/pull/14197#discussion_r773144253



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java
##########
@@ -78,7 +78,7 @@ private QueryResult getQueryResult(final String schemaName) {
     private Collection<String> getAllTableNames(final String schemaName) {
         Collection<String> allTableNames = ProxyContext.getInstance().getMetaData(schemaName).getSchema().getAllTableNames();
         if (showTablesStatement.getFilter().isPresent()) {
-            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern()));
+            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern().toLowerCase()));
             return pattern.isPresent() ? allTableNames.stream().filter(each -> each.matches(pattern.get())).collect(Collectors.toList()) : allTableNames;

Review comment:
       > In addition,In the implement of ShardingSphere, treat all table names in lower case.
   > 
   > ```java
   > public final class ShardingSphereSchema {
   >     
   >     private final Map<String, TableMetaData> tables;
   >     
   >     @SuppressWarnings("CollectionWithoutInitialCapacity")
   >     public ShardingSphereSchema() {
   >         tables = new ConcurrentHashMap<>();
   >     }
   >     
   >     public ShardingSphereSchema(final Map<String, TableMetaData> tables) {
   >         this.tables = new ConcurrentHashMap<>(tables.size(), 1);
   >         tables.forEach((key, value) -> this.tables.put(key.toLowerCase(), value));
   >     }
   > ```
   
   @MingxingLAI Only the key is lowercase, and all the real information is stored in the values. So, I think we can use values to handle show tables logic.




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #14197: 14101 ignore case when execute show tables statement

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #14197:
URL: https://github.com/apache/shardingsphere/pull/14197#discussion_r773050494



##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java
##########
@@ -78,7 +78,7 @@ private QueryResult getQueryResult(final String schemaName) {
     private Collection<String> getAllTableNames(final String schemaName) {
         Collection<String> allTableNames = ProxyContext.getInstance().getMetaData(schemaName).getSchema().getAllTableNames();
         if (showTablesStatement.getFilter().isPresent()) {
-            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern()));
+            Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern().toLowerCase()));
             return pattern.isPresent() ? allTableNames.stream().filter(each -> each.matches(pattern.get())).collect(Collectors.toList()) : allTableNames;

Review comment:
       @MingxingLAI I think we should distinguish case of table name for this issue. And the final result displayed to the user should be consistent with the table in the database, rather than converted to lowercase.




-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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