Skip to content

Commit

Permalink
Fix sonar issue in InlineShardingAlgorithm (apache#26573)
Browse files Browse the repository at this point in the history
  • Loading branch information
strongduanmu authored Jun 26, 2023
1 parent a5d6c92 commit 7a582fd
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import groovy.lang.Closure;
import groovy.lang.MissingMethodException;
import groovy.util.Expando;
import org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.UnsupportedSQLOperationException;
import org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
Expand Down Expand Up @@ -66,9 +66,11 @@ private boolean isAllowRangeQuery(final Properties props) {
@Override
public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<Comparable<?>> shardingValue) {
ShardingSpherePreconditions.checkNotNull(shardingValue.getValue(), NullShardingValueException::new);
String columnName = shardingValue.getColumnName();
ShardingSpherePreconditions.checkState(algorithmExpression.contains(columnName), () -> new MismatchedInlineShardingAlgorithmExpressionAndColumnException(algorithmExpression, columnName));
Closure<?> closure = createClosure();
closure.setProperty(shardingValue.getColumnName(), shardingValue.getValue());
return getTargetShardingNode(closure, shardingValue.getColumnName());
closure.setProperty(columnName, shardingValue.getValue());
return getTargetShardingNode(closure, columnName);
}

@Override
Expand All @@ -87,7 +89,7 @@ private Closure<?> createClosure() {
private String getTargetShardingNode(final Closure<?> closure, final String columnName) {
try {
return closure.call().toString();
} catch (final MissingMethodException | NullPointerException ignored) {
} catch (final MissingMethodException ignored) {
throw new MismatchedInlineShardingAlgorithmExpressionAndColumnException(algorithmExpression, columnName);
}
}
Expand Down

0 comments on commit 7a582fd

Please sign in to comment.