lanchengx commented on a change in pull request #14102:
URL: https://github.com/apache/shardingsphere/pull/14102#discussion_r771126339



##########
File path: 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingKeyGeneratorsQueryResultSet.java
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.config.algorithm.ShardingSphereAlgorithmConfiguration;
+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.ShowShardingKeyGeneratorsStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * Result set for show sharding key generators.
+ */
+public final class ShardingKeyGeneratorsQueryResultSet implements 
DistSQLResultSet {
+
+    private static final String NAME = "name";
+
+    private static final String TYPE = "type";
+
+    private static final String PROPS = "props";
+
+    private Iterator<Entry<String, ShardingSphereAlgorithmConfiguration>> data 
= Collections.emptyIterator();
+
+    @Override
+    public void init(final ShardingSphereMetaData metaData, final SQLStatement 
sqlStatement) {
+

Review comment:
       Redundant blank line

##########
File path: 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShardingKeyGeneratorsQueryResultSetTest.java
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.query;
+
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.distsql.handler.query.ShardingKeyGeneratorsQueryResultSet;
+import 
org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingKeyGeneratorsStatement;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class ShardingKeyGeneratorsQueryResultSetTest {
+
+    @Test
+    public void assertGetRowData() {
+        ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, 
RETURNS_DEEP_STUBS);
+        
when(metaData.getRuleMetaData().getConfigurations()).thenReturn(createRuleConfigurations());
+        ShardingKeyGeneratorsQueryResultSet resultSet = new 
ShardingKeyGeneratorsQueryResultSet();
+        resultSet.init(metaData, 
mock(ShowShardingKeyGeneratorsStatement.class));
+        List<Object> actual = new ArrayList<>(resultSet.getRowData());
+        assertThat(actual.size(), is(3));
+        assertThat(actual.get(0), is("snowflake"));
+        assertThat(actual.get(1), is("SNOWFLAKE"));
+        assertThat(actual.get(2).toString(), is("{work-id=123}"));
+    }
+
+    private Collection<RuleConfiguration> createRuleConfigurations() {
+        ShardingRuleConfiguration result = new ShardingRuleConfiguration();
+        Properties props = new Properties();
+        props.put("work-id", 123);
+        result.getKeyGenerators().put("snowflake", new 
ShardingSphereAlgorithmConfiguration("SNOWFLAKE", props));
+        return Collections.singleton(result);
+    }
+

Review comment:
       Redundant blank line

##########
File path: 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
##########
@@ -365,4 +367,11 @@ public ASTNode visitAlterShardingKeyGenerator(final 
AlterShardingKeyGeneratorCon
     private ShardingKeyGeneratorSegment buildShardingKeyGeneratorSegment(final 
KeyGeneratorDefinationContext ctx) {
         return new 
ShardingKeyGeneratorSegment(getIdentifierValue(ctx.keyGeneratorName()), 
(AlgorithmSegment) visitAlgorithmDefinition(ctx.algorithmDefinition()));
     }
+
+    @Override
+    public ASTNode visitShowShardingKeyGenerators(final 
ShardingDistSQLStatementParser.ShowShardingKeyGeneratorsContext ctx) {
+        return new 
ShowShardingKeyGeneratorsStatement(Objects.nonNull(ctx.schemaName())
+                ? (SchemaSegment) visit(ctx.schemaName()) : null);
+    }
+

Review comment:
       Redundant blank line

##########
File path: 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/antlr4/imports/sharding/ShardingDistSQLStatement.g4
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+grammar ShardingDistSQLStatement;
+
+import Symbol, RALStatement, RDLStatement, RQLStatement;
+
+execute
+    : (createShardingTableRule
+    | createDefaultShardingStrategy
+    | createShardingBindingTableRules
+    | createShardingBroadcastTableRules
+    | alterShardingTableRule
+    | alterShardingBindingTableRules
+    | alterShardingBroadcastTableRules
+    | dropShardingTableRule
+    | dropShardingBindingTableRules
+    | dropShardingBroadcastTableRules
+    | dropShardingAlgorithm
+    | showShardingTableRules
+    | showShardingBindingTableRules
+    | showShardingBroadcastTableRules
+    | showShardingAlgorithms
+    | setShardingHintDatabaseValue
+    | addShardingHintDatabaseValue
+    | addShardingHintTableValue
+    | showShardingHintStatus
+    | clearShardingHint
+    | createShardingAlgorithm
+    | alterShardingAlgorithm
+    | showShardingTableNodes
+    | createShardingKeyGenerator
+    | alterShardingKeyGenerator
+    | showShardingKeyGenerators
+    ) SEMI?
+    ;

Review comment:
        Shouldn't be added, it's the same as
   
`src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShardingDistSQLStatement.g4`
 same

##########
File path: 
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowShardingKeyGeneratorsStatementAssert.java
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.test.sql.parser.parameterized.asserts.statement.distsql.rql.impl.rule;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingKeyGeneratorsStatement;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.distsql.SchemaAssert;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShardingKeyGeneratorsStatementTestCase;
+
+import static org.junit.Assert.assertTrue;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShowShardingKeyGeneratorsStatementAssert {
+
+    public static void assertIs(final SQLCaseAssertContext assertContext, 
final ShowShardingKeyGeneratorsStatement actual,
+                                final 
ShowShardingKeyGeneratorsStatementTestCase expected) {
+        assertTrue(assertContext.getText("Actual schema should exist."), 
actual.getSchema().isPresent());
+        SchemaAssert.assertIs(assertContext, actual.getSchema().get(), 
expected.getSchema());
+    }
+

Review comment:
       Redundant blank line

##########
File path: 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingKeyGeneratorsQueryResultSet.java
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.config.algorithm.ShardingSphereAlgorithmConfiguration;
+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.ShowShardingKeyGeneratorsStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * Result set for show sharding key generators.
+ */
+public final class ShardingKeyGeneratorsQueryResultSet implements 
DistSQLResultSet {
+
+    private static final String NAME = "name";
+
+    private static final String TYPE = "type";
+
+    private static final String PROPS = "props";
+
+    private Iterator<Entry<String, ShardingSphereAlgorithmConfiguration>> data 
= Collections.emptyIterator();
+
+    @Override
+    public void init(final ShardingSphereMetaData metaData, final SQLStatement 
sqlStatement) {
+
+        metaData.getRuleMetaData().getConfigurations().stream()
+                .filter(each -> each instanceof ShardingRuleConfiguration)
+                .map(each -> (ShardingRuleConfiguration) each)
+                .forEach(each -> data = 
each.getKeyGenerators().entrySet().iterator());

Review comment:
       Consider using the  `ShardingSphereRuleMetaData#findRuleConfiguration` 
method

##########
File path: 
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rql/ShowShardingKeyGeneratorsStatementTestCase.java
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql;
+
+import lombok.Getter;
+import lombok.Setter;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.schema.ExpectedSchema;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * Show sharding key generators statement test case.
+ */
+@Getter
+@Setter
+public final class ShowShardingKeyGeneratorsStatementTestCase extends 
SQLParserTestCase {
+
+    @XmlElement
+    private ExpectedSchema schema;
+

Review comment:
       Redundant blank line

##########
File path: 
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowShardingKeyGeneratorsStatementAssert.java
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.test.sql.parser.parameterized.asserts.statement.distsql.rql.impl.rule;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingKeyGeneratorsStatement;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.distsql.SchemaAssert;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShardingKeyGeneratorsStatementTestCase;
+
+import static org.junit.Assert.assertTrue;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShowShardingKeyGeneratorsStatementAssert {
+

Review comment:
       Public methods require javadoc

##########
File path: 
shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
##########
@@ -84,4 +84,4 @@
 #    # if client connections are more than proxy-frontend-netty-executor-size, 
especially executing slow SQL.
 #  proxy-backend-executor-suitable: OLAP
 #  proxy-frontend-max-connections: 0 # Less than or equal to 0 means no 
limitation.
-#  sql-federation-enabled: false
+#  sql-federation-enabled: false

Review comment:
       The file needs a blank line at the end




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