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 @@ -20,7 +20,6 @@
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable;
import org.apache.doris.nereids.trees.expressions.functions.ComputePrecisionForSum;
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
Expand All @@ -35,7 +34,7 @@
import java.util.List;

/** MultiDistinctSum */
public class MultiDistinctSum extends AggregateFunction implements UnaryExpression, AlwaysNotNullable,
public class MultiDistinctSum extends NullableAggregateFunction implements UnaryExpression,
ExplicitlyCastableSignature, ComputePrecisionForSum, MultiDistinction {

public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
Expand All @@ -45,11 +44,15 @@ public class MultiDistinctSum extends AggregateFunction implements UnaryExpressi
);

public MultiDistinctSum(Expression arg0) {
super("multi_distinct_sum", true, arg0);
super("multi_distinct_sum", true, false, arg0);
}

public MultiDistinctSum(boolean distinct, Expression arg0) {
super("multi_distinct_sum", true, arg0);
super("multi_distinct_sum", true, false, arg0);
}

public MultiDistinctSum(boolean distinct, boolean alwaysNullable, Expression arg0) {
super("multi_distinct_sum", true, alwaysNullable, arg0);
}

@Override
Expand All @@ -64,6 +67,11 @@ public List<FunctionSignature> getSignatures() {
return new Sum(getArgument(0)).getSignatures();
}

@Override
public NullableAggregateFunction withAlwaysNullable(boolean alwaysNullable) {
return new MultiDistinctSum(distinct, alwaysNullable, children.get(0));
}

@Override
public MultiDistinctSum withDistinctAndChildren(boolean distinct, List<Expression> children) {
Preconditions.checkArgument(children.size() == 1);
Expand Down
2 changes: 2 additions & 0 deletions regression-test/data/nereids_syntax_p0/adjust_nullable.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
2
3

-- !distinct_sum --

31 changes: 31 additions & 0 deletions regression-test/suites/nereids_syntax_p0/adjust_nullable.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,36 @@ suite("adjust_nullable") {
order by
subq_1.gid;
"""

sql """
drop table if exists table_7_undef_undef;
"""
sql """
drop table if exists table_8_undef_undef;
"""
sql """
create table table_7_undef_undef (`pk` int,`col_int_undef_signed` int ,`col_varchar_10__undef_signed` varchar(10) ,`col_varchar_1024__undef_signed` varchar(1024) ) engine=olap distributed by hash(pk) buckets 10 properties( 'replication_num' = '1');
"""
sql """
create table table_8_undef_undef (`pk` int,`col_int_undef_signed` int ,`col_varchar_10__undef_signed` varchar(10) ,`col_varchar_1024__undef_signed` varchar(1024) ) engine=olap distributed by hash(pk) buckets 10 properties( 'replication_num' = '1');
"""

sql """
insert into table_7_undef_undef values (0,6,"didn't","was"),(1,1,"mean",'k'),(2,2,'i','i'),(3,null,'y','p'),(4,8,"you're","and"),(5,6,'i','o'),(6,null,"have","not");
"""
sql """
insert into table_8_undef_undef values (0,null,"one",'m'),(1,null,"got",'m'),(2,9,'m','b'),(3,null,"say",'p'),(4,null,'t',"yeah"),(5,null,'y',"because"),(6,null,"from",'q'),(7,null,"the","in");
"""

qt_distinct_sum """
SELECT SUM( DISTINCT alias1 . `col_int_undef_signed` ) AS field1 FROM table_7_undef_undef AS alias1 LEFT JOIN table_8_undef_undef AS alias2 ON alias1 . `col_varchar_1024__undef_signed` = alias2 . `col_varchar_1024__undef_signed` WHERE alias2 . `pk` >= alias2 . `col_int_undef_signed` HAVING field1 <> 8 ORDER BY field1 , field1 ;
"""

sql """
drop table if exists table_7_undef_undef;
"""
sql """
drop table if exists table_8_undef_undef;
"""
}