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/06/15 09:41:12 UTC

[GitHub] [shardingsphere] strongduanmu opened a new pull request #10816: support postgresql create index without index name

strongduanmu opened a new pull request #10816:
URL: https://github.com/apache/shardingsphere/pull/10816


   Fixes #10552.
   
   Changes proposed in this pull request:
   - support postgresql create index without index name
   - add rewrite test case
   


-- 
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] strongduanmu commented on a change in pull request #10816: support postgresql create index without index name

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



##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexToken.java
##########
@@ -62,7 +63,12 @@ public IndexToken(final int startIndex, final int stopIndex, final IdentifierVal
     
     @Override
     public String toString(final RouteUnit routeUnit) {
-        return identifier.getQuoteCharacter().wrap(getIndexValue(routeUnit));
+        String quotedIndexName = identifier.getQuoteCharacter().wrap(getIndexValue(routeUnit));
+        return isGeneratedIndex() ? " " + quotedIndexName + " " : quotedIndexName;

Review comment:
       > Will it be better to move blank space to the outer?
   
   @tristaZero Extracting to the outside means that we need to pass more parameters in RouteSQLBuilder. In addition, I refer to other tokens, and similar string splicing also exists.
   
   ```java
   // ShardingInsertValuesToken
   @Override
   public String toString(final RouteUnit routeUnit) {
       StringBuilder result = new StringBuilder();
       appendInsertValue(routeUnit, result);
       result.delete(result.length() - 2, result.length());
       return result.toString();
   }
   
   private void appendInsertValue(final RouteUnit routeUnit, final StringBuilder stringBuilder) {
       for (InsertValue each : getInsertValues()) {
           if (isAppend(routeUnit, (ShardingInsertValue) each)) {
               stringBuilder.append(each).append(", ");
           }
       }
   }
   
   // OrderByToken
   @Override
   public String toString() {
       StringBuilder result = new StringBuilder();
       result.append(" ORDER BY ");
       for (int i = 0; i < columnLabels.size(); i++) {
           if (0 == i) {
               result.append(columnLabels.get(0)).append(" ").append(orderDirections.get(i).name());
           } else {
               result.append(",").append(columnLabels.get(i)).append(" ").append(orderDirections.get(i).name());
           }
       }
       result.append(" ");
       return result.toString();
   }
   ```




-- 
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 merged pull request #10816: support postgresql create index without index name

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


   


-- 
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-commenter commented on pull request #10816: support postgresql create index without index name

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


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/10816?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 [#10816](https://codecov.io/gh/apache/shardingsphere/pull/10816?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (896facc) into [master](https://codecov.io/gh/apache/shardingsphere/commit/c7c05070675c9a5cc85987dc3f93a7d46aa58855?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (c7c0507) will **increase** coverage by `0.01%`.
   > The diff coverage is `40.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/10816/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/10816?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   #10816      +/-   ##
   ============================================
   + Coverage     65.61%   65.63%   +0.01%     
   - Complexity      701      718      +17     
   ============================================
     Files          1789     1809      +20     
     Lines         30866    30923      +57     
     Branches       5565     5572       +7     
   ============================================
   + Hits          20254    20296      +42     
   - Misses         8998     9011      +13     
   - Partials       1614     1616       +2     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/10816?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...sphere/sharding/rewrite/token/pojo/IndexToken.java](https://codecov.io/gh/apache/shardingsphere/pull/10816/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-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvcmV3cml0ZS90b2tlbi9wb2pvL0luZGV4VG9rZW4uamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...der/statement/ddl/CreateIndexStatementContext.java](https://codecov.io/gh/apache/shardingsphere/pull/10816/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-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtYmluZGVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9iaW5kZXIvc3RhdGVtZW50L2RkbC9DcmVhdGVJbmRleFN0YXRlbWVudENvbnRleHQuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...sql/common/statement/ddl/CreateIndexStatement.java](https://codecov.io/gh/apache/shardingsphere/pull/10816/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-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvY29tbW9uL3N0YXRlbWVudC9kZGwvQ3JlYXRlSW5kZXhTdGF0ZW1lbnQuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...alect/handler/ddl/CreateIndexStatementHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/10816/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-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvZGlhbGVjdC9oYW5kbGVyL2RkbC9DcmVhdGVJbmRleFN0YXRlbWVudEhhbmRsZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...postgresql/ddl/PostgreSQLCreateIndexStatement.java](https://codecov.io/gh/apache/shardingsphere/pull/10816/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-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvZGlhbGVjdC9zdGF0ZW1lbnQvcG9zdGdyZXNxbC9kZGwvUG9zdGdyZVNRTENyZWF0ZUluZGV4U3RhdGVtZW50LmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...sher/type/CreateIndexStatementSchemaRefresher.java](https://codecov.io/gh/apache/shardingsphere/pull/10816/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-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9tZXRhZGF0YS9zY2hlbWEvcmVmcmVzaGVyL3R5cGUvQ3JlYXRlSW5kZXhTdGF0ZW1lbnRTY2hlbWFSZWZyZXNoZXIuamF2YQ==) | `71.42% <50.00%> (-28.58%)` | :arrow_down: |
   | [...etadata/schema/builder/util/IndexMetaDataUtil.java](https://codecov.io/gh/apache/shardingsphere/pull/10816/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-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9tZXRhZGF0YS9zY2hlbWEvYnVpbGRlci91dGlsL0luZGV4TWV0YURhdGFVdGlsLmphdmE=) | `62.50% <57.14%> (-37.50%)` | :arrow_down: |
   | [...atement/impl/PostgreSQLDDLStatementSQLVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/10816/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-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci1wb3N0Z3Jlc3FsL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9zcWwvcGFyc2VyL3Bvc3RncmVzcWwvdmlzaXRvci9zdGF0ZW1lbnQvaW1wbC9Qb3N0Z3JlU1FMRERMU3RhdGVtZW50U1FMVmlzaXRvci5qYXZh) | `78.46% <85.71%> (+0.38%)` | :arrow_up: |
   | [...dl/impl/ShardingCreateIndexStatementValidator.java](https://codecov.io/gh/apache/shardingsphere/pull/10816/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-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmcvc2hhcmRpbmdzcGhlcmUtc2hhcmRpbmctY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc2hhcmRpbmcvcm91dGUvZW5naW5lL3ZhbGlkYXRvci9kZGwvaW1wbC9TaGFyZGluZ0NyZWF0ZUluZGV4U3RhdGVtZW50VmFsaWRhdG9yLmphdmE=) | `87.50% <100.00%> (ø)` | |
   | [...core/resource/ResourceDistSQLStatementVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/10816/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-c2hhcmRpbmdzcGhlcmUtZGlzdHNxbC1wYXJzZXIvc2hhcmRpbmdzcGhlcmUtZGlzdHNxbC1wYXJzZXItZW5naW5lL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9kaXN0c3FsL3BhcnNlci9jb3JlL3Jlc291cmNlL1Jlc291cmNlRGlzdFNRTFN0YXRlbWVudFZpc2l0b3IuamF2YQ==) | `55.00% <0.00%> (-26.04%)` | :arrow_down: |
   | ... and [33 more](https://codecov.io/gh/apache/shardingsphere/pull/10816/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/10816?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/10816?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 [c7c0507...896facc](https://codecov.io/gh/apache/shardingsphere/pull/10816?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.

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



[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #10816: support postgresql create index without index name

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



##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateIndexStatementValidator.java
##########
@@ -38,7 +39,9 @@ public void preValidate(final ShardingRule shardingRule, final SQLStatementConte
                             final List<Object> parameters, final ShardingSphereSchema schema) {
         validateTableExist(schema, Collections.singletonList(sqlStatementContext.getSqlStatement().getTable()));
         String tableName = sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue();
-        String indexName = sqlStatementContext.getSqlStatement().getIndex().getIdentifier().getValue();
+        String indexName = null != sqlStatementContext.getSqlStatement().getIndex() 
+                ? sqlStatementContext.getSqlStatement().getIndex().getIdentifier().getValue()
+                : IndexMetaDataUtil.getGeneratedLogicIndexName(sqlStatementContext.getSqlStatement().getColumns());

Review comment:
       > How about `sqlStatementContext.getIndexName()`?
   
   @tristaZero Great idea, I have extracted the logic into the getIndexes method in sqlStatementContext.




-- 
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] strongduanmu commented on pull request #10816: support postgresql create index without index name

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


   > fix ut in windows first
   
   @kimmking Thanks for your reminder, I have fixed 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.

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



[GitHub] [shardingsphere] kimmking commented on pull request #10816: support postgresql create index without index name

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


   fix ut in windows first


-- 
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 a change in pull request #10816: support postgresql create index without index name

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



##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexToken.java
##########
@@ -62,7 +63,12 @@ public IndexToken(final int startIndex, final int stopIndex, final IdentifierVal
     
     @Override
     public String toString(final RouteUnit routeUnit) {
-        return identifier.getQuoteCharacter().wrap(getIndexValue(routeUnit));
+        String quotedIndexName = identifier.getQuoteCharacter().wrap(getIndexValue(routeUnit));
+        return isGeneratedIndex() ? " " + quotedIndexName + " " : quotedIndexName;

Review comment:
       Will it be better to move blank space to the outer?

##########
File path: shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingCreateIndexStatementValidator.java
##########
@@ -38,7 +39,9 @@ public void preValidate(final ShardingRule shardingRule, final SQLStatementConte
                             final List<Object> parameters, final ShardingSphereSchema schema) {
         validateTableExist(schema, Collections.singletonList(sqlStatementContext.getSqlStatement().getTable()));
         String tableName = sqlStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue();
-        String indexName = sqlStatementContext.getSqlStatement().getIndex().getIdentifier().getValue();
+        String indexName = null != sqlStatementContext.getSqlStatement().getIndex() 
+                ? sqlStatementContext.getSqlStatement().getIndex().getIdentifier().getValue()
+                : IndexMetaDataUtil.getGeneratedLogicIndexName(sqlStatementContext.getSqlStatement().getColumns());

Review comment:
       How about `sqlStatementContext.getIndexName()`?

##########
File path: shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateIndexStatementContext.java
##########
@@ -49,6 +56,10 @@ public CreateIndexStatementContext(final CreateIndexStatement sqlStatement) {
     
     @Override
     public Collection<IndexSegment> getIndexes() {
-        return null == getSqlStatement().getIndex() ? Collections.emptyList() : Collections.singletonList(getSqlStatement().getIndex());
+        Optional<Integer> startIndex = CreateIndexStatementHandler.getGeneratedIndexStartIndex(getSqlStatement());
+        String generatedLogicIndexName = IndexMetaDataUtil.getGeneratedLogicIndexName(getSqlStatement().getColumns());
+        Collection<IndexSegment> generatedIndexSegments = startIndex.map(index -> Collections.singletonList(new IndexSegment(index, index, 

Review comment:
       if (null != getSqlStatement().getIndex()) {
   return
   }
   Collection<IndexSegment> generatedIndexSegments =xxx;
   return?




-- 
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] strongduanmu commented on a change in pull request #10816: support postgresql create index without index name

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



##########
File path: shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/ddl/CreateIndexStatementContext.java
##########
@@ -49,6 +56,10 @@ public CreateIndexStatementContext(final CreateIndexStatement sqlStatement) {
     
     @Override
     public Collection<IndexSegment> getIndexes() {
-        return null == getSqlStatement().getIndex() ? Collections.emptyList() : Collections.singletonList(getSqlStatement().getIndex());
+        Optional<Integer> startIndex = CreateIndexStatementHandler.getGeneratedIndexStartIndex(getSqlStatement());
+        String generatedLogicIndexName = IndexMetaDataUtil.getGeneratedLogicIndexName(getSqlStatement().getColumns());
+        Collection<IndexSegment> generatedIndexSegments = startIndex.map(index -> Collections.singletonList(new IndexSegment(index, index, 

Review comment:
       > if (null != getSqlStatement().getIndex()) {
   > return
   > }
   > Collection generatedIndexSegments =xxx;
   > return?
   
   @tristaZero Thanks for your suggestion, I have optimized 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.

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