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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3398044d6e4 [feature](nereids) support join with joinRelation (#30909)
3398044d6e4 is described below

commit 3398044d6e4b2462edb87bec954efa4a2074511d
Author: starocean999 <40539150+starocean...@users.noreply.github.com>
AuthorDate: Mon Feb 26 14:32:46 2024 +0800

    [feature](nereids) support join with joinRelation (#30909)
---
 .../main/antlr4/org/apache/doris/nereids/DorisParser.g4    |  9 +++++++--
 .../apache/doris/nereids/parser/LogicalPlanBuilder.java    | 14 ++++++++++++--
 regression-test/data/nereids_p0/subquery/test_subquery.out |  3 +++
 .../suites/nereids_p0/subquery/test_subquery.groovy        |  6 ++++++
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index 73933fd86b8..cb34af20e62 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -71,7 +71,7 @@ statementBase
         whereClause                                                    #update
     | explain? cte? DELETE FROM tableName=multipartIdentifier
         partitionSpec? tableAlias
-        (USING relation (COMMA relation)*)?
+        (USING relations)?
         whereClause?                                                   #delete
     | LOAD LABEL lableName=identifier
         LEFT_PAREN dataDescs+=dataDesc (COMMA dataDescs+=dataDesc)* RIGHT_PAREN
@@ -333,7 +333,11 @@ whereClause
     ;
 
 fromClause
-    : FROM relation (COMMA relation)*
+    : FROM relations
+    ;
+
+relations
+    : relation (COMMA relation)*
     ;
 
 relation
@@ -451,6 +455,7 @@ relationPrimary
     | tvfName=identifier LEFT_PAREN
       (properties=propertyItemList)?
       RIGHT_PAREN tableAlias                                               
#tableValuedFunction
+    | LEFT_PAREN relations RIGHT_PAREN                                     
#relationList
     ;
 
 materializedViewName
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index 550785999f4..e8e6bf828da 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -805,7 +805,7 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
                 StatementScopeIdGenerator.newRelationId(), 
visitMultipartIdentifier(ctx.tableName)));
         query = withTableAlias(query, ctx.tableAlias());
         if (ctx.fromClause() != null) {
-            query = withRelations(query, ctx.fromClause().relation());
+            query = withRelations(query, 
ctx.fromClause().relations().relation());
         }
         query = withFilter(query, Optional.of(ctx.whereClause()));
         String tableAlias = null;
@@ -836,7 +836,7 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
             return new DeleteFromCommand(tableName, tableAlias, 
partitionSpec.first, partitionSpec.second, query);
         } else {
             // convert to insert into select
-            query = withRelations(query, ctx.relation());
+            query = withRelations(query, ctx.relations().relation());
             query = withFilter(query, Optional.ofNullable(ctx.whereClause()));
             Optional<LogicalPlan> cte = Optional.empty();
             if (ctx.cte() != null) {
@@ -2248,9 +2248,19 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
 
     @Override
     public LogicalPlan visitFromClause(FromClauseContext ctx) {
+        return ParserUtils.withOrigin(ctx, () -> 
visitRelations(ctx.relations()));
+    }
+
+    @Override
+    public LogicalPlan visitRelations(DorisParser.RelationsContext ctx) {
         return ParserUtils.withOrigin(ctx, () -> withRelations(null, 
ctx.relation()));
     }
 
+    @Override
+    public LogicalPlan visitRelationList(DorisParser.RelationListContext ctx) {
+        return ParserUtils.withOrigin(ctx, () -> withRelations(null, 
ctx.relations().relation()));
+    }
+
     /* 
********************************************************************************************
      * Table Identifier parsing
      * 
********************************************************************************************
 */
diff --git a/regression-test/data/nereids_p0/subquery/test_subquery.out 
b/regression-test/data/nereids_p0/subquery/test_subquery.out
index 004aa0bcad0..a8d6064680d 100644
--- a/regression-test/data/nereids_p0/subquery/test_subquery.out
+++ b/regression-test/data/nereids_p0/subquery/test_subquery.out
@@ -30,3 +30,6 @@ true  15      1992    3021    11011920        0.000   true    
9999-12-12      2015-04-02T00:00                3.141592653     2
 1      9
 2      \N
 
+-- !select_sub2 --
+9
+
diff --git a/regression-test/suites/nereids_p0/subquery/test_subquery.groovy 
b/regression-test/suites/nereids_p0/subquery/test_subquery.groovy
index 36a863a211d..aa94e91e8db 100644
--- a/regression-test/suites/nereids_p0/subquery/test_subquery.groovy
+++ b/regression-test/suites/nereids_p0/subquery/test_subquery.groovy
@@ -244,6 +244,12 @@ suite("test_subquery") {
     sql """insert into table_9_undef_undef values 
(0,3,"his",'g'),(1,8,'p','n'),(2,null,"get","got"),(3,3,'r','r'),(4,null,"or","get"),(5,0,'j',"yeah"),(6,null,'w','x'),(7,8,'q',"for"),(8,3,'p',"that");"""
 
     qt_select_sub"""SELECT DISTINCT alias1.`pk` AS field1,     
alias2.`col_int_undef_signed` AS field2 FROM table_23_undef_undef AS alias1,    
 table_20_undef_undef AS alias2 WHERE (         EXISTS (             SELECT 
DISTINCT SQ1_alias1.`col_varchar_10__undef_signed` AS SQ1_field1             
FROM table_9_undef_undef AS SQ1_alias1             WHERE 
SQ1_alias1.`col_varchar_10__undef_signed` = 
alias1.`col_varchar_10__undef_signed`             )         )     OR 
alias1.`col_varchar_1024__ [...]
+    qt_select_sub2 """select count(*) from table_9_undef_undef SQ1_alias1
+                        LEFT JOIN ( table_20_undef_undef AS SQ1_alias2 RIGHT 
OUTER
+                        JOIN table_23_undef_undef AS SQ1_alias3
+                            ON SQ1_alias3.`pk` = SQ1_alias2.`pk` )
+                            ON SQ1_alias1.`pk` = SQ1_alias2.`pk`;"""
+
     sql """drop table if exists table_23_undef_undef"""
     sql """drop table if exists table_20_undef_undef"""
     sql """drop table if exists table_9_undef_undef"""


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to