lanchengx opened a new issue #13994:
URL: https://github.com/apache/shardingsphere/issues/13994


   `KeyGenerator` is defined as [Distributed Primary 
Key](https://shardingsphere.apache.org/document/current/en/features/sharding/concept/key-generator/)
 in ShardingSphere, and is configured as follows in the Sharding feature:
   
   
![image](https://user-images.githubusercontent.com/52209337/145165511-428b4f7b-6a46-4743-893c-27d99a6e01b2.png)
   
   At present, in the Sharding feature, DistSQL's support for `KeyGenerator` is 
not complete. It is only limited to adding `KeyGenerator` when adding 
`ShardingTableRule`. This method is not friendly enough for `KeyGenerator` 
reuse and property adjustment.
   
   Therefore, in the Sharding feature, DistSQL plans to provide more complete 
support for the `KeyGenerator` property.
   
   The ANTLR definition syntax is as follows:
   
   ```sql
   CREATE SHARDING KEY GENERATOR keyGeneratorDefination (COMMA 
keyGeneratorDefination)*
   
   keyGeneratorDefination: keyGeneratorName LP algorithmDefinition RP;
   keyGeneratorName:IDENTIFIER;
   algorithmDefinition: TYPE LP NAME EQ algorithmName (COMMA PROPERTIES LP 
algorithmProperties? RP)? RP;
   ```
   
   Examples are as follows:
   
   ```sql
   Create Sharding Key Generator 
uuid_key_generator(TYPE(NAME=uuid,PROPERTIES("worker-id"=123)));
   ```
   
   For the specific details of the implementation, please refer to `Sharding 
Algorithm`
   
   The files that may need to be adjusted during the implementation process are 
as follows:
   
   - Revise:
   
     - `src/main/antlr4/imports/sharding/RDLStatement.g4`
     - `src/main/antlr4/imports/sharding/Keyword.g4`
     - `ShardingDistSQLStatement.g4`
     - `ShardingDistSQLStatementVisitor.java`
     - `org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater`
     - `org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet`
     - `src/main/resources/sql/supported/` add test statement to the 
corresponding file
     - `src/main/resources/case/` adds a test case to the corresponding file
     - Add the corresponding `TestCase` in `SQLParserTestCases`
   
   - Add
   
     - `ShardingKeyGeneratorStatement.java` corresponding to the syntax
     - `ShardingKeyGeneratorStatementUpdater.java` corresponding to the syntax
     - `Updater` corresponding unit test
     - `TestCase` class
     - The `Assert` class for verifying test results


-- 
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: [email protected]

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


Reply via email to