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/03/25 04:20:27 UTC
[GitHub] [shardingsphere] yx9o commented on a change in pull request #16341: Add more validation to `import` syntax.
yx9o commented on a change in pull request #16341:
URL: https://github.com/apache/shardingsphere/pull/16341#discussion_r834941669
##########
File path: shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/checker/ShardingRuleConfigurationChecker.java
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.ral.common.checker;
+
+import org.apache.shardingsphere.infra.config.TypedSPIConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
+import org.apache.shardingsphere.infra.distsql.exception.resource.RequiredResourceMissedException;
+import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException;
+import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+import org.apache.shardingsphere.sharding.support.InlineExpressionParser;
+import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Sharding rule configuration checker.
+ */
+public final class ShardingRuleConfigurationChecker {
+
+ private static final String SHARDING = "sharding";
+
+ private static final String KEY_GENERATOR = "key generator";
+
+ private static final Map<String, Class<? extends ShardingSphereAlgorithm>> ALGORITHM_TYPE_MAP = new HashMap<>(2, 1);
+
+ static {
+ ALGORITHM_TYPE_MAP.put(SHARDING, ShardingAlgorithm.class);
+ ALGORITHM_TYPE_MAP.put(KEY_GENERATOR, KeyGenerateAlgorithm.class);
+ }
+
+ /**
+ * Check sharding rule configuration.
+ *
+ * @param shardingSphereMetaData ShardingSphere meta data
+ * @param currentRuleConfig current rule configuration
+ * @throws DistSQLException definition violation exception
+ */
+ public void check(final ShardingSphereMetaData shardingSphereMetaData, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException {
+ if (null == shardingSphereMetaData || null == currentRuleConfig) {
+ return;
+ }
+ String schemaName = shardingSphereMetaData.getName();
+ checkLogicTables(schemaName, currentRuleConfig);
+ checkResources(schemaName, shardingSphereMetaData, currentRuleConfig);
+ checkKeyGenerators(currentRuleConfig);
+ checkShardingAlgorithms(currentRuleConfig);
+ }
+
+ private void checkLogicTables(final String schemaName, final ShardingRuleConfiguration currentRuleConfig) throws DistSQLException {
+ LinkedList<String> tablesLogicTables = currentRuleConfig.getTables().stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toCollection(LinkedList::new));
Review comment:
ok.
--
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