i has 2 table in my database : EMPLOYEE and DEPARTMENT like this picture -->
In table EMPLOYEE has column LOCATION and i want to shard this table by LOCATION :
Example : if employee has LOCATION " France " --> shard0 , "USA" --> shard1, "singapore" --> shard2 ....
Here is my code :
Code:
public ShardId getShardId(String _location)
{
int shardId = 0;
if(_location.equalsIgnoreCase("VietNam"))
shardId = 0;
else if(_location.equalsIgnoreCase("Singapore"))
shardId = 1;
else if(_location.equalsIgnoreCase("USA"))
shardId = 2;
else if(_location.equalsIgnoreCase("France"))
shardId = 3;
return new ShardId(shardId);
}
if i shard with 1 table EMPLOYEE , it run successfully, BUT, when i shard it with table DEPARTMENT , it is wrong :(. It doesn't shard by LOCATION.
It return a shard with DEPARTMENT. it mean : if I has 2 employee with different LOCATION and the same ID_DEP (same DEPARTMENT) , if i shard only 1 Table EMPLOYEE by LOCATION, 2 employee will insert into different shard, BUT if i shard with 2 table EMPLOYEE and DEPARTMENT by LOCATION, 2 employee will insert into same shard :((.
Please help me. sr i has bad english :((.