Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public Rule build() {
((Avg) function).child()));
Count count = (Count) TypeCoercionUtils.processBoundFunction(
new Count(true, ((Avg) function).child()));
Expression divide = TypeCoercionUtils.processDivide(new Divide(sum, count));
Expression divide = TypeCoercionUtils.castIfNotSameType(TypeCoercionUtils.processDivide(
new Divide(sum, count)), function.getDataType());
if (!function.nullable() && divide.nullable()) {
// add NonNullable to ensure the result of divide is not nullable,
// otherwise AdjustNullable rule will throw exception
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !ctas --
135.55 67.7750

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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("avg_distinct_to_sum_div_count") {
sql "drop table if exists t1;"
sql """ create table t1 (
pk int,
c1 decimal(12,2) not null)
properties("replication_num" = "1");"""

sql "insert into t1 values(1,12.32),(2,123.23);"
sql "drop table if exists testctas;"
sql """create table testctas properties("replication_num" = "1") select sum(distinct c1),avg(distinct c1) from t1;"""
qt_ctas "select * from testctas;"
}