Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use SHARDING ALGORITHM Type: INTERVAL two database? #33635

Open
lvqibin123 opened this issue Nov 13, 2024 · 5 comments · May be fixed by #33653
Open

how to use SHARDING ALGORITHM Type: INTERVAL two database? #33635

lvqibin123 opened this issue Nov 13, 2024 · 5 comments · May be fixed by #33653

Comments

@lvqibin123
Copy link

how to use SHARDING ALGORITHM Type: INTERVAL two database?

app_user: actualDataNodes: <INTERVAL>P=ds0.app_user_;SP=yyyyMM;DIA=1;DIU=Months;DL=202401;DU=202412 # 配置分表策略 tableStrategy: standard: shardingColumn: updatetime shardingAlgorithmName: app_user_table_inline keyGenerateStrategy: column: id keyGeneratorName: snowflake
it work,but i have 2 database,I don't know how to configure it.
I have tried the following configurations, but none of them work:

P=ds0.app_user_;SP=yyyyMM;DIA=1;DIU=Months;DL=202401;DU=202412 ,P=ds1.app_user_;SP=yyyyMM;DIA=1;DIU=Months;DL=202401;DU=202412

P=ds${0..1}.app_user_;SP=yyyyMM;DIA=1;DIU=Months;DL=202401;DU=202412

Canonly be used for a single database?

@linghengqian
Copy link
Member

@lvqibin123
Copy link
Author

how to use SHARDING ALGORITHM Type: INTERVAL two database?

      app_user:
        actualDataNodes: <INTERVAL>P=ds0.app_user_;SP=yyyyMM;DIA=1;DIU=Months;DL=202401;DU=202412 
        tableStrategy:
          standard:
            shardingColumn: updatetime
            shardingAlgorithmName: app_user_table_inline
        keyGenerateStrategy:
          column: id
          keyGeneratorName: snowflake

it work,but i have 2 database,I don't know how to configure it.
I have tried the following configurations, but none of them work:

<INTERVAL>P=ds0.app_user_;SP=yyyyMM;DIA=1;DIU=Months;DL=202401;DU=202412,<INTERVAL>P=ds1.app_user_;SP=yyyyMM;DIA=1;DIU=Months;DL=202401;DU=202412
<INTERVAL>P=ds${0..1}.app_user_;SP=yyyyMM;DIA=1;DIU=Months;DL=202401;DU=202412 

Canonly be used for a single database?

@linghengqian
Copy link
Member

  • I'm actually the original author of the Row-Value expression implementation of INTERVAL. The relevant SPI has nothing to do with the sharding algorithm, which is the SPI for Row-Value expression. See https://shardingsphere.apache.org/document/current/cn/user-manual/common-config/builtin-algorithm/expr/ .
  • The logic of INTERVAL is located in org.apache.shardingsphere.infra.expr.interval.IntervalInlineExpressionParser, which is actually an extraction of the logic in an overly complex unit test, and that unit test only involves a single database. You can get a general understanding of what this unit test is from https://www.yuque.com/linghengqian/meve2v/cgi5en .
  • I would say that this SPI implementation class was indeed not originally designed with multiple databases in mind.
  • But then again, you can always create your own SPI implementation class of org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser to generate a java.util.List<String> from some more complex business logic, including connecting to a redis server to get a java.util.List<String>.
  • LITERAL, INTERVAL and GROOVY are always available. I personally do not recommend using ESPRESSO at the current point in time, as ESPRESSO is involved in multiple issues with the GraalVM community.

@lvqibin123
Copy link
Author

Thank you very much!

@linghengqian
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants