luckleemon opened a new issue #8309:
URL: https://github.com/apache/shardingsphere/issues/8309


   I have read the guide documentation you supply,but i still have no idea with 
how to configurate it,when i want
   to use the self implement sharding algorithm.
   
   for example:
   type: INLINE
   props:
   algorithm-expression: t_user_${id % 2}
   if i want use self implement sharding algorithm, how to configurate 
above.and i have put my jar into lib directory。
   
   
   this is part of my sharding algorithm code
   
   public class DatePreciseShardingAlgorithm implements 
PreciseShardingAlgorithm<String> {
   
        private static Logger logger = 
LoggerFactory.getLogger(DatePreciseShardingAlgorithm.class);
   
        private static DateTimeFormatter sdf = 
DateTimeFormatter.ofPattern("yyyyMM", Locale.CHINA);
        private static final String SEPERATOR = "_";
        private static Date  lowwerDate = null;
   
        @Override
        public String doSharding(Collection<String> availableTargetNames, 
PreciseShardingValue<String> shardingValue) {
                String loginTableName = shardingValue.getLogicTableName();
                logger.info("logicTableName===={}",loginTableName);
                String value = shardingValue.getValue();
                Date createTime = null;
                try {
                        createTime = new 
SimpleDateFormat("yyyy-MM-dd").parse(value);
                } catch (ParseException e) {
                
                }
   
                if(createTime == null){
                        return loginTableName;
                }
                String yyyyMM = "";
                try{
                        yyyyMM =SEPERATOR+ 
createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate().format(sdf);
                        return loginTableName+yyyyMM;
                }catch(Exception e){
                }
                return loginTableName;
        }
   
   and the code works well, in shardingsphere4.
   
   thank you very much.
   
   hope your reply.


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to