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/11/30 06:50:08 UTC

[GitHub] [shardingsphere] maketubo opened a new issue #13862: Will mixed shardingAlgorithms will be support?

maketubo opened a new issue #13862:
URL: https://github.com/apache/shardingsphere/issues/13862


   **Hi, i am new to sharding-jdbc.**
   **I try a test with both HintInlineShardingAlgorithm and InlineShardingAlgorithm on one logic table.**
   **The configuration is as follows: **
   ```
   // 配置 表规则
     ShardingTableRuleConfiguration hintRule = new ShardingTableRuleConfiguration
             ("demo", String.format("ds0.demo_${0..%s}", 2));
     hintRule.setTableShardingStrategy
             (new HintShardingStrategyConfiguration("demoHintAlgorithm"));
     shardingRuleConfig.getTables().add(hintRule);
   
   
     ShardingTableRuleConfiguration rule = new ShardingTableRuleConfiguration
             ("demo", String.format("ds0.demo_${0..%s}", 2));
     // 配置分表策略
     instanceRule.setTableShardingStrategy
             (new StandardShardingStrategyConfiguration("demo_id", "demoAlgorithm"));
     // 配置分片规则
     shardingRuleConfig.getTables().add(rule);
   
   Properties hintAlgorithmProps = new Properties();
           instanceHintAlgorithmProps.setProperty("algorithm-expression", "demo_${value}");
           shardingRuleConfig.getShardingAlgorithms().put("demoHintAlgorithm",
                   new ShardingSphereAlgorithmConfiguration("HINT_INLINE", hintAlgorithmProps));
   
     Properties demoAlgorithmProps = new Properties();
     instanceAlgorithmProps.setProperty("algorithm-expression",
            "demo_${demo_id%"+ 2 + "}");
     shardingRuleConfig.getShardingAlgorithms().put("demoAlgorithm",
             new ShardingSphereAlgorithmConfiguration("INLINE", demoAlgorithmProps));
   ```
   **Then i try query and work as expected.**
   ```
   //work
   try (HintManager hintManager = HintManager.getInstance()) {
           hintManager.addDatabaseShardingValue("demo", 0);
           hintManager.addTableShardingValue("demo", 1);
           try (
                   Connection conn = shardingDataSource.getConnection();
                   PreparedStatement ps = conn.prepareStatement(sql)) {
                   ps.setString(1, "hello");
               try (ResultSet rs = ps.executeQuery()) {
                   while(rs.next()) {
                       System.out.println(rs.getLong("demo_id"));
                   }
               }
           }
       }
   
   //work
   try (HintManager hintManager = HintManager.getInstance()) {
           hintManager.addDatabaseShardingValue("demo", 0);
           //hintManager.addTableShardingValue("demo", 1);
           try (
                   Connection conn = shardingDataSource.getConnection();
                   PreparedStatement ps = conn.prepareStatement(sql)) {
                   ps.setString(1, "hello");
               try (ResultSet rs = ps.executeQuery()) {
                   while(rs.next()) {
                       System.out.println(rs.getLong("demo_id"));
                   }
               }
           }
       }
   
   
   // not work
   // try execute insert sql without hintManager. addTableShardingValue
   ```
   
   ————————————————
   我尝试混合使用HintInlineShardingAlgorithm和InlineShardingAlgorithm,如果首先将hint分片算法添加进shardingRule,可以得到预期表现:只有指定了hint分片路由才会走指定的表,如果不指定,会扫描全部的物理表。应用的场景是有时候查询只在某张表进行,有时候需要在所有表中进行。一切都运行正常,但是当执行insert时(插入的sql中包含inline分片的列),会报java.lang.IllegalStateException: Insert statement does not support sharding table routing to multiple data nodes. 原因是ShardingSQLRouter中的postValidate不通过。
   请问未来会考虑支持HintInlineShardingAlgorithm和InlineShardingAlgorithm共同使用在同一张逻辑表的场景么?


-- 
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] terrymanu commented on issue #13862: Will mixed shardingAlgorithms will be support?

Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #13862:
URL: https://github.com/apache/shardingsphere/issues/13862#issuecomment-1046272421


   I just close it because no response for long 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



[GitHub] [shardingsphere] terrymanu closed issue #13862: Will mixed shardingAlgorithms will be support?

Posted by GitBox <gi...@apache.org>.
terrymanu closed issue #13862:
URL: https://github.com/apache/shardingsphere/issues/13862


   


-- 
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 issue #13862: Will mixed shardingAlgorithms will be support?

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #13862:
URL: https://github.com/apache/shardingsphere/issues/13862#issuecomment-982455261


   @maketubo Apache ShardingSphere only provides some general sharding algorithms, and does not provide customized algorithms. If you want to customize the sharding algorithm, you can use the `class_based` algorithm——https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/builtin-algorithm/sharding/#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%B1%BB%E5%88%86%E7%89%87%E7%AE%97%E6%B3%95.


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