You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "Afsalmc (via GitHub)" <gi...@apache.org> on 2023/12/07 11:10:12 UTC

[I] Wrong TableDataNode is returned when tablename contains number [shardingsphere]

Afsalmc opened a new issue, #29316:
URL: https://github.com/apache/shardingsphere/issues/29316

   ## Bug Report
   
   
   ### Which version of ShardingSphere did you use?
   5.4.1
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC
   ### Expected behavior
   TableRule.createTableDataNode() returns the correct value.
   ### Actual behavior
   TableRule.createTableDataNode() returns value with all number omitted
   ### Reason analyze (If you can)
   ```
       private DataNodeInfo createTableDataNode(final Collection<DataNode> actualDataNodes) {
           String tableName = actualDataNodes.iterator().next().getTableName();
           String prefix = tableName.startsWith(logicTable) ? logicTable + DATA_NODE_SUFFIX_PATTERN.matcher(tableName.substring(logicTable.length())).replaceAll("")
                   : DATA_NODE_SUFFIX_PATTERN.matcher(tableName).replaceAll("");
           int suffixMinLength = actualDataNodes.stream().map(each -> each.getTableName().length() - prefix.length()).min(Comparator.comparing(Integer::intValue)).orElse(1);
           return new DataNodeInfo(prefix, suffixMinLength, DEFAULT_PADDING_CHAR);
       }
   ```
   `DATA_NODE_SUFFIX_PATTERN` implies a regex pattern to match all numbers, it then wrongly identifies the matching number as table name suffix even if the number is part of the actual tablename.
   
   Eg : Suppose I have a table named AllPatientsV1 ... it returns AllPatientsV as prefix and suffix length as 1, thinking the 1, in the end, was a suffix but it is part of the table name. 
   This prevents me from adding bindingtableRules since `ShardingRule.isValidActualTableName() `returns `false` when contains a table like AllPatientsV1.
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   
   ### Example codes for reproduce this issue (such as a github link).
   


-- 
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.apache.org

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


Re: [I] Wrong TableDataNode is returned when tablename contains number [shardingsphere]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #29316:
URL: https://github.com/apache/shardingsphere/issues/29316#issuecomment-1879814749

   There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.


-- 
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


Re: [I] Wrong TableDataNode is returned when tablename contains number [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu closed issue #29316: Wrong TableDataNode is returned when tablename contains number
URL: https://github.com/apache/shardingsphere/issues/29316


-- 
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


Re: [I] Wrong TableDataNode is returned when tablename contains number [shardingsphere]

Posted by "Afsalmc (via GitHub)" <gi...@apache.org>.
Afsalmc commented on issue #29316:
URL: https://github.com/apache/shardingsphere/issues/29316#issuecomment-1845150558

   Is there a workaround to use bindingtables in the mean time ?


-- 
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


Re: [I] Wrong TableDataNode is returned when tablename contains number [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu commented on issue #29316:
URL: https://github.com/apache/shardingsphere/issues/29316#issuecomment-3552465074

   ### Issue Understanding
   
     - In ShardingSphere-JDBC 5.4.1, configuring binding tables fails with ShardingRule.isValidActualTableName() when actual table names include business digits such as AllPatientsV1.
   
     ### Root Cause
   
     - ShardingTable.createTableDataNode() assumes actual tables follow “common prefix + numeric suffix”. It removes trailing digits via DATA_NODE_SUFFIX_PATTERN (\d+$):
   
       private DataNodeInfo createTableDataNode(final Collection<DataNode> actualDataNodes) {
           String tableName = actualDataNodes.iterator().next().getTableName();
           String prefix = tableName.startsWith(logicTable)
                   ? logicTable + ShardingTableConstants.DATA_NODE_SUFFIX_PATTERN.matcher(tableName.substring(logicTable.length())).replaceAll("")
                   : ShardingTableConstants.DATA_NODE_SUFFIX_PATTERN.matcher(tableName).replaceAll("");
           int suffixMinLength = actualDataNodes.stream()
                   .map(each -> each.getTableName().length() - prefix.length())
                   .min(Comparator.comparing(Integer::intValue)).orElse(1);
           return new DataNodeInfo(prefix, suffixMinLength, ShardingTableConstants.DEFAULT_PADDING_CHAR);
       }
     - As a result, any digits—even those that are part of the real name—are stripped during binding-table validation.
   
     ### Issue Analysis
   
     - This behavior reflects the community convention: actual table names must share an identical prefix and use pure numeric suffixes so that different logic tables align their sharding topology. The “Binding Table Configuration” guide (https://shardingsphere.apache.org/
       document/current/en/user-manual/shardingsphere-jdbc/yaml-config/sharding/binding-tables/) describes binding rules but does not explicitly emphasize the numeric-suffix constraint.
     - Therefore the current implementation is behaving as designed; supporting non-numeric suffixes would require additional features (e.g., customizable suffix patterns).
   
     ### Conclusion & Next Steps
   
     - No code change is planned; users should follow the numeric-suffix naming convention when defining binding tables (e.g., t_order_0, t_order_1).
     - Documentation needs a clarification: update docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/sharding/binding-tables*.md to state that actual table names must share a common prefix and end with numeric indexes, and provide inline/actualDataNodes
       examples reflecting this rule.
     - We warmly invite community contributors to submit a PR that (1) adds the documentation note above, and (2) optionally includes guidance on how to handle table names that contain business digits. Please feel free to volunteer on this issue—your docs/tests contributions
       are highly appreciated!
   


-- 
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