From 6bd790c636395279979d202e8e3cc5ff994e3d1a Mon Sep 17 00:00:00 2001 From: baishen Date: Fri, 10 Jan 2025 16:37:39 +0800 Subject: [PATCH 1/3] fix(query): fix `array_agg` failed if the argument is NULL --- .../functions/src/aggregates/aggregate_array_agg.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/query/functions/src/aggregates/aggregate_array_agg.rs b/src/query/functions/src/aggregates/aggregate_array_agg.rs index 28218078ea2d..7400d75d8db0 100644 --- a/src/query/functions/src/aggregates/aggregate_array_agg.rs +++ b/src/query/functions/src/aggregates/aggregate_array_agg.rs @@ -418,12 +418,12 @@ pub fn try_create_aggregate_array_agg_function( ) -> Result> { 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; AggregateArrayAggFunction::::try_create(display_name, return_type) } else { @@ -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>; AggregateArrayAggFunction::, State>::try_create( display_name, @@ -451,7 +451,7 @@ pub fn try_create_aggregate_array_agg_function( }) } DataType::Decimal(DecimalDataType::Decimal128(_)) => { - if nullable { + if is_nullable { type State = NullableArrayAggState>; AggregateArrayAggFunction::, State>::try_create( display_name, @@ -466,7 +466,7 @@ pub fn try_create_aggregate_array_agg_function( } } DataType::Decimal(DecimalDataType::Decimal256(_)) => { - if nullable { + if is_nullable { type State = NullableArrayAggState>; AggregateArrayAggFunction::, State>::try_create( display_name, @@ -481,7 +481,7 @@ pub fn try_create_aggregate_array_agg_function( } } _ => { - if nullable { + if is_nullable { type State = NullableArrayAggState; AggregateArrayAggFunction::::try_create(display_name, return_type) } else { From 475ef9e04fee825aded13b336a42a388e970284f Mon Sep 17 00:00:00 2001 From: baishen Date: Fri, 10 Jan 2025 16:41:11 +0800 Subject: [PATCH 2/3] add tests --- .../functions/02_0000_function_aggregate_mix.test | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/sqllogictests/suites/query/functions/02_0000_function_aggregate_mix.test b/tests/sqllogictests/suites/query/functions/02_0000_function_aggregate_mix.test index b170af49fb42..e07ee66404f7 100644 --- a/tests/sqllogictests/suites/query/functions/02_0000_function_aggregate_mix.test +++ b/tests/sqllogictests/suites/query/functions/02_0000_function_aggregate_mix.test @@ -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) @@ -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 From 88786e11389d7d9f05ab2332b0186d8b74ec1157 Mon Sep 17 00:00:00 2001 From: baishen Date: Fri, 10 Jan 2025 20:03:58 +0800 Subject: [PATCH 3/3] fmt mysql source sql --- tests/sqllogictests/src/util.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/sqllogictests/src/util.rs b/tests/sqllogictests/src/util.rs index 7001343acac8..c985d6151f4a 100644 --- a/tests/sqllogictests/src/util.rs +++ b/tests/sqllogictests/src/util.rs @@ -407,7 +407,13 @@ async fn run_mysql_server(docker: &Docker) -> Result> { loop { let mysql_res = Mysql::default() .with_init_sql( - "CREATE TABLE test.user(id INT, name VARCHAR(100), age SMALLINT UNSIGNED, salary DOUBLE, active BOOL); INSERT INTO test.user VALUES(1, 'Alice', 24, 100, true), (2, 'Bob', 35, 200.1, false), (3, 'Lily', 41, 1000.2, true), (4, 'Tom', 55, 3000.55, false), (5, NULL, NULL, NULL, NULL);" + "CREATE TABLE test.user(id INT, name VARCHAR(100), age SMALLINT UNSIGNED, salary DOUBLE, active BOOL); \ + INSERT INTO test.user VALUES \ + (1, 'Alice', 24, 100, true), \ + (2, 'Bob', 35, 200.1, false), \ + (3, 'Lily', 41, 1000.2, true), \ + (4, 'Tom', 55, 3000.55, false), \ + (5, NULL, NULL, NULL, NULL);" .to_string() .into_bytes(), )