You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/01/03 06:56:06 UTC

[doris] branch master updated: [fix](nereids)support nulls first/last in order by clause (#15530)

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 8748f65a1b [fix](nereids)support nulls first/last in order by clause (#15530)
8748f65a1b is described below

commit 8748f65a1ba0f9bb70520a66d0709fe1629d95c8
Author: starocean999 <40...@users.noreply.github.com>
AuthorDate: Tue Jan 3 14:56:00 2023 +0800

    [fix](nereids)support nulls first/last in order by clause (#15530)
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |  2 +-
 .../doris/nereids/parser/LogicalPlanBuilder.java   |  3 +-
 .../data/query_p0/keyword/order_group.out          | 55 ++++++++++++++++++++++
 .../suites/query_p0/keyword/order_group.groovy     |  9 ++++
 4 files changed, 66 insertions(+), 3 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 e4b28a0069..6b199654d8 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
@@ -166,7 +166,7 @@ sortClause
     ;
 
 sortItem
-    :  expression ordering = (ASC | DESC)?
+    :  expression ordering = (ASC | DESC)? (NULLS (FIRST | LAST))?
     ;
 
 limitClause
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 551a594ca6..f69d1a86ce 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
@@ -1076,8 +1076,7 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
     public OrderKey visitSortItem(SortItemContext ctx) {
         return ParserUtils.withOrigin(ctx, () -> {
             boolean isAsc = ctx.DESC() == null;
-            // TODO(wj): isNullFirst
-            boolean isNullFirst = true;
+            boolean isNullFirst = ctx.LAST() == null;
             Expression expression = typedVisit(ctx.expression());
             return new OrderKey(expression, isAsc, isNullFirst);
         });
diff --git a/regression-test/data/query_p0/keyword/order_group.out b/regression-test/data/query_p0/keyword/order_group.out
index 9445f24208..5a46327a8b 100644
--- a/regression-test/data/query_p0/keyword/order_group.out
+++ b/regression-test/data/query_p0/keyword/order_group.out
@@ -1392,3 +1392,58 @@ true	0.1
 
 -- !group1 --
 123.123000000
+
+-- !orderBy_withNull_3 --
+\N	\N
+\N	15
+\N	14
+\N	13
+\N	12
+\N	11
+\N	10
+\N	9
+\N	8
+\N	7
+\N	6
+\N	5
+\N	4
+\N	3
+\N	2
+\N	1
+
+-- !orderBy_withNull_3 --
+\N	15
+\N	14
+\N	13
+\N	12
+\N	11
+\N	10
+\N	9
+\N	8
+\N	7
+\N	6
+\N	5
+\N	4
+\N	3
+\N	2
+\N	1
+\N	\N
+
+-- !orderBy_withNull_3 --
+\N	\N
+\N	15
+\N	14
+\N	13
+\N	12
+\N	11
+\N	10
+\N	9
+\N	8
+\N	7
+\N	6
+\N	5
+\N	4
+\N	3
+\N	2
+\N	1
+
diff --git a/regression-test/suites/query_p0/keyword/order_group.groovy b/regression-test/suites/query_p0/keyword/order_group.groovy
index 6e6d3bc9b7..6028e5a529 100644
--- a/regression-test/suites/query_p0/keyword/order_group.groovy
+++ b/regression-test/suites/query_p0/keyword/order_group.groovy
@@ -211,4 +211,13 @@ suite("order_group", "query,p0") {
     qt_group31 "select count(*) from ${tableName1} where (k11='2015-03-13 12:36:38' or k11 = '2000-01-01 00:00:00')\
 		    and k5 is not null group by k1%2, k2%2, k3%3, k4%3, k11%2 order by count(*)"
     qt_group1 "select min(k5) from ${tableName1}"
+    qt_orderBy_withNull_3 " select a.k1 ak1, b.k1 bk1 from ${tableName1} a \
+       right join ${tableName2} b on a.k1=b.k1 and b.k1>10 \
+       order by bk1 desc nulls first, ak1"
+    qt_orderBy_withNull_3 " select a.k1 ak1, b.k1 bk1 from ${tableName1} a \
+       right join ${tableName2} b on a.k1=b.k1 and b.k1>10 \
+       order by bk1 desc nulls last, ak1"
+    qt_orderBy_withNull_3 " select a.k1 ak1, b.k1 bk1 from ${tableName1} a \
+       right join ${tableName2} b on a.k1=b.k1 and b.k1>10 \
+       order by bk1 desc, ak1"
 }


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