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 2021/01/31 17:02:03 UTC

[GitHub] [shardingsphere] jackyLqq opened a new pull request #9239: sql hint

jackyLqq opened a new pull request #9239:
URL: https://github.com/apache/shardingsphere/pull/9239


   Fixes #9235.
   
   Changes proposed in this pull request:
   - Sql database hint by comment,only support DQL Sql of mysql
   - Sql sharding hint by comment,only support DQL Sql of mysql
   - Single-line comments are not supported like /* */,
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere] jackyLqq commented on a change in pull request #9239: sql hint

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



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLFormatTest.java
##########
@@ -117,7 +117,7 @@
                 + "FROM t_order\n"
                 + "WHERE \n"
                 + "\torder_id = 1;"});
-        testUnits.add(new String[]{"only_comment", "/* c_zz_xdba_test_4 login */", ""});
+        // testUnits.add(new String[]{"only_comment", "/* c_zz_xdba_test_4 login */", ""});

Review comment:
       @jingshanglu single-line comments are not supported like /* */   because of sharding hint,Do you have any other hint parse solutions




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere] jackyLqq commented on pull request #9239: sql hint

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


   > @jackyLqq Can you add a test case for `hint`?
   
   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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] jackyLqq commented on a change in pull request #9239: sql hint

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



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select-comment.xml
##########
@@ -17,6 +17,6 @@
   -->
 
 <sql-cases>
-    <sql-case id="select_with_block_comment" value="SELECT * /* this is &#x000D;&#x000A; block comment */ FROM /* this is another &#x000A; block comment */ t_order where status='1'" db-types="MySQL" />
+   <!-- <sql-case id="select_with_block_comment" value="SELECT * /* this is &#x000D;&#x000A; block comment */ FROM /* this is another &#x000A; block comment */ t_order where status='1'" db-types="MySQL" />-->

Review comment:
       @jingshanglu The single-line comment like  /* */ conflicts with the syntax implied by the sharding hint, and I did not find a solution.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere] jackyLqq commented on pull request #9239: sql hint

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






----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere] jingshanglu commented on pull request #9239: sql hint

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


   @jackyLqq Can you add a test case for `hint`?


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere] jackyLqq commented on a change in pull request #9239: sql hint

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



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
##########
@@ -237,6 +237,31 @@ withClause
     : WITH RECURSIVE? cteClause (COMMA_ cteClause)*
     ;
 
+hintComment
+    : SLASH_ ASTERISK_ NOT_ (databaseHintComment| shardingHintComment) ASTERISK_ SLASH_
+    ;
+
+databaseHintComment
+    : DATABASESHARDING LP_ identifier RP_
+    ;
+
+shardingHintComment
+    : shardingDatabaseHintComment? shardingTableHintComment?
+    | shardingTableHintComment? shardingDatabaseHintComment?
+    ;

Review comment:
       sharding table hint and sharding database hint support different order




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere] jingshanglu commented on a change in pull request #9239: sql hint

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



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select-comment.xml
##########
@@ -17,6 +17,6 @@
   -->
 
 <sql-cases>
-    <sql-case id="select_with_block_comment" value="SELECT * /* this is &#x000D;&#x000A; block comment */ FROM /* this is another &#x000A; block comment */ t_order where status='1'" db-types="MySQL" />
+   <!-- <sql-case id="select_with_block_comment" value="SELECT * /* this is &#x000D;&#x000A; block comment */ FROM /* this is another &#x000A; block comment */ t_order where status='1'" db-types="MySQL" />-->

