This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch dev-1.1.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/dev-1.1.2 by this push:
new d1ad2f75b3 [fix](orderby)remove useless null literal in order by
(#11821)
d1ad2f75b3 is described below
commit d1ad2f75b3f50f866e1d817d6d9b0a322f9f3090
Author: starocean999 <[email protected]>
AuthorDate: Thu Aug 18 10:10:25 2022 +0800
[fix](orderby)remove useless null literal in order by (#11821)
---
fe/fe-core/src/main/cup/sql_parser.cup | 8 +++--
.../java/org/apache/doris/qe/StmtExecutor.java | 12 +++++++
.../data/query/test_orderby_nullliteral.out | 5 +++
.../suites/query/test_orderby_nullliteral.groovy | 38 ++++++++++++++++++++++
4 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup
b/fe/fe-core/src/main/cup/sql_parser.cup
index 65662f1e2d..9752b9ee08 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -4496,12 +4496,16 @@ order_by_elements ::=
order_by_element:e
{:
ArrayList<OrderByElement> list = new ArrayList<OrderByElement>();
- list.add(e);
+ if (!(e.getExpr() instanceof NullLiteral)) {
+ list.add(e);
+ }
RESULT = list;
:}
| order_by_elements:list COMMA order_by_element:e
{:
- list.add(e);
+ if (!(e.getExpr() instanceof NullLiteral)) {
+ list.add(e);
+ }
RESULT = list;
:}
;
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
index e874358d08..da7e7a9821 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -666,6 +666,18 @@ public class StmtExecutor implements ProfileWriter {
}
private void analyzeAndGenerateQueryPlan(TQueryOptions tQueryOptions)
throws UserException {
+ if (parsedStmt instanceof QueryStmt || parsedStmt instanceof
InsertStmt) {
+ QueryStmt queryStmt = null;
+ if (parsedStmt instanceof QueryStmt) {
+ queryStmt = (QueryStmt) parsedStmt;
+ }
+ if (parsedStmt instanceof InsertStmt) {
+ queryStmt = (QueryStmt) ((InsertStmt)
parsedStmt).getQueryStmt();
+ }
+ if (queryStmt.getOrderByElements() != null &&
queryStmt.getOrderByElements().isEmpty()) {
+ queryStmt.removeOrderByElements();
+ }
+ }
parsedStmt.analyze(analyzer);
if (parsedStmt instanceof QueryStmt || parsedStmt instanceof
InsertStmt) {
ExprRewriter rewriter = analyzer.getExprRewriter();
diff --git a/regression-test/data/query/test_orderby_nullliteral.out
b/regression-test/data/query/test_orderby_nullliteral.out
new file mode 100644
index 0000000000..bd4e137a52
--- /dev/null
+++ b/regression-test/data/query/test_orderby_nullliteral.out
@@ -0,0 +1,5 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !select --
+1 hello 2022-07-04 1.23 hello
+2 \N \N \N hello
+
diff --git a/regression-test/suites/query/test_orderby_nullliteral.groovy
b/regression-test/suites/query/test_orderby_nullliteral.groovy
new file mode 100644
index 0000000000..fe11c778af
--- /dev/null
+++ b/regression-test/suites/query/test_orderby_nullliteral.groovy
@@ -0,0 +1,38 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("orderby_nullliteral", "query") {
+
+ def tableName = "test_orderby_nullliteral"
+ sql "DROP TABLE IF EXISTS ${tableName}"
+ sql """
+ CREATE TABLE IF NOT EXISTS ${tableName} (
+ c_int INT,
+ c_string VARCHAR(10),
+ c_date Date,
+ c_decimal DECIMAL(10, 2),
+ c_string_not_null VARCHAR(10) NOT NULL
+ )
+ DISTRIBUTED BY HASH(c_int) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1"
+ )
+ """
+ sql "INSERT INTO ${tableName} values(1,'hello','2022-07-04',1.23,'hello'),
(2,NULL,NULL,NULL,'hello')"
+
+ qt_select "select * from ${tableName} order by null"
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]