You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/07/20 04:19:56 UTC

[shardingsphere] branch master updated: Add unit test for ColumnSegment#getExpression (#19365)

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

zhangliang 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 5264fdca876 Add unit test for ColumnSegment#getExpression (#19365)
5264fdca876 is described below

commit 5264fdca876887361f5aa8b5e0aaa23342f93d38
Author: skai <su...@gmail.com>
AuthorDate: Wed Jul 20 12:19:47 2022 +0800

    Add unit test for ColumnSegment#getExpression (#19365)
    
    * Add unit test for ColumnSegment#getExpression
    
    * clear code
    
    Co-authored-by: skai <sk...@topode.com>
---
 .../sql/parser/sql/common/segment/dml/column/ColumnSegment.java   | 4 +++-
 .../parser/sql/common/segment/dml/column/ColumnSegmentTest.java   | 8 ++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/column/ColumnSegment.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/column/ColumnSegment.java
index 2681bdff040..bac7b8b0c23 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/column/ColumnSegment.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/column/ColumnSegment.java
@@ -63,7 +63,9 @@ public final class ColumnSegment implements ExpressionSegment, OwnerAvailable {
      * @return expression
      */
     public String getExpression() {
-        return null == owner ? identifier.getValue() : owner.getIdentifier().getValue() + "." + identifier.getValue();
+        return null == owner
+                ? identifier.getValue()
+                : String.join(".", owner.getIdentifier().getValue(), identifier.getValue());
     }
     
     @Override
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/column/ColumnSegmentTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/column/ColumnSegmentTest.java
index bab776c2b9e..a44f49eb8ad 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/column/ColumnSegmentTest.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/column/ColumnSegmentTest.java
@@ -65,4 +65,12 @@ public final class ColumnSegmentTest {
         actual.setOwner(new OwnerSegment(0, 0, new IdentifierValue("`tbl`")));
         assertThat(actual.getQualifiedName(), is("`tbl`.`col`"));
     }
+
+    @Test
+    public void assertGetExpression() {
+        ColumnSegment actual = new ColumnSegment(0, 0, new IdentifierValue("`col`"));
+        assertThat(actual.getExpression(), is("col"));
+        actual.setOwner(new OwnerSegment(0, 0, new IdentifierValue("`tbl`")));
+        assertThat(actual.getExpression(), is("tbl.col"));
+    }
 }