shubham-18-paytm opened a new issue, #35077:
URL: https://github.com/apache/shardingsphere/issues/35077

   ## Question
   
   **For English only**, other languages will not accept.
   
   Before asking a question, make sure you have:
   
   - Googled your question.
   - Searched open and closed [GitHub 
issues](https://github.com/apache/shardingsphere/issues).
   - Read documentation: [ShardingSphere 
Doc](https://shardingsphere.apache.org/document/current/en/overview).
   
   Please pay attention on issues you submitted, because we maybe need more 
details. 
   If no response anymore and we cannot reproduce it on current information, we 
will **close it**.
   
   Dear Team,
   
   I am encountering an issue in my codebase after upgrading from 
ShardingSphere Spring Boot Starter 4.1.1 to shardingsphere-jdbc 5.5.1 .
   
   Currently, my codebase supports both partitioned and non-partitioned 
databases. My data objects are common for both database types. Previously, this 
setup was functioning correctly.
   
   Now, when a request needs to be routed to the partitioned database, and I 
have a getter method for `partition_date` in my data object (without explicitly 
mentioning the field i.e virtual field), Shardingsphere seems to be validating 
data object  against the table structure of the actual data nodes. 
Consequently, it fails to locate the `partition_date` column in the 
non-partitioned database `db0` and throws an error.
   
   However, I do not want this validation to occur. I want the process to 
continue as before, because my HintShardingAlgorithm Implementation is already 
responsible for selecting the correct database and executing queries on the 
appropriate database.
   
   Is there a way to disable this validation behavior? My code was working 
perfectly fine with ShardingSphere Spring Boot Starter version 4.1.1.
   
   actualDataNodes: 
db$->{0..1}.req_unique_$->{0..2},dbp$->{0..1}.req_unique_$->{0..1}
   The problem is before even checking the correct db node in 
DbComplexShardingAlgorithm HintAlgorithm implementation the code is breaking 
due to some pre validations of  table meta data and I am getting exception
   ```
   Error preparing statement.  Cause: 
org.apache.shardingsphere.infra.exception.kernel.metadata.ColumnNotFoundException:
 Unknown column 'partition_date' in 'field list'.
   ```
   
   if i switch the order of db nodes like 
   actualDataNodes: 
dbp$->{0..1}.req_unique_$->{0..1},db$->{0..1}.req_unique_$->{0..2}
   
   Then partitioned request works fine but non partitioned request fails  with 
exception
   ```
   ### Cause: java.sql.SQLException: Field 'partition_date' doesn't have a 
default value
   ; Field 'partition_date' doesn't have a default value
   
   ```
   from above i can conclude that shardingsphere tries validating dataObjects 
with the whichever the first datanode i provide in actualDataNodes configuration
   Any insights or suggestions on how to resolve this issue would be greatly 
appreciated.
   
   Thanks
   
   DataObject Sample 
   
   `
   @Data
   @Alias("req_unique")
   @Getter
   @Setter
   public class RequestUniqueDO {
       private String requestId;
       private String orderId;
   
       /**
        * This method is used for partitioning logic and should not be mapped 
to any database column.
        * It's used by the sharding algorithm to determine the correct database 
and table.
        */
       public Date getPartitionDate() {
           return Utils.composePartitionDate(this.orderId);
       }
   
       // Override the setter to prevent any database mapping
       public void setPartitionDate(Date partitionDate) {
           // No-op - this is a computed field
       }
   }
   `
   
   Jdbc yaml config for the table
   `
   rules:
     - !SHARDING
       tables:
         req_unique:
           actualDataNodes: 
db$->{0..1}.req_unique_$->{0..2},dbp$->{0..1}.req_unique_$->{0..1}
           databaseStrategy:
             hint:
               shardingAlgorithmName: db_complex_sharding_algorithm
           tableStrategy:
             hint:
               shardingAlgorithmName: req_unique_sharding_algorithm
   
   
       shardingAlgorithms:
         db_complex_sharding_algorithm:
           type: CLASS_BASED
           props:
             strategy: HINT
             algorithmClassName: com.shubh.shards.DBComplexShardingAlgorithm
   `
   
   DBComplexShardingAlgorithm
   
   `
   public class DBComplexShardingAlgorithm 
           implements HintShardingAlgorithm<String> {
   
       private static final String PARTITION_SUPPORTED_DBSHARD_NAME = "dbp";
       private final String DB_NAME = "db";
   
       @Override
       public Collection<String> doSharding(Collection<String> availableTargets,
                                            HintShardingValue<String> 
hintShardingValue) {
   
           List<String> shardingResult = new ArrayList<>();
           Collection<String> values = hintShardingValue.getValues();
           if (values.isEmpty()) {
               return availableTargets;
           }
   
           String orderId = values.iterator().next();
   
           String sharding;
   
           if(PARTITIONED_ENABLED){
                   sharding = getPartitionedShard(orderId);
             }
            else{
                   sharding = getShardingDb(orderId);
            }
     
   
           shardingResult.add(sharding);
           return shardingResult;
       }
   
       public String getPartitionedShard(String shardingId) {
   
           int dbShard = Integer.parseInt(shardingId.substring(2, 4)) %10;
           return PARTITION_SUPPORTED_DBSHARD_NAME + dbShard; // eg dbp0, 
dbp1... dbp9
       }
   
       public String getNonPartitionedShard(String shardingId) {
   
           int dbShard = Integer.parseInt(shardingId.substring(2,4)) % 25;
           return DB_NAME + dbShard; // eg. db0,db1...db24
       }
   }
   `


-- 
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-unsubscr...@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to