Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong TableDataNode is returned when tablename contains number #29316

Open
Afsalmc opened this issue Dec 7, 2023 · 2 comments
Open

Wrong TableDataNode is returned when tablename contains number #29316

Afsalmc opened this issue Dec 7, 2023 · 2 comments

Comments

@Afsalmc
Copy link

Afsalmc commented Dec 7, 2023

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

@Afsalmc
Copy link
Author

Afsalmc commented Dec 7, 2023

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

Copy link

github-actions bot commented Jan 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants