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 2020/01/04 13:43:32 UTC

[GitHub] [incubator-shardingsphere] lyzhb9014 opened a new pull request #3868: Dev 3644

lyzhb9014 opened a new pull request #3868: Dev 3644
URL: https://github.com/apache/incubator-shardingsphere/pull/3868
 
 
   Fixes #3644 .
   
   Changes proposed in this pull request:
   - Part of the shard key in multiple sharding policies can be null
   -
   -
   

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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] KomachiSion commented on a change in pull request #3868: Part of the shard key in multiple sharding policies can be null

Posted by GitBox <gi...@apache.org>.
KomachiSion commented on a change in pull request #3868: Part of the shard key in multiple sharding policies can be null
URL: https://github.com/apache/incubator-shardingsphere/pull/3868#discussion_r363133756
 
 

 ##########
 File path: sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/router/sharding/condition/engine/InsertClauseShardingConditionEngine.java
 ##########
 @@ -84,27 +84,39 @@ private ShardingCondition createShardingCondition(final String tableName, final
         for (ExpressionSegment each : insertValueContext.getValueExpressions()) {
             String columnName = columnNames.next();
             if (shardingRule.isShardingColumn(columnName, tableName)) {
-                if (each instanceof SimpleExpressionSegment) {
-                    result.getRouteValues().add(new ListRouteValue<>(columnName, tableName, Collections.singletonList(getRouteValue((SimpleExpressionSegment) each, parameters))));
-                } else if (ExpressionConditionUtils.isNowExpression(each)) {
-                    result.getRouteValues().add(new ListRouteValue<>(columnName, tableName, Collections.singletonList(timeService.getTime())));
+                Comparable<?> routeValue = getRouteValue(each, parameters, timeService);
+                if (null != routeValue) {
+                    result.getRouteValues().add(new ListRouteValue<>(columnName, tableName, Collections.singletonList(routeValue)));
                 }
             }
         }
         return result;
     }
-    
+
+    private Comparable<?> getRouteValue(final ExpressionSegment expressionSegment, final List<Object> parameters, final SPITimeService timeService) {
+        Comparable<?> routeValue = null;
+        if (expressionSegment instanceof SimpleExpressionSegment) {
+            routeValue = getRouteValue((SimpleExpressionSegment) expressionSegment, parameters);
+        } else if (ExpressionConditionUtils.isNowExpression(expressionSegment)) {
+            routeValue = timeService.getTime();
+        }
+        return routeValue;
+    }
+
     private Comparable<?> getRouteValue(final SimpleExpressionSegment expressionSegment, final List<Object> parameters) {
         Object result;
         if (expressionSegment instanceof ParameterMarkerExpressionSegment) {
             result = parameters.get(((ParameterMarkerExpressionSegment) expressionSegment).getParameterMarkerIndex());
         } else {
             result = ((LiteralExpressionSegment) expressionSegment).getLiterals();
         }
+        if (null == result) {
+            return null;
+        }
         Preconditions.checkArgument(result instanceof Comparable, "Sharding value must implements Comparable.");
         return (Comparable) result;
     }
-    
+
 
 Review comment:
   Please do not change the indents

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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] SteNicholas commented on a change in pull request #3868: Part of the shard key in multiple sharding policies can be null

