Sharding error when inserting data into ShardingSphere-Proxy with AlloyDB
I am using ShardingSphere-Proxy with AlloyDB and I am facing an error when trying to insert data into the ni_contribuinte
table.
Error when executing an INSERT
:
rtc_db_des_aa=> INSERT INTO identifier(identifier) VALUES ('1a2b3c4d5e');
ERROR: Inline sharding algorithms expression 'shard_${(abs(identifier.hashCode())) % 5}' and sharding column 'identifier' do not match.
My table schema is as follows:
Table "identifier" {
"identifier" "character varying(14)" [pk, not null]
}
And my ShardingSphere configuration is as follows:
databaseName: rtc_db_des_aa
dataSources:
shard_0:
url: jdbc:postgresql://10.0.0.2:5432/rtc_db_des_aa
username: postgres
password: "pass"
shard_1:
url: jdbc:postgresql://10.0.0.7:5432/rtc_db_des_aa
username: postgres
password: "pass"
shard_2:
url: jdbc:postgresql://10.0.0.8:5432/rtc_db_des_aa
username: postgres
password: "pass"
shard_3:
url: jdbc:postgresql://10.0.0.9:5432/rtc_db_des_aa
username: postgres
password: "pass"
shard_4:
url: jdbc:postgresql://10.0.0.10:5432/rtc_db_des_aa
username: postgres
password: "pass"
rules:
- !SHARDING
tables:
identifier:
actualDataNodes: shard_${0..4}.identifier
tableStrategy:
standard:
shardingColumn: identifier
shardingAlgorithmName: hash_inline
shardingAlgorithms:
hash_inline:
type: INLINE
props:
sharding-count: 5
algorithm-expression: shard_${(abs(identifier.hashCode())) % 5}
From the error, it seems that the sharding expression is not being applied correctly to the ni_contribuinte
column. What could be causing this?
I have already tried:
- Making sure that the
identifier
column is correctly set tocharacter varying(14)
. - Testing other sharding expressions, but I still get the same error.
Could someone help me understand what the problem might be?
- List item