tristaZero commented on a change in pull request #10110:
URL: https://github.com/apache/shardingsphere/pull/10110#discussion_r614693361
##########
File path:
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandlerFactory.java
##########
@@ -91,6 +93,9 @@ private static void checkRegistryCenterExisted(final
SQLStatement sqlStatement)
if (sqlStatement instanceof CreateShardingRuleStatement) {
Review comment:
This branch will be removed later, won't it?
##########
File path:
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/converter/ShardingRuleStatementConverter.java
##########
@@ -46,19 +47,35 @@
* @return YAML sharding rule configuration
*/
public static YamlShardingRuleConfiguration convert(final
CreateShardingRuleStatement sqlStatement) {
+ YamlShardingRuleConfiguration result =
convertTableRuleSegments(sqlStatement.getTables());
+ for (Collection<String> each : sqlStatement.getBindingTables()) {
+ result.getBindingTables().add(Joiner.on(",").join(each));
+ }
+ return result;
+ }
+
+ /**
+ * Convert create sharding table rule statement context to YAML sharding
rule configuration.
+ *
+ * @param sqlStatement create sharding table rule statement
+ * @return YAML sharding rule configuration
+ */
+ public static YamlShardingRuleConfiguration convert(final
CreateShardingTableRuleStatement sqlStatement) {
+ return convertTableRuleSegments(sqlStatement.getTables());
+ }
+
+ private static YamlShardingRuleConfiguration
convertTableRuleSegments(final Collection<TableRuleSegment> tableRuleSegments) {
YamlShardingRuleConfiguration result = new
YamlShardingRuleConfiguration();
- for (TableRuleSegment each : sqlStatement.getTables()) {
+ for (TableRuleSegment each : tableRuleSegments) {
if (null != each.getTableStrategy()) {
result.getShardingAlgorithms().put(getAlgorithmName(each.getLogicTable(),
each.getTableStrategy().getAlgorithmName()),
createAlgorithmConfiguration(each.getTableStrategy()));
result.getAutoTables().put(each.getLogicTable(),
createAutoTableRuleConfiguration(each));
}
}
- for (Collection<String> each : sqlStatement.getBindingTables()) {
- result.getBindingTables().add(Joiner.on(",").join(each));
- }
return result;
}
+
Review comment:
Is this a reductant line? I assume the blank line above is enough.
##########
File path:
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/test/java/org/apache/shardingsphere/distsql/parser/api/DistSQLStatementParserEngineTest.java
##########
@@ -42,6 +44,12 @@
private static final String RDL_DROP_RESOURCE = "DROP RESOURCE ds_0,ds_1";
+ private static final String RDL_CREATE_SHARDING_TABLE_RULE = "CREATE
SHARDING TABLE RULE t_order ("
+ + "RESOURCES(ms_group_0,ms_group_1),"
+ + "SHARDING_COLUMN=order_id,"
+ + "TYPE(NAME=hash_mod,PROPERTIES(\"sharding-count\"=4)),"
Review comment:
'sharding-count' is possible to be used as well, right?
##########
File path:
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandler.java
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
+
+import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateShardingTableRuleStatement;
+import
org.apache.shardingsphere.governance.core.event.model.rule.RuleConfigurationsAlteredEvent;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
+import
org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
+import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
+import
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
+import
org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
+import
org.apache.shardingsphere.sharding.converter.ShardingRuleStatementConverter;
+import
org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * Create sharding table rule backend handler.
+ */
+public final class CreateShardingTableRuleBackendHandler extends
SchemaRequiredBackendHandler<CreateShardingTableRuleStatement> {
+
+ public CreateShardingTableRuleBackendHandler(final
CreateShardingTableRuleStatement sqlStatement, final BackendConnection
backendConnection) {
+ super(sqlStatement, backendConnection);
+ }
+
+ @Override
+ public ResponseHeader execute(final String schemaName, final
CreateShardingTableRuleStatement sqlStatement) {
Review comment:
Do we have any UT for these distsql handlers?
--
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]