Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(query): fix array_agg failed if the argument is NULL #17244

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 6 additions & 6 deletions src/query/functions/src/aggregates/aggregate_array_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,12 @@ pub fn try_create_aggregate_array_agg_function(
) -> Result<Arc<dyn AggregateFunction>> {
assert_unary_arguments(display_name, argument_types.len())?;
let data_type = argument_types[0].clone();
let nullable = data_type.is_nullable();
let is_nullable = data_type.is_nullable_or_null();
let return_type = DataType::Array(Box::new(data_type.clone()));

with_simple_no_number_mapped_type!(|T| match data_type.remove_nullable() {
DataType::T => {
if nullable {
if is_nullable {
type State = NullableArrayAggState<T>;
AggregateArrayAggFunction::<T, State>::try_create(display_name, return_type)
} else {
Expand All @@ -434,7 +434,7 @@ pub fn try_create_aggregate_array_agg_function(
DataType::Number(num_type) => {
with_number_mapped_type!(|NUM| match num_type {
NumberDataType::NUM => {
if nullable {
if is_nullable {
type State = NullableArrayAggState<NumberType<NUM>>;
AggregateArrayAggFunction::<NumberType<NUM>, State>::try_create(
display_name,
Expand All @@ -451,7 +451,7 @@ pub fn try_create_aggregate_array_agg_function(
})
}
DataType::Decimal(DecimalDataType::Decimal128(_)) => {
if nullable {
if is_nullable {
type State = NullableArrayAggState<DecimalType<i128>>;
AggregateArrayAggFunction::<DecimalType<i128>, State>::try_create(
display_name,
Expand All @@ -466,7 +466,7 @@ pub fn try_create_aggregate_array_agg_function(
}
}
DataType::Decimal(DecimalDataType::Decimal256(_)) => {
if nullable {
if is_nullable {
type State = NullableArrayAggState<DecimalType<i256>>;
AggregateArrayAggFunction::<DecimalType<i256>, State>::try_create(
display_name,
Expand All @@ -481,7 +481,7 @@ pub fn try_create_aggregate_array_agg_function(
}
}
_ => {
if nullable {
if is_nullable {
type State = NullableArrayAggState<AnyType>;
AggregateArrayAggFunction::<AnyType, State>::try_create(display_name, return_type)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ select string_agg(s, '|') from t3;
----
abc|def|xyz

query TT
select array_agg(s), array_agg(null) from t3;
----
['abc','def',NULL,'xyz'] [NULL,NULL,NULL,NULL]

statement ok
create table aggavg(shopid string, goodsid string, avgcostvalue decimal(16, 8), sdate_rn uint64, md string)

Expand Down Expand Up @@ -424,6 +429,11 @@ select json_object_agg(b, a), json_object_agg(b, c), json_object_agg(b, d), json
----
{"abc":20.0,"de":10.0,"xyz":5.99} {"de":100,"xyz":300} {"abc":{"k":"v"},"de":null,"xyz":[1,2,3]} {"abc":["a","b"],"de":[],"xyz":["z"]} {"abc":"a","de":"a","xyz":"a"}

query TTTTT
select array_agg(a), array_agg(b), array_agg(c), array_agg(d), array_agg(e), array_agg('a') from d
----
[20.00,10.00,4.23,5.99] ['abc','de',NULL,'xyz'] [NULL,100,200,300] ['{"k":"v"}','null','"uvw"','[1,2,3]'] [['a','b'],[],['x','y'],['z']] ['a','a','a','a']

statement ok
DROP TABLE d

Expand Down
Loading