diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java index da1492c2537c04..685430cd5c3c86 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java @@ -362,4 +362,14 @@ public Set computeInputSlotIds(Analyzer analyzer) throws NotImplementedE } return result; } + + @Override + public void finalize(Analyzer analyzer) throws UserException { + super.finalize(analyzer); + List groupingExprs = aggInfo.getGroupingExprs(); + for (int i = 0; i < groupingExprs.size(); i++) { + aggInfo.getOutputTupleDesc().getSlots().get(i).setIsNullable(groupingExprs.get(i).isNullable()); + aggInfo.getOutputTupleDesc().computeMemLayout(); + } + } } diff --git a/regression-test/data/query_p0/aggregate/nullablity_consistency.out b/regression-test/data/query_p0/aggregate/nullablity_consistency.out new file mode 100644 index 00000000000000..e011475a94c738 --- /dev/null +++ b/regression-test/data/query_p0/aggregate/nullablity_consistency.out @@ -0,0 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +\N + diff --git a/regression-test/suites/query_p0/aggregate/nullablity_consistency.groovy b/regression-test/suites/query_p0/aggregate/nullablity_consistency.groovy new file mode 100644 index 00000000000000..6f4cc1a4a91336 --- /dev/null +++ b/regression-test/suites/query_p0/aggregate/nullablity_consistency.groovy @@ -0,0 +1,63 @@ +// 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_nullability_consistency") { + sql """DROP TABLE IF EXISTS t114;""" + sql """CREATE TABLE t114 (col1 varchar(11451) not null, col2 int not null, col3 int not null) + UNIQUE KEY(col1) + DISTRIBUTED BY HASH(col1) + BUCKETS 3 + PROPERTIES( + "replication_num"="1", + "enable_unique_key_merge_on_write"="true" + );""" + sql """insert into t114 values('1994',1644, 1994);""" + + sql """DROP TABLE IF EXISTS t115;""" + sql """CREATE TABLE t115 (col1 varchar(32) not null, col2 int not null, col3 int not null, col4 int not null) + DISTRIBUTED BY HASH(col3) + BUCKETS 3 + PROPERTIES( + "replication_num"="1" + );""" + + sql """insert into t115 values("1994", 1994, 1995, 1996);""" + + qt_sql """WITH a_cte AS ( + SELECT * + FROM t114 + ) + + SELECT + col1 + FROM ( + SELECT + lower(b.col1) col1 + FROM a_cte a + LEFT JOIN t115 b + ON a.col2=b.col2 + UNION ALL + SELECT + lower(b.col1) col1 + FROM a_cte a + LEFT JOIN t115 b + ON a.col2=b.col2) tt + GROUP BY + col1""" + + +} \ No newline at end of file