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/02/21 11:46:51 UTC

[GitHub] [shardingsphere] leedongyang opened a new pull request #15551: Add a syntax SHOW SHARDING TABLE RULES USED ALGORITHM

leedongyang opened a new pull request #15551:
URL: https://github.com/apache/shardingsphere/pull/15551


   Fixes #15168 
   
   Changes proposed in this pull request:
   - add RQL statement
   - add test


-- 
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



[GitHub] [shardingsphere] RaigorJiang commented on pull request #15551: Add a syntax SHOW SHARDING TABLE RULES USED ALGORITHM

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on pull request #15551:
URL: https://github.com/apache/shardingsphere/pull/15551#issuecomment-1050724410


   Thank you @leedongyang , well done!


-- 
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



[GitHub] [shardingsphere] menghaoranss commented on pull request #15551: Add a syntax SHOW SHARDING TABLE RULES USED ALGORITHM

Posted by GitBox <gi...@apache.org>.
menghaoranss commented on pull request #15551:
URL: https://github.com/apache/shardingsphere/pull/15551#issuecomment-1046828680


   @leedongyang some it tests execute failed.


-- 
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



[GitHub] [shardingsphere] RaigorJiang merged pull request #15551: Add a syntax SHOW SHARDING TABLE RULES USED ALGORITHM

Posted by GitBox <gi...@apache.org>.
RaigorJiang merged pull request #15551:
URL: https://github.com/apache/shardingsphere/pull/15551


   


-- 
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



[GitHub] [shardingsphere] RaigorJiang commented on a change in pull request #15551: Add a syntax SHOW SHARDING TABLE RULES USED ALGORITHM

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on a change in pull request #15551:
URL: https://github.com/apache/shardingsphere/pull/15551#discussion_r813579705



##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRulesUsedAlgorithmQueryResultSet.java
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.sharding.distsql.handler.query;
+
+import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingTableRulesUsedAlgorithmStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Result set for show sharding table rules used algorithm.
+ */
+public final class ShardingTableRulesUsedAlgorithmQueryResultSet implements DistSQLResultSet {
+
+    private Iterator<Collection<Object>> data = Collections.emptyIterator();
+
+    @Override
+    public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) {
+        ShowShardingTableRulesUsedAlgorithmStatement statement = (ShowShardingTableRulesUsedAlgorithmStatement) sqlStatement;
+        List<Collection<Object>> result = new ArrayList<>();
+        Collection<ShardingRuleConfiguration> shardingTableRules = metaData.getRuleMetaData().findRuleConfiguration(ShardingRuleConfiguration.class);
+        shardingTableRules.forEach(each -> requireResult(statement, metaData.getName(), result, each));
+        data = result.iterator();
+    }
+
+    private void requireResult(final ShowShardingTableRulesUsedAlgorithmStatement statement, final String schemaName, final List<Collection<Object>> result,
+                               final ShardingRuleConfiguration shardingRuleConfiguration) {
+        if (!statement.getAlgorithmName().isPresent()) {
+            return;
+        }
+        shardingRuleConfiguration.getTables().forEach(each -> {
+            if (null != each.getTableShardingStrategy() && statement.getAlgorithmName().get().equals(each.getTableShardingStrategy().getShardingAlgorithmName())) {

Review comment:
       Hi @leedongyang , `databaseShardingStrategy` also needs to be checked here.




-- 
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