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

proxy write 'CREATE SHARDING TABLE RULE' #32832

Closed
hongbofan opened this issue Sep 12, 2024 · 7 comments
Closed

proxy write 'CREATE SHARDING TABLE RULE' #32832

hongbofan opened this issue Sep 12, 2024 · 7 comments

Comments

@hongbofan
Copy link

Question

first put the jar to /lib
then
CREATE SHARDING TABLE RULE test_table(
STORAGE_UNITS(ds0),
SHARDING_COLUMNS=product_source,creation_date,
TYPE(NAME="SOURCE_DATE_COMPLEX",PROPERTIES("defTable"="test_table","sources"="mall,customer","strategy"="COMPLEX","algorithmClassName"="com.qx.agg.client.sharding.SourceDateComplexShardingAlgorithm")),
KEY_GENERATE_STRATEGY(COLUMN=media_id,TYPE(NAME="snowflake"))
);

'SOURCE_DATE_COMPLEX' is SourceDateComplexShardingAlgorithm’s type
'com.qx.agg.client.sharding.SourceDateComplexShardingAlgorithm' is my tableAlgorithm
how to write the distSql right?

For English only, other languages will not accept.

Before asking a question, make sure you have:

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.

@RaigorJiang
Copy link
Contributor

@hongbofan
If you want to specify a custom algorithm type "SOURCE_DATE_COMPLEX" in TYPE NAME, you need to make sure your class has been defined in SPI service, refer to ComplexInlineShardingAlgorithm

https://github.com/apache/shardingsphere/blob/master/features/sharding/core/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm

@RaigorJiang
Copy link
Contributor

@hongbofan
If you do not want to add the SPI Services file, you can also specify the full path of the custom algorithm with CLASS BASED type. The following is an example

CREATE SHARDING TABLE RULE t_order (
DATANODES("ds_${0..2}.t_order_${0..3}"),
DATABASE_STRATEGY(TYPE="standard",
SHARDING_COLUMN=order_id,
SHARDING_ALGORITHM(TYPE(NAME="CLASS_BASED",
PROPERTIES(
"strategy"="standard", "algorithmClassName"="com.sphereex.example.fixture.CustomShardingAlgorithm",
"mod-value-length"=5,"mod-count"=3)
))),
TABLE_STRATEGY(TYPE="standard",
SHARDING_COLUMN=order_id,
SHARDING_ALGORITHM(TYPE(NAME="CLASS_BASED",
PROPERTIES(
"strategy"="standard", "algorithmClassName"="com.sphereex.example.fixture.CustomShardingAlgorithm",
"mod-value-length"=5,"mod-count"=4)
)))
);

@hongbofan
Copy link
Author

@hongbofan If you want to specify a custom algorithm type "SOURCE_DATE_COMPLEX" in TYPE NAME, you need to make sure your class has been defined in SPI service, refer to ComplexInlineShardingAlgorithm

https://github.com/apache/shardingsphere/blob/master/features/sharding/core/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm

unpack my jar
get two folders
com/qx/agg/client/sharding/SourceDateComplexShardingAlgorithm.class
META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm

spi.ShardingAlgorithm's context is
com.qx.agg.client.sharding.SourceDateComplexShardingAlgorithm

@hongbofan
Copy link
Author

@hongbofan If you do not want to add the SPI Services file, you can also specify the full path of the custom algorithm with CLASS BASED type. The following is an example

CREATE SHARDING TABLE RULE t_order (
DATANODES("ds_${0..2}.t_order_${0..3}"),
DATABASE_STRATEGY(TYPE="standard",
SHARDING_COLUMN=order_id,
SHARDING_ALGORITHM(TYPE(NAME="CLASS_BASED",
PROPERTIES(
"strategy"="standard", "algorithmClassName"="com.sphereex.example.fixture.CustomShardingAlgorithm",
"mod-value-length"=5,"mod-count"=3)
))),
TABLE_STRATEGY(TYPE="standard",
SHARDING_COLUMN=order_id,
SHARDING_ALGORITHM(TYPE(NAME="CLASS_BASED",
PROPERTIES(
"strategy"="standard", "algorithmClassName"="com.sphereex.example.fixture.CustomShardingAlgorithm",
"mod-value-length"=5,"mod-count"=4)
)))
);

this way i create sharding algorithm,

CREATE SHARDING ALGORITHM source_date_complex (
TYPE(NAME=CLASS_BASED,PROPERTIES("defTable"="o2pcm_multimedia","sources"="mall,customer","strategy"="COMPLEX","algorithmClassName"="com.qx.agg.client.sharding.SourceDateComplexShardingAlgorithm"))
);
get a error message
You have an error in your SQL syntax: no viable alternative at input ‘CREATESHARDING’ near ‘[@2,47:54=‘SHARDING’,<864>,1:47]’ at line 1

@RaigorJiang
Copy link
Contributor

unpack my jar get two folders com/qx/agg/client/sharding/SourceDateComplexShardingAlgorithm.class META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm

spi.ShardingAlgorithm's context is com.qx.agg.client.sharding.SourceDateComplexShardingAlgorithm

It looks correct. Note that this jar needs to be placed under lib before Proxy is started. Next, you need to find the problem locally.

@RaigorJiang
Copy link
Contributor

@hongbofan If you do not want to add the SPI Services file, you can also specify the full path of the custom algorithm with CLASS BASED type. The following is an example

CREATE SHARDING TABLE RULE t_order (
DATANODES("ds_${0..2}.t_order_${0..3}"),
DATABASE_STRATEGY(TYPE="standard",
SHARDING_COLUMN=order_id,
SHARDING_ALGORITHM(TYPE(NAME="CLASS_BASED",
PROPERTIES(
"strategy"="standard", "algorithmClassName"="com.sphereex.example.fixture.CustomShardingAlgorithm",
"mod-value-length"=5,"mod-count"=3)
))),
TABLE_STRATEGY(TYPE="standard",
SHARDING_COLUMN=order_id,
SHARDING_ALGORITHM(TYPE(NAME="CLASS_BASED",
PROPERTIES(
"strategy"="standard", "algorithmClassName"="com.sphereex.example.fixture.CustomShardingAlgorithm",
"mod-value-length"=5,"mod-count"=4)
)))
);

this way i create sharding algorithm,

CREATE SHARDING ALGORITHM source_date_complex ( TYPE(NAME=CLASS_BASED,PROPERTIES("defTable"="o2pcm_multimedia","sources"="mall,customer","strategy"="COMPLEX","algorithmClassName"="com.qx.agg.client.sharding.SourceDateComplexShardingAlgorithm")) ); get a error message You have an error in your SQL syntax: no viable alternative at input ‘CREATESHARDING’ near ‘[@2,47:54=‘SHARDING’,<864>,1:47]’ at line 1

Please use CREATE SHARDING TABLE RULE, there is no syntax of CREATE SHARDING ALGORITHM right now.

Copy link

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

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

No branches or pull requests

3 participants