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 1da4ec60204 Handling of star in select statement in postgresql (#18979)
1da4ec60204 is described below

commit 1da4ec60204826dc4b417fcdeac4801e08819df6
Author: RunQi Zhao <[email protected]>
AuthorDate: Sun Jul 10 18:09:21 2022 +0800

    Handling of star in select statement in postgresql (#18979)
    
    * alias of star
---
 .../src/main/antlr4/imports/postgresql/DMLStatement.g4        |  1 +
 .../visitor/statement/impl/PostgreSQLStatementSQLVisitor.java |  3 +++
 .../common/segment/dml/item/ShorthandProjectionSegment.java   | 11 ++++++++++-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
index f762d1fe3ba..5ca159e9e0c 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/antlr4/imports/postgresql/DMLStatement.g4
@@ -275,6 +275,7 @@ targetEl
     | aExpr identifier
     | aExpr
     | ASTERISK_
+    | colId DOT_ASTERISK_ AS identifier
     ;
 
 groupClause
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
index c8cc7d2d1bd..12b090e6209 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLStatementSQLVisitor.java
@@ -938,6 +938,9 @@ public abstract class PostgreSQLStatementSQLVisitor extends 
PostgreSQLStatementP
         if (null != ctx.DOT_ASTERISK_()) {
             ShorthandProjectionSegment shorthandProjection = new 
ShorthandProjectionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
             shorthandProjection.setOwner(new 
OwnerSegment(ctx.colId().start.getStartIndex(), 
ctx.colId().stop.getStopIndex(), new IdentifierValue(ctx.colId().getText())));
+            if (null != ctx.identifier()) {
+                shorthandProjection.setAlias(new 
AliasSegment(ctx.identifier().start.getStartIndex(), 
ctx.identifier().stop.getStopIndex(), new 
IdentifierValue(ctx.identifier().getText())));
+            }
             return shorthandProjection;
         }
         AExprContext expr = ctx.aExpr();
diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/item/ShorthandProjectionSegment.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/item/ShorthandProjectionSegment.java
index a7e504dcb35..2127c09360f 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/item/ShorthandProjectionSegment.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/dml/item/ShorthandProjectionSegment.java
@@ -20,6 +20,8 @@ package 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item;
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 import lombok.Setter;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasAvailable;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerAvailable;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
 
@@ -31,7 +33,7 @@ import java.util.Optional;
 @RequiredArgsConstructor
 @Getter
 @Setter
-public final class ShorthandProjectionSegment implements ProjectionSegment, 
OwnerAvailable {
+public final class ShorthandProjectionSegment implements ProjectionSegment, 
OwnerAvailable, AliasAvailable {
     
     private final int startIndex;
     
@@ -39,8 +41,15 @@ public final class ShorthandProjectionSegment implements 
ProjectionSegment, Owne
     
     private OwnerSegment owner;
     
+    private AliasSegment alias;
+    
     @Override
     public Optional<OwnerSegment> getOwner() {
         return Optional.ofNullable(owner);
     }
+    
+    @Override
+    public Optional<String> getAlias() {
+        return null == alias ? Optional.empty() : 
Optional.ofNullable(alias.getIdentifier().getValue());
+    }
 }

Reply via email to