Posted by GitBox <gi...@apache.org>.
SteNicholas commented on a change in pull request #3868: Part of the shard key in multiple sharding policies can be null
URL: https://github.com/apache/incubator-shardingsphere/pull/3868#discussion_r363067410
 
 

 ##########
 File path: sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/router/sharding/condition/engine/InsertClauseShardingConditionEngine.java
 ##########
 @@ -84,27 +84,40 @@ private ShardingCondition createShardingCondition(final String tableName, final
         for (ExpressionSegment each : insertValueContext.getValueExpressions()) {
             String columnName = columnNames.next();
             if (shardingRule.isShardingColumn(columnName, tableName)) {
-                if (each instanceof SimpleExpressionSegment) {
-                    result.getRouteValues().add(new ListRouteValue<>(columnName, tableName, Collections.singletonList(getRouteValue((SimpleExpressionSegment) each, parameters))));
-                } else if (ExpressionConditionUtils.isNowExpression(each)) {
-                    result.getRouteValues().add(new ListRouteValue<>(columnName, tableName, Collections.singletonList(timeService.getTime())));
+                Comparable<?> routeValue = getRouteValue(each, parameters, timeService);
+                if (null == routeValue) {
 
 Review comment:
   This could judge routeValue is not null, and `result.getRouteValues().add(new ListRouteValue<>(columnName, tableName, Collections.singletonList(routeValue)))` add to if logic, remove the continue.

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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] coveralls commented on issue #3868: Part of the shard key in multiple sharding policies can be null

Posted by GitBox <gi...@apache.org>.
coveralls commented on issue #3868: Part of the shard key in multiple sharding policies can be null
URL: https://github.com/apache/incubator-shardingsphere/pull/3868#issuecomment-570953429
 
 
   ## Pull Request Test Coverage Report for [Build 1267](https://coveralls.io/builds/27922373)
   
   * **8** of **11**   **(72.73%)**  changed or added relevant lines in **1** file are covered.
   * **228** unchanged lines in **9** files lost coverage.
   * Overall coverage decreased (**-0.2%**) to **65.045%**
   
   ---
   
   |  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
   | :-----|--------------|--------|---: |
   | [sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/router/sharding/condition/engine/InsertClauseShardingConditionEngine.java](https://coveralls.io/builds/27922373/source?filename=sharding-core%2Fsharding-core-route%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fcore%2Froute%2Frouter%2Fsharding%2Fcondition%2Fengine%2FInsertClauseShardingConditionEngine.java#L100) | 8 | 11 | 72.73%
   <!-- | **Total:** | **8** | **11** | **72.73%** | -->
   
   |  Files with Coverage Reduction | New Missed Lines | % |
   | :-----|--------------|--: |
   | [sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/context/ShardingRuntimeContext.java](https://coveralls.io/builds/27922373/source?filename=sharding-jdbc%2Fsharding-jdbc-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fshardingjdbc%2Fjdbc%2Fcore%2Fcontext%2FShardingRuntimeContext.java#L57) | 2 | 93.94% |
   | [sharding-proxy/sharding-proxy-backend/src/main/java/org/apache/shardingsphere/shardingproxy/backend/schema/impl/EncryptSchema.java](https://coveralls.io/builds/27922373/source?filename=sharding-proxy%2Fsharding-proxy-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fshardingproxy%2Fbackend%2Fschema%2Fimpl%2FEncryptSchema.java#L54) | 11 | 0.0% |
   | [sharding-proxy/sharding-proxy-backend/src/main/java/org/apache/shardingsphere/shardingproxy/backend/schema/LogicSchema.java](https://coveralls.io/builds/27922373/source?filename=sharding-proxy%2Fsharding-proxy-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fshardingproxy%2Fbackend%2Fschema%2FLogicSchema.java#L48) | 11 | 0.0% |
   | [sharding-proxy/sharding-proxy-backend/src/main/java/org/apache/shardingsphere/shardingproxy/backend/schema/impl/TransparentSchema.java](https://coveralls.io/builds/27922373/source?filename=sharding-proxy%2Fsharding-proxy-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fshardingproxy%2Fbackend%2Fschema%2Fimpl%2FTransparentSchema.java#L51) | 14 | 0.0% |
   | [sharding-proxy/sharding-proxy-backend/src/main/java/org/apache/shardingsphere/shardingproxy/backend/schema/impl/MasterSlaveSchema.java](https://coveralls.io/builds/27922373/source?filename=sharding-proxy%2Fsharding-proxy-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fshardingproxy%2Fbackend%2Fschema%2Fimpl%2FMasterSlaveSchema.java#L60) | 21 | 0.0% |
   | [sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/executor/AbstractStatementExecutor.java](https://coveralls.io/builds/27922373/source?filename=sharding-jdbc%2Fsharding-jdbc-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fshardingjdbc%2Fexecutor%2FAbstractStatementExecutor.java#L89) | 26 | 50.48% |
   | [encrypt-core/encrypt-core-common/src/main/java/org/apache/shardingsphere/encrypt/metadata/loader/EncryptTableMetaDataLoader.java](https://coveralls.io/builds/27922373/source?filename=encrypt-core%2Fencrypt-core-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fencrypt%2Fmetadata%2Floader%2FEncryptTableMetaDataLoader.java#L47) | 31 | 0.0% |
   | [sharding-proxy/sharding-proxy-backend/src/main/java/org/apache/shardingsphere/shardingproxy/backend/schema/impl/ShardingSchema.java](https://coveralls.io/builds/27922373/source?filename=sharding-proxy%2Fsharding-proxy-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fshardingproxy%2Fbackend%2Fschema%2Fimpl%2FShardingSchema.java#L75) | 37 | 0.0% |
   | [sharding-core/sharding-core-execute/src/main/java/org/apache/shardingsphere/sharding/execute/metadata/loader/ShardingTableMetaDataLoader.java](https://coveralls.io/builds/27922373/source?filename=sharding-core%2Fsharding-core-execute%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fsharding%2Fexecute%2Fmetadata%2Floader%2FShardingTableMetaDataLoader.java#L59) | 75 | 0.0% |
   <!-- | **Total:** | **228** |  | -->
   
   |  Totals | [![Coverage Status](https://coveralls.io/builds/27922373/badge)](https://coveralls.io/builds/27922373) |
   | :-- | --: |
   | Change from base [Build 646](https://coveralls.io/builds/27911328): |  -0.2% |
   | Covered Lines: | 11381 |
   | Relevant Lines: | 17497 |
   
   ---
   ##### 💛  - [Coveralls](https://coveralls.io)
   

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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] kimmking commented on issue #3868: Part of the shard key in multiple sharding policies can be null

Posted by GitBox <gi...@apache.org>.
kimmking commented on issue #3868: Part of the shard key in multiple sharding policies can be null
URL: https://github.com/apache/incubator-shardingsphere/pull/3868#issuecomment-570912954
 
 
   I think a git squash is necessary.

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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] lyzhb9014 commented on issue #3868: Part of the shard key in multiple sharding policies can be null

Posted by GitBox <gi...@apache.org>.
lyzhb9014 commented on issue #3868: Part of the shard key in multiple sharding policies can be null
URL: https://github.com/apache/incubator-shardingsphere/pull/3868#issuecomment-570978904
 
 
   > The implement has no problem, but has one code style problem.
   > Can you fix it?
   > 
   > What's more, Can you add unit test case for this PR?
   
   ok, I will fix it, and add unit 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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] KomachiSion commented on issue #3868: Part of the shard key in multiple sharding policies can be null

Posted by GitBox <gi...@apache.org>.
KomachiSion commented on issue #3868: Part of the shard key in multiple sharding policies can be null
URL: https://github.com/apache/incubator-shardingsphere/pull/3868#issuecomment-571012238
 
 
   @lyzhb9014 , Sorry, My mistake. I read the issue again, and I found there are some error  in this implementation.
   
   1. this implementation will cause insert with null value full-routing for one record.
   2. Even just for ComplexShardingStrategy, the null value also can't be input to sharding algorithm.
   
   So we can't accept this PR.

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


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] lyzhb9014 closed pull request #3868: Part of the shard key in multiple sharding policies can be null

Posted by GitBox <gi...@apache.org>.
lyzhb9014 closed pull request #3868: Part of the shard key in multiple sharding policies can be null
URL: https://github.com/apache/incubator-shardingsphere/pull/3868
 
 
   

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


With regards,
Apache Git Services