proxy-5.0.0 分库分表插入数据报错
使用环境:
5.7.28-log-ShardingSphere-Proxy 5.0.0
场景、问题:
字符串截取
algorithm-expression: "${'2021-10-01'[0..3]}"
报错 [C1997][1997] Runtime exception: [Cannot invoke method getAt() on null object]
字符串转数字
algorithm-expression: "${'4'.toInteger() % 2}"
报错 [C1997][1997] Runtime exception: [Cannot invoke method toInteger() on null object]
现状:
当前配置
schemaName: sharding_db
dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useSSL=false
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
ds_1:
url: jdbc:mysql://127.0.0.1:3306/test_2?serverTimezone=UTC&useSSL=false
username: root
password: root
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
rules:
- !SHARDING
tables:
od_orderdetails:
actualDataNodes: ds_0.od_orderdetails_${[2021]}, ds_1.od_orderdetails_${[2020,2022,2023]}
databaseStrategy:
standard:
shardingColumn: CreateTime
shardingAlgorithmName: od_orderdetails_database
tableStrategy:
standard:
shardingColumn: CreateTime
shardingAlgorithmName: od_orderdetails_table
# 默认数据库分片策略
defaultDatabaseStrategy:
hint:
shardingAlgorithmName: default_database
# 默认表分片策略
defaultTableStrategy:
none:
# 默认键生成策略
defaultKeyGenerateStrategy:
column: KeyID
keyGeneratorName: uuid
# 分片算法配置
shardingAlgorithms:
default_database:
type: HINT_INLINE
props:
algorithm-expression: "ds_0"
od_orderdetails_database:
type: INLINE
props:
algorithm-expression: "ds_${CreateTime[0..3] == '2021' ? '0' : '1'}"
od_orderdetails_table:
type: INLINE
props:
algorithm-expression: "od_orderdetails_${CreateTime[0..3]}"
# 分布式序列算法配置
keyGenerators:
uuid:
type: UUID