You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/12/23 16:35:39 UTC

[GitHub] [shardingsphere] linghengqian commented on issue #22899: Make actualDataNodes expose SPI that can define expression with custom rules and add GraalVM Truffle implementation

linghengqian commented on issue #22899:
URL: https://github.com/apache/shardingsphere/issues/22899#issuecomment-1364102613

   - For a long time no one gave an opinion. Let me expand on this issue a bit. Considering sharding by date, we should not limit the expression, but directly build an algorithmic SPI.
   ```java
   import org.apache.shardingsphere.infra.util.spi.lifecycle.SPIPostProcessor;
   import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
   import java.util.Properties;
   
   public interface AbstractActualdataNodes extends TypedSPI, SPIPostProcessor {
      /**
        *
        * @return result real table list
        */
      List<String> getActualDataNodes();
   
      /**
        * Get properties.
        *
        * @return properties
        */
       Properties getProps();
   }
   ```
   - We should only consider the `java.util.List` of the final real table. For the simplest case of sharding by date, the configuration of the simplest implementation class using JSR 310 should be similar to the following.
   ```yaml
   rules:
      - !SHARDING
        tables:
          t_order:
            actualDataNodes:
              type: SINGLE_TABLE
              props:
               table-prefix: t_order # The prefix of the real table
               datetime-lower: 2022-10-01 # lower limit of time
               datetime-upper: 2022-12-31 # time upper limit
               datetime-pattern: yyyy-MM-dd # A string conforming to the format of java.time.format.DateTimeFormatter, used to convert datetime-lower and datetime-upper
               table-suffix-pattern: _yyyyMM # The suffix of the real table, also follows the format of java.time.format.DateTimeFormatter
               datetime-interval-amount: 1 # time interval
               datetime-interval-unit: MONTHS # follow java.time.temporal.ChronoUnit
   ```
   - It should end up producing an ArrayList containing `[t_order_202210,t_order_202211,t_order_202212]`.
   - Let's assume a simple function to do this conversion.
   ```java
   import org.junit.jupiter.api.Test;
   
   import java.time.LocalDate;
   import java.time.format.DateTimeFormatter;
   import java.time.temporal.ChronoField;
   import java.time.temporal.ChronoUnit;
   import java.time.temporal.TemporalAccessor;
   import java.util.List;
   import java.util.stream.LongStream;
   
   public class DateTest {
       @Test
       void testDate() {
           DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
           TemporalAccessor start = dateTimeFormatter.parse("2022-10-01");
           TemporalAccessor end = dateTimeFormatter.parse("2022-12-31");
           if (!start.isSupported(ChronoField.NANO_OF_DAY) && start.isSupported(ChronoField.EPOCH_DAY)) {
               LocalDate startTime = start.query(LocalDate::from);
               LocalDate endTime = end.query(LocalDate::from);
               List<String> actualDataNodes = LongStream.range(0, ChronoUnit.MONTHS.between(startTime, endTime.plusMonths(1)))
                       .mapToObj(startTime::plusMonths)
                       .map(localDate -> "t_order" + localDate.format(DateTimeFormatter.ofPattern("_yyyyMM")))
                       .toList();
               assert actualDataNodes.equals(List.of("t_order_202210", "t_order_202211", "t_order_202212"));
           }
       }
   }
   ```


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

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