From fb847a7b279d2398d6c40a9fe0178b4e296b30f5 Mon Sep 17 00:00:00 2001 From: englefly Date: Wed, 13 Sep 2023 01:20:28 +0800 Subject: [PATCH] having --- .../org/apache/doris/analysis/SelectStmt.java | 6 ++- .../suites/query_p0/having/having.groovy | 49 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 regression-test/suites/query_p0/having/having.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java index 0f03afde0afd24..67c2a06a1c85d6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java @@ -1811,10 +1811,12 @@ public void rewriteExprs(ExprRewriter rewriter) throws AnalysisException { whereClause.collect(Subquery.class, subqueryExprs); } - if (havingClause != null) { - havingClause = rewriter.rewrite(havingClause, analyzer); + + if (havingClauseAfterAnalyzed != null) { + havingClauseAfterAnalyzed = rewriter.rewrite(havingClauseAfterAnalyzed, analyzer); havingClauseAfterAnalyzed.collect(Subquery.class, subqueryExprs); } + for (Subquery subquery : subqueryExprs) { subquery.getStatement().rewriteExprs(rewriter); } diff --git a/regression-test/suites/query_p0/having/having.groovy b/regression-test/suites/query_p0/having/having.groovy new file mode 100644 index 00000000000000..2cb0755d5423e7 --- /dev/null +++ b/regression-test/suites/query_p0/having/having.groovy @@ -0,0 +1,49 @@ +// 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. + +// The cases is copied from https://github.com/trinodb/trino/tree/master +// /testing/trino-product-tests/src/main/resources/sql-tests/testcases/aggregate +// and modified by Doris. + +suite("having") { + sql "set enable_nereids_planner=false;" + sql """CREATE TABLE `supplier` ( + `s_suppkey` int(11) NOT NULL, + `s_name` varchar(25) NOT NULL, + `s_address` varchar(40) NOT NULL, + `s_nationkey` int(11) NOT NULL, + `s_phone` varchar(15) NOT NULL, + `s_acctbal` DECIMAL(15, 2) NOT NULL, + `s_comment` varchar(101) NOT NULL + ) ENGINE=OLAP + DUPLICATE KEY(`s_suppkey`) + COMMENT 'OLAP' + DISTRIBUTED BY HASH(`s_suppkey`) BUCKETS 12 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "is_being_synced" = "false", + "storage_format" = "V2", + "light_schema_change" = "true", + "disable_auto_compaction" = "false", + "enable_single_replica_compaction" = "false" + ); """ + sql """explain + select count(*) + from supplier s + group by s_nationkey,s_suppkey + having s_nationkey=1 or s_suppkey=1;""" +} \ No newline at end of file