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

Questions between rule assignments #24420

Closed
taetaetae opened this issue Mar 2, 2023 · 4 comments
Closed

Questions between rule assignments #24420

taetaetae opened this issue Mar 2, 2023 · 4 comments
Assignees

Comments

@taetaetae
Copy link

taetaetae commented Mar 2, 2023

Hello!

I want to utilize shardingsphere to query the existing sharding tables at once.
The current database and table configuration is as follows:

  • database name : db_0....db_3
  • table name
    • db_0 : sample_0...sample_9
    • db_1 : sample_10...sample_19
    • db_2 : sample_20...sample_29
    • db_3 : sample_30...sample_39

In this situation, how should I write the rule specification in YAML?

Also, the logic that determines the database number, table number is also a situation that requires Java logic. In this case, how can I express it in YAML?

Any help would be very helpful in setting this up, thanks!

@FlyingZC
Copy link
Member

FlyingZC commented Mar 2, 2023

You can use groovy expression configuration in yaml, and groovy expression also supports Java syntax.
You can also implement the ShardingAlgorithm algorithm to define your own sharding algorithm.

@taetaetae
Copy link
Author

Thanks for the advice @FlyingZC, I'm getting an error when I write it like below, where did I go wrong?

rules:
  - !SHARDING
    tables:
      sample:
        actualDataNodes: db$->{0..3}.sample_$->{[0,10,20,30]..[9,19,29,39]}
        tableStrategy:
          complex:
            shardingColumns: id1, id2
            shardingAlgorithmName: contentTableShardingAlgorithm
Caused by: java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.lang.Comparable (java.util.ArrayList and java.lang.Comparable are in module java.base of loader 'bootstrap')
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.createRange(ScriptBytecodeAdapter.java:693)
	at Script1.run(Script1.groovy:1)
	at org.apache.shardingsphere.infra.util.groovy.expr.HotspotInlineExpressionParser.evaluate(HotspotInlineExpressionParser.java:103)
	at org.apache.shardingsphere.infra.util.groovy.expr.HotspotInlineExpressionParser.evaluate(HotspotInlineExpressionParser.java:90)
	at org.apache.shardingsphere.infra.util.groovy.expr.HotspotInlineExpressionParser.splitAndEvaluate(HotspotInlineExpressionParser.java:68)
	at org.apache.shardingsphere.infra.util.expr.InlineExpressionParser.splitAndEvaluate(InlineExpressionParser.java:78)
	at org.apache.shardingsphere.sharding.rule.ShardingRule.getDataSourceNames(ShardingRule.java:172)
	at org.apache.shardingsphere.sharding.rule.ShardingRule.lambda$getDataSourceNames$6(ShardingRule.java:161)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at org.apache.shardingsphere.sharding.rule.ShardingRule.getDataSourceNames(ShardingRule.java:161)
	at org.apache.shardingsphere.sharding.rule.ShardingRule.<init>(ShardingRule.java:119)
	at org.apache.shardingsphere.sharding.rule.builder.ShardingRuleBuilder.build(ShardingRuleBuilder.java:42)
	at org.apache.shardingsphere.sharding.rule.builder.ShardingRuleBuilder.build(ShardingRuleBuilder.java:36)
	at org.apache.shardingsphere.infra.rule.builder.database.DatabaseRulesBuilder.build(DatabaseRulesBuilder.java:64)
	at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase.create(ShardingSphereDatabase.java:87)
	at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabasesFactory.createGenericDatabases(ShardingSphereDatabasesFactory.java:79)
	at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabasesFactory.create(ShardingSphereDatabasesFactory.java:67)
	at org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory.create(MetaDataContextsFactory.java:90)
	at org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory.create(MetaDataContextsFactory.java:68)
	at org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder.build(StandaloneContextManagerBuilder.java:53)
	at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:77)
	at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:65)
	at org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:93)
	at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:153)
	at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:95)
	at org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.createDataSource(DriverDataSourceCache.java:51)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
	at org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.get(DriverDataSourceCache.java:45)
	at org.apache.shardingsphere.driver.ShardingSphereDriver.connect(ShardingSphereDriver.java:51)
	at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121)
	at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:354)
	at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:202)
	at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473)
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:554)

@FlyingZC
Copy link
Member

FlyingZC commented Mar 6, 2023

This seems to be a groovy expression syntax error, you can first verify your expression in the groovy console of idea.

@github-actions github-actions bot added the stale label Jul 12, 2023
@linghengqian
Copy link
Member

@linghengqian linghengqian self-assigned this Sep 28, 2023
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

4 participants