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 076dd67347 [fix](grouping)fix grouping function bug (#11861)
076dd67347 is described below
commit 076dd67347c79d57a0604c6905ae5f0b09218936
Author: starocean999 <[email protected]>
AuthorDate: Wed Aug 24 15:05:25 2022 +0800
[fix](grouping)fix grouping function bug (#11861)
---
.../org/apache/doris/analysis/GroupByClause.java | 10 ++-
.../org/apache/doris/analysis/GroupingInfo.java | 15 ----
.../aggregate/aggregate_grouping_function.out | 43 ++++++++++
.../aggregate/aggregate_grouping_function.groovy | 93 ++++++++++++++++++++++
4 files changed, 142 insertions(+), 19 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupByClause.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupByClause.java
index 14d1804e71..faf0fd2626 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupByClause.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupByClause.java
@@ -30,9 +30,7 @@ import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Optional;
import java.util.Set;
-import java.util.stream.Collectors;
/**
* Wraps all information of group by clause. support normal GROUP BY clause
and extended GROUP BY clause like
@@ -286,8 +284,12 @@ public class GroupByClause implements ParseNode {
Analyzer analyzer) {
groupingExprs = Expr.substituteList(groupingExprs, smap, analyzer,
true);
for (VirtualSlotRef vs : groupingSlots) {
-
vs.setRealSlots(Optional.ofNullable(Expr.substituteList(vs.getRealSlots(),
smap, analyzer, true)).orElse(
- new ArrayList<>()).stream().map(e -> (SlotRef)
e).collect(Collectors.toList()));
+ ArrayList<Expr> exprs = Expr.substituteList(vs.getRealSlots(),
smap, analyzer, true);
+ if (exprs != null) {
+ vs.setRealSlots(exprs);
+ } else {
+ vs.setRealSlots(new ArrayList<Expr>());
+ }
}
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupingInfo.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupingInfo.java
index e153c5f929..b7ba987cc6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupingInfo.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupingInfo.java
@@ -17,7 +17,6 @@
package org.apache.doris.analysis;
-import org.apache.doris.catalog.Table;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
@@ -270,20 +269,6 @@ public class GroupingInfo {
public void substituteGroupingFn(Expr expr, Analyzer analyzer) throws
AnalysisException {
if (expr instanceof GroupingFunctionCallExpr) {
- // TODO(yangzhengguo) support expression in grouping functions
- for (Expr child: expr.getChildren()) {
- if (!(child instanceof SlotRef)) {
- throw new AnalysisException("grouping functions only
support column in current version.");
- // expr from inline view
- } else if (((SlotRef)
child).getDesc().getParent().getTable().getType()
- == Table.TableType.INLINE_VIEW) {
- InlineViewRef ref = (InlineViewRef) ((SlotRef)
child).getDesc().getParent().getRef();
- int colIndex = ref.getColLabels().indexOf(((SlotRef)
child).getColumnName());
- if (colIndex != -1 &&
!(ref.getViewStmt().getResultExprs().get(colIndex) instanceof SlotRef)) {
- throw new AnalysisException("grouping functions only
support column in current version.");
- }
- }
- }
// if is substituted skip
if (expr.getChildren().size() == 1 && expr.getChild(0) instanceof
VirtualSlotRef) {
return;
diff --git
a/regression-test/data/query/aggregate/aggregate_grouping_function.out
b/regression-test/data/query/aggregate/aggregate_grouping_function.out
new file mode 100644
index 0000000000..292966bd15
--- /dev/null
+++ b/regression-test/data/query/aggregate/aggregate_grouping_function.out
@@ -0,0 +1,43 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !select --
+1 2022-08-01 \N 6
+0 2022-08-01 aaa 2
+0 2022-08-01 bbb 2
+0 2022-08-01 ccc 2
+1 2022-08-02 \N 6
+0 2022-08-02 aaa 2
+0 2022-08-02 bbb 2
+0 2022-08-02 ccc 2
+1 2022-08-03 \N 6
+0 2022-08-03 aaa 2
+0 2022-08-03 bbb 2
+0 2022-08-03 ccc 2
+
+-- !select --
+1 2022-08-01 \N 6
+0 2022-08-01 aaa 2
+0 2022-08-01 bbb 2
+0 2022-08-01 ccc 2
+1 2022-08-02 \N 6
+0 2022-08-02 aaa 2
+0 2022-08-02 bbb 2
+0 2022-08-02 ccc 2
+1 2022-08-03 \N 6
+0 2022-08-03 aaa 2
+0 2022-08-03 bbb 2
+0 2022-08-03 ccc 2
+
+-- !select --
+1 2022-08-01 \N 6
+0 2022-08-01 aaa 2
+0 2022-08-01 bbb 2
+0 2022-08-01 ccc 2
+1 2022-08-02 \N 6
+0 2022-08-02 aaa 2
+0 2022-08-02 bbb 2
+0 2022-08-02 ccc 2
+1 2022-08-03 \N 6
+0 2022-08-03 aaa 2
+0 2022-08-03 bbb 2
+0 2022-08-03 ccc 2
+
diff --git
a/regression-test/suites/query/aggregate/aggregate_grouping_function.groovy
b/regression-test/suites/query/aggregate/aggregate_grouping_function.groovy
new file mode 100644
index 0000000000..e371fb2d86
--- /dev/null
+++ b/regression-test/suites/query/aggregate/aggregate_grouping_function.groovy
@@ -0,0 +1,93 @@
+// 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("aggregate_grouping_function") {
+ sql "DROP TABLE IF EXISTS test_aggregate_grouping_function"
+
+ sql """
+ CREATE TABLE `test_aggregate_grouping_function` (
+ `dt_date` varchar(1000) NULL COMMENT "",
+ `name` varchar(1000) NULL COMMENT "",
+ `num1` bigint(20) SUM NOT NULL COMMENT "",
+ `num2` bigint(20) SUM NOT NULL COMMENT ""
+ ) ENGINE=OLAP
+ AGGREGATE KEY(`dt_date`, `name`)
+ COMMENT "OLAP"
+ DISTRIBUTED BY HASH(`dt_date`) BUCKETS 32
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1",
+ "in_memory" = "false",
+ "storage_format" = "V2"
+ )
+ ;
+ """
+
+ sql """INSERT INTO test_aggregate_grouping_function values ('2022-08-01',
"aaa", 1,2),('2022-08-01', "bbb", 1,2),('2022-08-01', "ccc", 1,2),
+ ('2022-08-02', "aaa", 1,2),('2022-08-02', "bbb",
1,2),('2022-08-02', "ccc", 1,2),('2022-08-03', "aaa", 1,2),
+ ('2022-08-03', "bbb", 1,2),('2022-08-03', "ccc", 1,2);"""
+
+ qt_select """
+ WITH base_table AS (
+ SELECT dt_date, name, sum(num1) AS sum1
+ , sum(num2) AS sum2
+ , sum(num1) / sum(num2) AS ratio
+ FROM test_aggregate_grouping_function
+ GROUP BY dt_date, name
+ )
+ SELECT grouping_id(sum1), dt_date, name
+ , sum(sum2)
+ FROM base_table
+ GROUP BY GROUPING SETS ((dt_date), (dt_date, name, sum1))
+ ORDER BY dt_date, name;
+ """
+
+ qt_select """
+ WITH base_table AS (
+ SELECT dt_date, name, sum(num1) AS sum1
+ , sum(num2) AS sum2
+ , sum(num1) / sum(num2) AS ratio
+ FROM test_aggregate_grouping_function
+ GROUP BY dt_date, name
+ )
+ SELECT grouping_id(ratio), dt_date, name
+ , sum(sum2)
+ FROM base_table
+ GROUP BY GROUPING SETS ((dt_date), (dt_date, name, ratio))
+ ORDER BY dt_date, name;
+ """
+
+ qt_select """
+ WITH base_table AS (
+ SELECT dt_date, name, sum(num1) AS sum1
+ , sum(num2) AS sum2
+ , sum(num1) / sum(num2) AS ratio
+ FROM test_aggregate_grouping_function
+ GROUP BY dt_date, name
+ ),
+ base_table2 AS (
+ SELECT *
+ FROM base_table
+ )
+ SELECT grouping_id(ratio), dt_date, name
+ , sum(sum2)
+ FROM base_table2
+ GROUP BY GROUPING SETS ((dt_date), (dt_date, name, ratio))
+ ORDER BY dt_date, name;
+ """
+
+ sql "DROP TABLE test_aggregate_grouping_function"
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]