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/12/02 10:49:08 UTC
[GitHub] [shardingsphere] tuichenchuxin opened a new pull request #13905: add sql hint for write route only.
tuichenchuxin opened a new pull request #13905:
URL: https://github.com/apache/shardingsphere/pull/13905
Fixes #13771.
Changes proposed in this pull request:
- add sql hint for write route only
--
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] codecov-commenter edited a comment on pull request #13905: add sql hint for write route only.
Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #13905:
URL: https://github.com/apache/shardingsphere/pull/13905#issuecomment-985202160
# [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#13905](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (6184c3f) into [master](https://codecov.io/gh/apache/shardingsphere/commit/9a57fb4ed9e83f1b90500f3981bad86c80209d8e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (9a57fb4) will **decrease** coverage by `0.02%`.
> The diff coverage is `73.07%`.
[](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
```diff
@@ Coverage Diff @@
## master #13905 +/- ##
============================================
- Coverage 63.95% 63.93% -0.03%
+ Complexity 1761 1760 -1
============================================
Files 2793 2793
Lines 41653 41669 +16
Branches 7136 7127 -9
============================================
- Hits 26641 26639 -2
- Misses 12977 12995 +18
Partials 2035 2035
```
| [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...ra/binder/statement/CommonSQLStatementContext.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtYmluZGVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9iaW5kZXIvc3RhdGVtZW50L0NvbW1vblNRTFN0YXRlbWVudENvbnRleHQuamF2YQ==) | `71.42% <33.33%> (-2.26%)` | :arrow_down: |
| [...route/impl/ReadwriteSplittingDataSourceRouter.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtcmVhZHdyaXRlLXNwbGl0dGluZy9zaGFyZGluZ3NwaGVyZS1yZWFkd3JpdGUtc3BsaXR0aW5nLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3JlYWR3cml0ZXNwbGl0dGluZy9yb3V0ZS9pbXBsL1JlYWR3cml0ZVNwbGl0dGluZ0RhdGFTb3VyY2VSb3V0ZXIuamF2YQ==) | `36.84% <50.00%> (+1.54%)` | :arrow_up: |
| [.../parser/sql/common/extractor/SQLHintExtractor.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvY29tbW9uL2V4dHJhY3Rvci9TUUxIaW50RXh0cmFjdG9yLmphdmE=) | `83.33% <82.35%> (+3.33%)` | :arrow_up: |
| [...tesplitting/route/ReadwriteSplittingSQLRouter.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtcmVhZHdyaXRlLXNwbGl0dGluZy9zaGFyZGluZ3NwaGVyZS1yZWFkd3JpdGUtc3BsaXR0aW5nLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3JlYWR3cml0ZXNwbGl0dGluZy9yb3V0ZS9SZWFkd3JpdGVTcGxpdHRpbmdTUUxSb3V0ZXIuamF2YQ==) | `95.00% <100.00%> (ø)` | |
| [...d/text/distsql/ral/common/hint/HintSourceType.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L2Rpc3RzcWwvcmFsL2NvbW1vbi9oaW50L0hpbnRTb3VyY2VUeXBlLmphdmE=) | `0.00% <0.00%> (-42.86%)` | :arrow_down: |
| [...DatabaseDiscoveryRuleConfigurationYamlSwapper.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZGItZGlzY292ZXJ5L3NoYXJkaW5nc3BoZXJlLWRiLWRpc2NvdmVyeS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9kYmRpc2NvdmVyeS95YW1sL3N3YXBwZXIvRGF0YWJhc2VEaXNjb3ZlcnlSdWxlQ29uZmlndXJhdGlvbllhbWxTd2FwcGVyLmphdmE=) | `74.28% <0.00%> (-13.22%)` | :arrow_down: |
| [.../core/executor/dumper/AbstractInventoryDumper.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc2NhbGluZy9zaGFyZGluZ3NwaGVyZS1zY2FsaW5nLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NjYWxpbmcvY29yZS9leGVjdXRvci9kdW1wZXIvQWJzdHJhY3RJbnZlbnRvcnlEdW1wZXIuamF2YQ==) | `80.39% <0.00%> (-7.85%)` | :arrow_down: |
| [...sphere/scaling/core/job/schedule/JobScheduler.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc2NhbGluZy9zaGFyZGluZ3NwaGVyZS1zY2FsaW5nLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NjYWxpbmcvY29yZS9qb2Ivc2NoZWR1bGUvSm9iU2NoZWR1bGVyLmphdmE=) | `20.68% <0.00%> (-3.45%)` | :arrow_down: |
| [...ngsphere/scaling/core/api/impl/ScalingAPIImpl.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc2NhbGluZy9zaGFyZGluZ3NwaGVyZS1zY2FsaW5nLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NjYWxpbmcvY29yZS9hcGkvaW1wbC9TY2FsaW5nQVBJSW1wbC5qYXZh) | `70.67% <0.00%> (-0.54%)` | :arrow_down: |
| [...gsphere/scaling/mysql/component/MySQLImporter.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc2NhbGluZy9zaGFyZGluZ3NwaGVyZS1zY2FsaW5nLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc2NhbGluZy1teXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2NhbGluZy9teXNxbC9jb21wb25lbnQvTXlTUUxJbXBvcnRlci5qYXZh) | `100.00% <0.00%> (ø)` | |
| ... and [38 more](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [9a57fb4...6184c3f](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
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] strongduanmu commented on a change in pull request #13905: add sql hint for write route only.
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #13905:
URL: https://github.com/apache/shardingsphere/pull/13905#discussion_r761670631
##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/SQLHintExtractor.java
##########
@@ -17,54 +17,88 @@
package org.apache.shardingsphere.sql.parser.sql.common.extractor;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.CommentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import java.util.Collections;
+import java.util.Map;
import java.util.Optional;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
/**
* SQL hint extractor.
*/
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class SQLHintExtractor {
private static final String SQL_COMMENT_SUFFIX = "*/";
- private static final String SQL_HINT_TOKEN = "sql hint:";
+ private static final String SQL_HINT_TOKEN = "shardingsphere hint:";
private static final String SQL_HINT_SPLIT = "=";
- private static final String SQL_HINT_DATASOURCE_NAME_KEY = "datasourcename";
+ private static final String SQL_HINT_DATASOURCE_NAME_KEY = "dataSourceName";
+
+ private static final String SQL_HINT_WRITE_ROUTE_ONLY_KEY = "writeRouteOnly";
+
+ private final Map<String, String> sqlHintMap;
+
+ private final Set<String> supportedSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+
+ public SQLHintExtractor(final SQLStatement sqlStatement) {
+ supportedSet.add(SQL_HINT_DATASOURCE_NAME_KEY);
+ supportedSet.add(SQL_HINT_WRITE_ROUTE_ONLY_KEY);
+ if (sqlStatement instanceof AbstractSQLStatement) {
+ sqlHintMap = extract((AbstractSQLStatement) sqlStatement);
+ } else {
+ sqlHintMap = Collections.emptyMap();
+ }
+ }
/**
- * Find hint data source name.
+ * Extract from statement.
*
* @param statement statement
- * @return data source name
+ * @return sql hint map
*/
- public static Optional<String> findHintDataSourceName(final AbstractSQLStatement statement) {
+ public Map<String, String> extract(final AbstractSQLStatement statement) {
+ Map<String, String> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
for (CommentSegment each : statement.getCommentSegments()) {
- Optional<String> result = findDataSourceNameFromComment(each.getText());
- if (result.isPresent()) {
- return result;
- }
+ extractFromComment(each.getText(), result);
}
- return Optional.empty();
+ return result;
}
- private static Optional<String> findDataSourceNameFromComment(final String comment) {
+ private void extractFromComment(final String comment, final Map<String, String> result) {
int startIndex = comment.toLowerCase().indexOf(SQL_HINT_TOKEN);
if (startIndex < 0) {
- return Optional.empty();
+ return;
}
startIndex = startIndex + SQL_HINT_TOKEN.length();
int endIndex = comment.endsWith(SQL_COMMENT_SUFFIX) ? comment.indexOf(SQL_COMMENT_SUFFIX) : comment.length();
String[] hintValue = comment.substring(startIndex, endIndex).trim().split(SQL_HINT_SPLIT);
- if (2 == hintValue.length && SQL_HINT_DATASOURCE_NAME_KEY.equalsIgnoreCase(hintValue[0].trim()) && hintValue[1].trim().length() > 0) {
- return Optional.of(hintValue[1].trim());
+ if (2 == hintValue.length && hintValue[0].trim().length() > 0 && hintValue[1].trim().length() > 0 && supportedSet.contains(hintValue[0].trim())) {
+ result.put(hintValue[0].trim(), hintValue[1].trim());
}
- return Optional.empty();
+ }
+
+ /**
+ * Find hint data source name.
+ *
+ * @return data source name
+ */
+ public Optional<String> findHintDataSourceName() {
+ return Optional.ofNullable(sqlHintMap.get(SQL_HINT_DATASOURCE_NAME_KEY));
+ }
+
+ /**
+ * Judge whether is hint routed to write data source.
+ *
+ * @return whether is hint routed to write data source
+ */
+ public boolean isHintWriteRouteOnly() {
+ return "true".equalsIgnoreCase(sqlHintMap.get(SQL_HINT_WRITE_ROUTE_ONLY_KEY));
Review comment:
@tuichenchuxin Can we add SQLHintProperties and SQLHintPropertyKey to handle properties type cast?
--
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] codecov-commenter commented on pull request #13905: add sql hint for write route only.
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #13905:
URL: https://github.com/apache/shardingsphere/pull/13905#issuecomment-985202160
# [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#13905](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (61d48a5) into [master](https://codecov.io/gh/apache/shardingsphere/commit/9a57fb4ed9e83f1b90500f3981bad86c80209d8e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (9a57fb4) will **decrease** coverage by `0.01%`.
> The diff coverage is `70.83%`.
[](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
```diff
@@ Coverage Diff @@
## master #13905 +/- ##
============================================
- Coverage 63.95% 63.94% -0.02%
+ Complexity 1761 1760 -1
============================================
Files 2793 2792 -1
Lines 41653 41655 +2
Branches 7136 7126 -10
============================================
- Hits 26641 26638 -3
- Misses 12977 12984 +7
+ Partials 2035 2033 -2
```
| [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...ra/binder/statement/CommonSQLStatementContext.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtYmluZGVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9iaW5kZXIvc3RhdGVtZW50L0NvbW1vblNRTFN0YXRlbWVudENvbnRleHQuamF2YQ==) | `71.42% <33.33%> (-2.26%)` | :arrow_down: |
| [...route/impl/ReadwriteSplittingDataSourceRouter.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtcmVhZHdyaXRlLXNwbGl0dGluZy9zaGFyZGluZ3NwaGVyZS1yZWFkd3JpdGUtc3BsaXR0aW5nLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3JlYWR3cml0ZXNwbGl0dGluZy9yb3V0ZS9pbXBsL1JlYWR3cml0ZVNwbGl0dGluZ0RhdGFTb3VyY2VSb3V0ZXIuamF2YQ==) | `36.84% <50.00%> (+1.54%)` | :arrow_up: |
| [.../parser/sql/common/extractor/SQLHintExtractor.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvY29tbW9uL2V4dHJhY3Rvci9TUUxIaW50RXh0cmFjdG9yLmphdmE=) | `79.16% <80.00%> (-0.84%)` | :arrow_down: |
| [...tesplitting/route/ReadwriteSplittingSQLRouter.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtcmVhZHdyaXRlLXNwbGl0dGluZy9zaGFyZGluZ3NwaGVyZS1yZWFkd3JpdGUtc3BsaXR0aW5nLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3JlYWR3cml0ZXNwbGl0dGluZy9yb3V0ZS9SZWFkd3JpdGVTcGxpdHRpbmdTUUxSb3V0ZXIuamF2YQ==) | `95.00% <100.00%> (ø)` | |
| [...d/text/distsql/ral/common/hint/HintSourceType.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L2Rpc3RzcWwvcmFsL2NvbW1vbi9oaW50L0hpbnRTb3VyY2VUeXBlLmphdmE=) | `0.00% <0.00%> (-42.86%)` | :arrow_down: |
| [...ngsphere/scaling/core/api/impl/ScalingAPIImpl.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc2NhbGluZy9zaGFyZGluZ3NwaGVyZS1zY2FsaW5nLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NjYWxpbmcvY29yZS9hcGkvaW1wbC9TY2FsaW5nQVBJSW1wbC5qYXZh) | `70.67% <0.00%> (-0.54%)` | :arrow_down: |
| [...gsphere/scaling/mysql/component/MySQLImporter.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc2NhbGluZy9zaGFyZGluZ3NwaGVyZS1zY2FsaW5nLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc2NhbGluZy1teXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2NhbGluZy9teXNxbC9jb21wb25lbnQvTXlTUUxJbXBvcnRlci5qYXZh) | `100.00% <0.00%> (ø)` | |
| [.../scaling/mysql/component/MySQLInventoryDumper.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc2NhbGluZy9zaGFyZGluZ3NwaGVyZS1zY2FsaW5nLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc2NhbGluZy1teXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2NhbGluZy9teXNxbC9jb21wb25lbnQvTXlTUUxJbnZlbnRvcnlEdW1wZXIuamF2YQ==) | `90.00% <0.00%> (ø)` | |
| [...tor/dml/impl/ShardingDeleteStatementValidator.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvcm91dGUvZW5naW5lL3ZhbGlkYXRvci9kbWwvaW1wbC9TaGFyZGluZ0RlbGV0ZVN0YXRlbWVudFZhbGlkYXRvci5qYXZh) | `33.33% <0.00%> (ø)` | |
| [...tor/dml/impl/ShardingInsertStatementValidator.java](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvcm91dGUvZW5naW5lL3ZhbGlkYXRvci9kbWwvaW1wbC9TaGFyZGluZ0luc2VydFN0YXRlbWVudFZhbGlkYXRvci5qYXZh) | `84.37% <0.00%> (ø)` | |
| ... and [30 more](https://codecov.io/gh/apache/shardingsphere/pull/13905/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [9a57fb4...61d48a5](https://codecov.io/gh/apache/shardingsphere/pull/13905?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
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] strongduanmu merged pull request #13905: add sql hint for write route only.
Posted by GitBox <gi...@apache.org>.
strongduanmu merged pull request #13905:
URL: https://github.com/apache/shardingsphere/pull/13905
--
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] strongduanmu commented on a change in pull request #13905: add sql hint for write route only.
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #13905:
URL: https://github.com/apache/shardingsphere/pull/13905#discussion_r761667099
##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/SQLHintExtractor.java
##########
@@ -17,54 +17,88 @@
package org.apache.shardingsphere.sql.parser.sql.common.extractor;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.CommentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import java.util.Collections;
+import java.util.Map;
import java.util.Optional;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
/**
* SQL hint extractor.
*/
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class SQLHintExtractor {
private static final String SQL_COMMENT_SUFFIX = "*/";
- private static final String SQL_HINT_TOKEN = "sql hint:";
+ private static final String SQL_HINT_TOKEN = "shardingsphere hint:";
private static final String SQL_HINT_SPLIT = "=";
- private static final String SQL_HINT_DATASOURCE_NAME_KEY = "datasourcename";
+ private static final String SQL_HINT_DATASOURCE_NAME_KEY = "dataSourceName";
+
+ private static final String SQL_HINT_WRITE_ROUTE_ONLY_KEY = "writeRouteOnly";
+
+ private final Map<String, String> sqlHintMap;
+
+ private final Set<String> supportedSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
Review comment:
@tuichenchuxin Please add static modifier.
##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/SQLHintExtractor.java
##########
@@ -17,54 +17,88 @@
package org.apache.shardingsphere.sql.parser.sql.common.extractor;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.CommentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import java.util.Collections;
+import java.util.Map;
import java.util.Optional;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
/**
* SQL hint extractor.
*/
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class SQLHintExtractor {
private static final String SQL_COMMENT_SUFFIX = "*/";
- private static final String SQL_HINT_TOKEN = "sql hint:";
+ private static final String SQL_HINT_TOKEN = "shardingsphere hint:";
private static final String SQL_HINT_SPLIT = "=";
- private static final String SQL_HINT_DATASOURCE_NAME_KEY = "datasourcename";
+ private static final String SQL_HINT_DATASOURCE_NAME_KEY = "dataSourceName";
+
+ private static final String SQL_HINT_WRITE_ROUTE_ONLY_KEY = "writeRouteOnly";
+
+ private final Map<String, String> sqlHintMap;
+
+ private final Set<String> supportedSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+
+ public SQLHintExtractor(final SQLStatement sqlStatement) {
+ supportedSet.add(SQL_HINT_DATASOURCE_NAME_KEY);
+ supportedSet.add(SQL_HINT_WRITE_ROUTE_ONLY_KEY);
+ if (sqlStatement instanceof AbstractSQLStatement) {
+ sqlHintMap = extract((AbstractSQLStatement) sqlStatement);
+ } else {
+ sqlHintMap = Collections.emptyMap();
+ }
+ }
/**
- * Find hint data source name.
+ * Extract from statement.
*
* @param statement statement
- * @return data source name
+ * @return sql hint map
*/
- public static Optional<String> findHintDataSourceName(final AbstractSQLStatement statement) {
+ public Map<String, String> extract(final AbstractSQLStatement statement) {
+ Map<String, String> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
for (CommentSegment each : statement.getCommentSegments()) {
- Optional<String> result = findDataSourceNameFromComment(each.getText());
- if (result.isPresent()) {
- return result;
- }
+ extractFromComment(each.getText(), result);
}
- return Optional.empty();
+ return result;
}
- private static Optional<String> findDataSourceNameFromComment(final String comment) {
+ private void extractFromComment(final String comment, final Map<String, String> result) {
int startIndex = comment.toLowerCase().indexOf(SQL_HINT_TOKEN);
if (startIndex < 0) {
- return Optional.empty();
+ return;
}
startIndex = startIndex + SQL_HINT_TOKEN.length();
int endIndex = comment.endsWith(SQL_COMMENT_SUFFIX) ? comment.indexOf(SQL_COMMENT_SUFFIX) : comment.length();
String[] hintValue = comment.substring(startIndex, endIndex).trim().split(SQL_HINT_SPLIT);
- if (2 == hintValue.length && SQL_HINT_DATASOURCE_NAME_KEY.equalsIgnoreCase(hintValue[0].trim()) && hintValue[1].trim().length() > 0) {
- return Optional.of(hintValue[1].trim());
+ if (2 == hintValue.length && hintValue[0].trim().length() > 0 && hintValue[1].trim().length() > 0 && supportedSet.contains(hintValue[0].trim())) {
+ result.put(hintValue[0].trim(), hintValue[1].trim());
}
- return Optional.empty();
+ }
+
+ /**
+ * Find hint data source name.
+ *
+ * @return data source name
+ */
+ public Optional<String> findHintDataSourceName() {
+ return Optional.ofNullable(sqlHintMap.get(SQL_HINT_DATASOURCE_NAME_KEY));
+ }
+
+ /**
+ * Judge whether is hint routed to write data source.
+ *
+ * @return whether is hint routed to write data source
+ */
+ public boolean isHintWriteRouteOnly() {
+ return "true".equalsIgnoreCase(sqlHintMap.get(SQL_HINT_WRITE_ROUTE_ONLY_KEY));
Review comment:
@tuichenchuxin Can we add `SQLHintProperties` and `SQLHintPropertyKey` to handle properties type cast?
--
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] strongduanmu commented on a change in pull request #13905: add sql hint for write route only.
Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #13905:
URL: https://github.com/apache/shardingsphere/pull/13905#discussion_r761621987
##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/SQLHintExtractor.java
##########
@@ -17,54 +17,87 @@
package org.apache.shardingsphere.sql.parser.sql.common.extractor;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.CommentSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Optional;
/**
* SQL hint extractor.
*/
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class SQLHintExtractor {
private static final String SQL_COMMENT_SUFFIX = "*/";
- private static final String SQL_HINT_TOKEN = "sql hint:";
+ private static final String SQL_HINT_TOKEN = "shardingsphere hint:";
private static final String SQL_HINT_SPLIT = "=";
private static final String SQL_HINT_DATASOURCE_NAME_KEY = "datasourcename";
+ private static final String SQL_HINT_WRITE_ROUTE_ONLY_KEY = "writerouteonly";
+
+ private final Map<String, String> sqlHintMap;
+
+ public SQLHintExtractor(final SQLStatement sqlStatement) {
+ if (sqlStatement instanceof AbstractSQLStatement) {
+ sqlHintMap = extract((AbstractSQLStatement) sqlStatement);
+ } else {
+ sqlHintMap = Collections.emptyMap();
+ }
+ }
+
/**
- * Find hint data source name.
+ * Extract from statement.
*
* @param statement statement
- * @return data source name
+ * @return sql hint map
*/
- public static Optional<String> findHintDataSourceName(final AbstractSQLStatement statement) {
+ public static Map<String, String> extract(final AbstractSQLStatement statement) {
for (CommentSegment each : statement.getCommentSegments()) {
- Optional<String> result = findDataSourceNameFromComment(each.getText());
- if (result.isPresent()) {
- return result;
+ Optional<Map<String, String>> map = extractFromComment(each.getText());
+ if (map.isPresent()) {
+ return map.get();
}
}
- return Optional.empty();
+ return Collections.emptyMap();
}
- private static Optional<String> findDataSourceNameFromComment(final String comment) {
+ private static Optional<Map<String, String>> extractFromComment(final String comment) {
Review comment:
@tuichenchuxin Can we remove Optional 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