Review comment:
       @jackyLqq Change lexer rule like this,maybe it will solve the problem.
   ```
   BLOCK_COMMENT:  ('/**/' |'/*' ~[!] .*? '*/') -> channel(HIDDEN);
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere] codecov-io commented on pull request #9239: sql hint

Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #9239:
URL: https://github.com/apache/shardingsphere/pull/9239#issuecomment-772652941


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/9239?src=pr&el=h1) Report
   > Merging [#9239](https://codecov.io/gh/apache/shardingsphere/pull/9239?src=pr&el=desc) (946e08d) into [master](https://codecov.io/gh/apache/shardingsphere/commit/12c5f72e88f60feafe663ab39e1d9397d37fefc2?el=desc) (12c5f72) will **decrease** coverage by `2.30%`.
   > The diff coverage is `42.44%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/9239/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so)](https://codecov.io/gh/apache/shardingsphere/pull/9239?src=pr&el=tree)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #9239      +/-   ##
   ============================================
   - Coverage     69.72%   67.41%   -2.31%     
   + Complexity      659      636      -23     
   ============================================
     Files          1649     1652       +3     
     Lines         26664    26994     +330     
     Branches       4638     4743     +105     
   ============================================
   - Hits          18591    18199     -392     
   - Misses         6785     7494     +709     
   - Partials       1288     1301      +13     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/9239?src=pr&el=tree) | Coverage Δ | Complexity Δ | |
   |---|---|---|---|
   | [...gent/core/config/yaml/YamlPluginConfiguration.java](https://codecov.io/gh/apache/shardingsphere/pull/9239/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtYWdlbnQvc2hhcmRpbmdzcGhlcmUtYWdlbnQtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvYWdlbnQvY29yZS9jb25maWcveWFtbC9ZYW1sUGx1Z2luQ29uZmlndXJhdGlvbi5qYXZh) | `0.00% <ø> (ø)` | `0.00 <0.00> (ø)` | |
   | [...re/db/protocol/mysql/constant/MySQLServerInfo.java](https://codecov.io/gh/apache/shardingsphere/pull/9239/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wvc2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wtbXlzcWwvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2RiL3Byb3RvY29sL215c3FsL2NvbnN0YW50L015U1FMU2VydmVySW5mby5qYXZh) | `100.00% <ø> (ø)` | `0.00 <0.00> (ø)` | |
   | [...execute/protocol/MySQLInt4BinaryProtocolValue.java](https://codecov.io/gh/apache/shardingsphere/pull/9239/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wvc2hhcmRpbmdzcGhlcmUtZGItcHJvdG9jb2wtbXlzcWwvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2RiL3Byb3RvY29sL215c3FsL3BhY2tldC9jb21tYW5kL3F1ZXJ5L2JpbmFyeS9leGVjdXRlL3Byb3RvY29sL015U1FMSW50NEJpbmFyeVByb3RvY29sVmFsdWUuamF2YQ==) | `75.00% <0.00%> (-25.00%)` | `1.00 <0.00> (ø)` | |
   | [...dingsphere/distsql/parser/core/DistSQLVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/9239/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZGlzdHNxbC1wYXJzZXIvc2hhcmRpbmdzcGhlcmUtZGlzdHNxbC1wYXJzZXItZW5naW5lL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9kaXN0c3FsL3BhcnNlci9jb3JlL0Rpc3RTUUxWaXNpdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | `0.00 <0.00> (ø)` | |
   | [...e/validator/ShardingStatementValidatorFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/9239/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctcm91dGUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NoYXJkaW5nL3JvdXRlL2VuZ2luZS92YWxpZGF0b3IvU2hhcmRpbmdTdGF0ZW1lbnRWYWxpZGF0b3JGYWN0b3J5LmphdmE=) | `14.81% <0.00%> (-1.19%)` | `0.00 <0.00> (ø)` | |
   | [...g/listener/metadata/DataSourceChangedListener.java](https://codecov.io/gh/apache/shardingsphere/pull/9239/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29yZS9jb25maWcvbGlzdGVuZXIvbWV0YWRhdGEvRGF0YVNvdXJjZUNoYW5nZWRMaXN0ZW5lci5qYXZh) | `23.07% <0.00%> (ø)` | `0.00 <0.00> (ø)` | |
   | [.../config/listener/metadata/RuleChangedListener.java](https://codecov.io/gh/apache/shardingsphere/pull/9239/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29yZS9jb25maWcvbGlzdGVuZXIvbWV0YWRhdGEvUnVsZUNoYW5nZWRMaXN0ZW5lci5qYXZh) | `15.00% <0.00%> (ø)` | `0.00 <0.00> (ø)` | |
   | [.../governance/core/event/model/lock/UnlockEvent.java](https://codecov.io/gh/apache/shardingsphere/pull/9239/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtZ292ZXJuYW5jZS9zaGFyZGluZ3NwaGVyZS1nb3Zlcm5hbmNlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2dvdmVybmFuY2UvY29yZS9ldmVudC9tb2RlbC9sb2NrL1VubG9ja0V2ZW50LmphdmE=) | `0.00% <0.00%> (ø)` | `0.00 <0.00> (?)` | |
   | [...uth/builtin/yaml/config/YamlUserConfiguration.java](https://codecov.io/gh/apache/shardingsphere/pull/9239/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9hdXRoL2J1aWx0aW4veWFtbC9jb25maWcvWWFtbFVzZXJDb25maWd1cmF0aW9uLmphdmE=) | `100.00% <ø> (ø)` | `1.00 <0.00> (ø)` | |
   | [...e/infra/config/datasource/DataSourceValidator.java](https://codecov.io/gh/apache/shardingsphere/pull/9239/diff?src=pr&el=tree#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9jb25maWcvZGF0YXNvdXJjZS9EYXRhU291cmNlVmFsaWRhdG9yLmphdmE=) | `0.00% <0.00%> (ø)` | `0.00 <0.00> (?)` | |
   | ... and [260 more](https://codecov.io/gh/apache/shardingsphere/pull/9239/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/9239?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/9239?src=pr&el=footer). Last update [0840267...946e08d](https://codecov.io/gh/apache/shardingsphere/pull/9239?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere] tristaZero commented on pull request #9239: sql hint

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


   Hi since there is no progress, I have to close it.


-- 
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] jingshanglu commented on a change in pull request #9239: sql hint

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



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/hint/AbstractHintSegment.java
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.sql.parser.sql.common.segment.dml.hint;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
+
+/**
+ * AbstractHintSegment.
+ */
+@RequiredArgsConstructor
+@Getter
+public abstract class AbstractHintSegment implements SQLSegment {
+
+    private final int startIndex;
+
+    private final int stopIndex;
+

Review comment:
       Delete the empty line.

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
##########
@@ -237,6 +237,31 @@ withClause
     : WITH RECURSIVE? cteClause (COMMA_ cteClause)*
     ;
 
+hintComment
+    : SLASH_ ASTERISK_ NOT_ (databaseHintComment| shardingHintComment) ASTERISK_ SLASH_
+    ;
+
+databaseHintComment
+    : DATABASESHARDING LP_ identifier RP_
+    ;
+
+shardingHintComment
+    : shardingDatabaseHintComment? shardingTableHintComment?
+    | shardingTableHintComment? shardingDatabaseHintComment?
+    ;

Review comment:
       @jackyLqq There is a conflict between the two branches.

##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/hint/ShardingHintRoutingEngine.java
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.route.engine.type.hint;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import com.google.common.base.Preconditions;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
+import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.route.context.RouteContext;
+import org.apache.shardingsphere.infra.route.context.RouteMapper;
+import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
+import org.apache.shardingsphere.sharding.route.engine.condition.generator.ConditionValue;
+import org.apache.shardingsphere.sharding.route.engine.condition.value.ListShardingConditionValue;
+import org.apache.shardingsphere.sharding.route.engine.type.ShardingRouteEngine;
+import org.apache.shardingsphere.sharding.route.strategy.ShardingStrategy;
+import org.apache.shardingsphere.sharding.route.strategy.ShardingStrategyFactory;
+import org.apache.shardingsphere.sharding.route.strategy.type.none.NoneShardingStrategy;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sharding.rule.TableRule;
+import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.hint.ShardingHintValueSegment;
+
+/**
+ * ShardingSqlHintRoutingEngine.
+ */
+
+@RequiredArgsConstructor
+public class ShardingHintRoutingEngine implements ShardingRouteEngine {
+
+    private final String logicTableName;
+
+    private final ConfigurationProperties properties;
+
+    private final SelectStatementContext selectStatementContext;
+
+    @Override
+    public void route(final RouteContext routeContext, final ShardingRule shardingRule) {
+        Collection<DataNode> dataNodes = getDataNodes(shardingRule, shardingRule.getTableRule(logicTableName), selectStatementContext);
+        for (DataNode each : dataNodes) {
+            routeContext.getRouteUnits().add(
+                    new RouteUnit(new RouteMapper(each.getDataSourceName(), each.getDataSourceName()), Collections.singletonList(new RouteMapper(logicTableName, each.getTableName()))));
+        }
+
+    }
+
+    private Collection<DataNode> route(final TableRule tableRule, final ShardingStrategy databaseShardingStrategy, final ShardingHintValueSegment shardingDatabaseHintValueSegment,
+                                       final ShardingStrategy tableShardingStrategy, final ShardingHintValueSegment shardingTableHintValueSegment) {
+        Collection<String> routedDataSources = routeDataSourcesByHint(tableRule, databaseShardingStrategy, shardingDatabaseHintValueSegment);
+        Collection<DataNode> result = new LinkedList<>();
+        for (String each : routedDataSources) {
+            result.addAll(routeTablesByHint(tableRule, each, tableShardingStrategy, shardingTableHintValueSegment));
+        }
+        return result;
+    }
+
+    private Collection<DataNode> getDataNodes(final ShardingRule shardingRule, final TableRule tableRule, final SelectStatementContext selectStatementContext) {
+        ShardingStrategy databaseShardingStrategy = createShardingStrategy(shardingRule.getDatabaseShardingStrategyConfiguration(tableRule), shardingRule.getShardingAlgorithms());
+        ShardingStrategy tableShardingStrategy = createShardingStrategy(shardingRule.getTableShardingStrategyConfiguration(tableRule), shardingRule.getShardingAlgorithms());
+        return route(tableRule, databaseShardingStrategy, selectStatementContext.getHintContext().getShardingHintSegment().getShardingDatabaseHintValueSegment(),
+                tableShardingStrategy, selectStatementContext.getHintContext().getShardingHintSegment().getShardingTableHintValueSegment());
+    }
+
+    private Collection<String> routeDataSourcesByHint(final TableRule tableRule, final ShardingStrategy databaseShardingStrategy, final ShardingHintValueSegment shardingDatabaseHintValueSegment) {
+        Collection<String> datasourceNames = tableRule.getActualDatasourceNames();
+        if (shardingDatabaseHintValueSegment != null) {
+            List<ExpressionSegment> databaseHintValueSegmentValues = shardingDatabaseHintValueSegment.getValues();
+            ListShardingConditionValue<Comparable<?>> listShardingValue = getListShardingValueFromHint(databaseHintValueSegmentValues, databaseShardingStrategy);
+            datasourceNames = new LinkedHashSet<>(databaseShardingStrategy.doSharding(datasourceNames, Collections.singletonList(listShardingValue), properties));
+        } 
+        Preconditions.checkState(!datasourceNames.isEmpty(), "no database route info");
+        Preconditions.checkState(tableRule.getActualDatasourceNames().containsAll(datasourceNames),
+                "Some routed data sources do not belong to configured data sources. routed data sources: `%s`, configured data sources: `%s`", datasourceNames, tableRule.getActualDatasourceNames());
+        return datasourceNames;
+    }
+
+    private ListShardingConditionValue<Comparable<?>> getListShardingValueFromHint(final List<ExpressionSegment> databaseHintValueSegmentValues, final ShardingStrategy shardingStrategy) {
+        Collection<Comparable<?>> shardingConditionValues = new LinkedHashSet<>();
+        for (ExpressionSegment expressionSegment : databaseHintValueSegmentValues) {
+            new ConditionValue(expressionSegment, Collections.emptyList()).getValue().ifPresent(shardingConditionValues::add);
+        }
+        return new ListShardingConditionValue<>(shardingStrategy.getShardingColumns().iterator().next(), logicTableName, shardingConditionValues);
+    }
+
+    private Collection<? extends DataNode> routeTablesByHint(final TableRule tableRule, final String routedDataSource,
+                                                             final ShardingStrategy tableShardingStrategy, final ShardingHintValueSegment shardingTableHintValueSegment) {
+        Collection<String> availableTargetTables = tableRule.getActualTableNames(routedDataSource);
+        if (shardingTableHintValueSegment != null) {
+            ListShardingConditionValue<Comparable<?>> listShardingValue = getListShardingValueFromHint(shardingTableHintValueSegment.getValues(), tableShardingStrategy);
+            availableTargetTables = tableShardingStrategy.doSharding(availableTargetTables, Collections.singletonList(listShardingValue), properties);
+        }
+        Collection<DataNode> result = new LinkedList<>();
+        for (String each : availableTargetTables) {
+            result.add(new DataNode(routedDataSource, each));
+        }
+        return result;
+    }
+
+    private ShardingStrategy createShardingStrategy(final ShardingStrategyConfiguration shardingStrategyConfig, final Map<String, ShardingAlgorithm> shardingAlgorithms) {
+        return null == shardingStrategyConfig ? new NoneShardingStrategy()
+                : ShardingStrategyFactory.newInstance(shardingStrategyConfig, shardingAlgorithms.get(shardingStrategyConfig.getShardingAlgorithmName()));
+    }
+

Review comment:
       Plz delete the empty line.

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLFormatTest.java
##########
@@ -117,7 +117,7 @@
                 + "FROM t_order\n"
                 + "WHERE \n"
                 + "\torder_id = 1;"});
-        testUnits.add(new String[]{"only_comment", "/* c_zz_xdba_test_4 login */", ""});
+        // testUnits.add(new String[]{"only_comment", "/* c_zz_xdba_test_4 login */", ""});

Review comment:
       why delete the case?

##########
File path: shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/hint/HintContextEngineTest.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.infra.binder.segment.select.hint;
+
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.hint.DataBaseHintSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.hint.HintSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.hint.ShardingHintSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.hint.ShardingHintValueSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * HintContextEngineTest.
+ */
+public final class HintContextEngineTest {
+
+    @Test
+    public void testCreateHintContextForCommonSql() {
+        HintContext hintContext = new HintContextEngine().createHintContext(new MySQLSelectStatement());
+        Assert.assertEquals(HintType.NONE, hintContext.getHintType());
+    }
+
+    @Test
+    public void testCreateHintContextForDataBaseHint() {
+        MySQLSelectStatement mySQLSelectStatement = new MySQLSelectStatement();
+        mySQLSelectStatement.setHint(new HintSegment(0, 52, new DataBaseHintSegment(3, 50, new IdentifierValue("ds_0"))));
+        HintContext hintContext = new HintContextEngine().createHintContext(mySQLSelectStatement);
+        Assert.assertEquals(HintType.DATABASE_HINT, hintContext.getHintType());
+    }
+
+    @Test
+    public void testCreateHintContextForShardingValueHint() {
+        ShardingHintValueSegment shardingDatabaseHintValueSegment = new ShardingHintValueSegment(10, 50);
+        shardingDatabaseHintValueSegment.getValues().add(new LiteralExpressionSegment(20, 40, 1));
+        ShardingHintValueSegment shardingTableHintValueSegment = new ShardingHintValueSegment(50, 90);
+        shardingTableHintValueSegment.getValues().add(new LiteralExpressionSegment(60, 80, 1));
+        ShardingHintSegment shardingHintSegment = new ShardingHintSegment(10, 90);
+        shardingHintSegment.setShardingDatabaseHintValueSegment(shardingDatabaseHintValueSegment);
+        shardingHintSegment.setShardingTableHintValueSegment(shardingTableHintValueSegment);
+        MySQLSelectStatement mySQLSelectStatement = new MySQLSelectStatement();
+        mySQLSelectStatement.setHint(new HintSegment(0, 100, shardingHintSegment));
+        HintContext hintContext = new HintContextEngine().createHintContext(mySQLSelectStatement);
+        Assert.assertEquals(HintType.SHARDING_HINT, hintContext.getHintType());
+    }
+    

Review comment:
       Plz delete the empty line.

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select-comment.xml
##########
@@ -17,6 +17,6 @@
   -->
 
 <sql-cases>
-    <sql-case id="select_with_block_comment" value="SELECT * /* this is &#x000D;&#x000A; block comment */ FROM /* this is another &#x000A; block comment */ t_order where status='1'" db-types="MySQL" />
+   <!-- <sql-case id="select_with_block_comment" value="SELECT * /* this is &#x000D;&#x000A; block comment */ FROM /* this is another &#x000A; block comment */ t_order where status='1'" db-types="MySQL" />-->

Review comment:
       We should not delete exist test case.

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/Keyword.g4
##########
@@ -115,3 +115,15 @@ INNODB
 REDO_LOG
     : 'REDO_LOG'
     ;
+
+DATABASESHARDING
+    : D A T A B A S E S H A R D I N G
+    ;
+
+SHARDINGDATABASEVALUE
+    : S H A R D I N G D A T A B A S E V A L U E
+    ;
+
+SHARDINGTABLEVALUE
+    : S H A R D I N G T A B L E V A L U E
+    ;

Review comment:
       A blank line is required at the end of the file.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere] jackyLqq removed a comment on pull request #9239: sql hint

Posted by GitBox <gi...@apache.org>.
jackyLqq removed a comment on pull request #9239:
URL: https://github.com/apache/shardingsphere/pull/9239#issuecomment-770557322


   > @jackyLqq Can you add a test case for `hint`?
   SelectStatementContext.java add hintContext parameter  affect a large number of test cases,this is why I did not add test cases,
   I will provide examples in the example project
   
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere] tristaZero commented on pull request #9239: sql hint

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


   @jackyLqq Hi what's going on with this PR? Do U want to continue or close it?


-- 
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] tristaZero closed pull request #9239: sql hint

Posted by GitBox <gi...@apache.org>.
tristaZero closed pull request #9239:
URL: https://github.com/apache/shardingsphere/pull/9239


   


-- 
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] jackyLqq commented on a change in pull request #9239: sql hint

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



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/select-comment.xml
##########
@@ -17,6 +17,6 @@
   -->
 
 <sql-cases>
-    <sql-case id="select_with_block_comment" value="SELECT * /* this is &#x000D;&#x000A; block comment */ FROM /* this is another &#x000A; block comment */ t_order where status='1'" db-types="MySQL" />
+   <!-- <sql-case id="select_with_block_comment" value="SELECT * /* this is &#x000D;&#x000A; block comment */ FROM /* this is another &#x000A; block comment */ t_order where status='1'" db-types="MySQL" />-->

Review comment:
       @jingshanglu 
   
   > @jackyLqq Change lexer rule like this,maybe it will solve the problem.
   > 
   > ```
   > BLOCK_COMMENT:  ('/**/' |'/*' ~[!] .*? '*/') -> channel(HIDDEN);
   > ```
   
    hint commment not be parsed




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [shardingsphere] jackyLqq commented on a change in pull request #9239: sql hint

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



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
##########
@@ -237,6 +237,31 @@ withClause
     : WITH RECURSIVE? cteClause (COMMA_ cteClause)*
     ;
 
+hintComment
+    : SLASH_ ASTERISK_ NOT_ (databaseHintComment| shardingHintComment) ASTERISK_ SLASH_
+    ;
+
+databaseHintComment
+    : DATABASESHARDING LP_ identifier RP_
+    ;
+
+shardingHintComment
+    : shardingDatabaseHintComment? shardingTableHintComment?
+    | shardingTableHintComment? shardingDatabaseHintComment?
+    ;

Review comment:
       @jingshanglu  sharding table hint and sharding database hint support different order




----------------------------------------------------------------
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:
users@infra.apache.org