You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/09/24 05:12:36 UTC

[shardingsphere] branch master updated: Fix SQL garbled after sharding rewrote (#21164)

This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 1c6202cc915 Fix SQL garbled after sharding rewrote (#21164)
1c6202cc915 is described below

commit 1c6202cc91556972bd3e68a0e2d4f58dec184016
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Sat Sep 24 13:12:26 2022 +0800

    Fix SQL garbled after sharding rewrote (#21164)
    
    * Fix SQL garbled after rewrote
    
    * Complete ShardingInsertValuesTokenTest
---
 .../sharding/rewrite/token/pojo/ShardingInsertValuesToken.java |  5 +++++
 .../rewrite/token/pojo/ShardingInsertValuesTokenTest.java      | 10 ++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingInsertValuesToken.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingInsertValuesToken.java
index 9f146825ca9..9633115e288 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingInsertValuesToken.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingInsertValuesToken.java
@@ -40,6 +40,11 @@ public final class ShardingInsertValuesToken extends InsertValuesToken implement
         return result.toString();
     }
     
+    @Override
+    public String toString() {
+        return toString(null);
+    }
+    
     private void appendInsertValue(final RouteUnit routeUnit, final StringBuilder stringBuilder) {
         for (InsertValue each : getInsertValues()) {
             if (isAppend(routeUnit, (ShardingInsertValue) each)) {
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingInsertValuesTokenTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingInsertValuesTokenTest.java
index bf5046619df..0cc6b6feac5 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingInsertValuesTokenTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingInsertValuesTokenTest.java
@@ -26,10 +26,10 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.L
 import org.junit.Before;
 import org.junit.Test;
 
-import java.util.List;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.LinkedList;
+import java.util.List;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -53,13 +53,19 @@ public final class ShardingInsertValuesTokenTest {
         expressionSegment.add(expressionSegment1);
         expressionSegment.add(expressionSegment2);
         Collection<DataNode> dataNodes = new LinkedList<>();
+        dataNodes.add(new DataNode("logic_ds", "tbl_0"));
         ShardingInsertValue shardingInsertValue = new ShardingInsertValue(expressionSegment, dataNodes);
         List<InsertValue> insertValues = shardingInsertValuesToken.getInsertValues();
         insertValues.add(shardingInsertValue);
     }
     
     @Test
-    public void assertToString() {
+    public void assertToStringWithRouteUnit() {
         assertThat(shardingInsertValuesToken.toString(routeUnit), is("('shardingsphere', 'test')"));
     }
+    
+    @Test
+    public void assertToStringWithoutRouteUnit() {
+        assertThat(shardingInsertValuesToken.toString(), is("('shardingsphere', 'test')"));
+    }
 }