This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 68aa4867b0 [fix](map_agg) lost scale information for decimal type (#23776) 68aa4867b0 is described below commit 68aa4867b090719316696a2aaaf1b9dc2b69398b Author: Jerry Hu <mrh...@gmail.com> AuthorDate: Sat Sep 2 08:03:33 2023 +0800 [fix](map_agg) lost scale information for decimal type (#23776) --- .../aggregate_functions/aggregate_function_map.h | 11 ++-- .../apache/doris/analysis/FunctionCallExpr.java | 4 ++ .../data/query_p0/aggregate/map_agg.out | 9 +++- .../suites/query_p0/aggregate/map_agg.groovy | 58 +++++++++++++++++++--- 4 files changed, 69 insertions(+), 13 deletions(-) diff --git a/be/src/vec/aggregate_functions/aggregate_function_map.h b/be/src/vec/aggregate_functions/aggregate_function_map.h index d04f85973b..057012f8b7 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_map.h +++ b/be/src/vec/aggregate_functions/aggregate_function_map.h @@ -225,13 +225,14 @@ public: const size_t num_rows, Arena* arena) const override { auto& col = assert_cast<ColumnMap&>(*dst); for (size_t i = 0; i != num_rows; ++i) { - Map map(2); - columns[0]->get(i, map[0]); - if (map[0].is_null()) { + Field key, value; + columns[0]->get(i, key); + if (key.is_null()) { continue; } - columns[1]->get(i, map[1]); - col.insert(map); + + columns[1]->get(i, value); + col.insert(Map {Array {key}, Array {value}}); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index c9af3ed874..480877e666 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -1550,6 +1550,10 @@ public class FunctionCallExpr extends Expr { fn.setReturnType(new ArrayType(getChild(0).type)); } + if (fnName.getFunction().equalsIgnoreCase("map_agg")) { + fn.setReturnType(new MapType(getChild(0).type, getChild(1).type)); + } + if (fnName.getFunction().equalsIgnoreCase("group_uniq_array") || fnName.getFunction().equalsIgnoreCase("group_array")) { fn.setReturnType(new ArrayType(getChild(0).type)); diff --git a/regression-test/data/query_p0/aggregate/map_agg.out b/regression-test/data/query_p0/aggregate/map_agg.out index 62c8ecc101..ebe4099c2d 100644 --- a/regression-test/data/query_p0/aggregate/map_agg.out +++ b/regression-test/data/query_p0/aggregate/map_agg.out @@ -13,13 +13,18 @@ 4 V4_1 V4_2 \N 5 V5_1 V5_2 V5_3 --- !sql2 -- +-- !sql3 -- 1 V1_1 V1_2 V1_3 2 V2_1 V2_2 V2_3 3 V3_1 V3_2 V3_3 4 V4_1 V4_2 V4_3 5 V5_1 V5_2 V5_3 --- !sql3 -- +-- !sql4 -- {"key":["ab", "efg", NULL]} +-- !sql5 -- +1 1.2345 2.4567 5.9876 +2 2.4567 3.3300 4.5500 +3 188.9980 998.9960 1024.1024 + diff --git a/regression-test/suites/query_p0/aggregate/map_agg.groovy b/regression-test/suites/query_p0/aggregate/map_agg.groovy index 2337f2fcea..a29ee5003f 100644 --- a/regression-test/suites/query_p0/aggregate/map_agg.groovy +++ b/regression-test/suites/query_p0/aggregate/map_agg.groovy @@ -127,7 +127,39 @@ suite("map_agg") { (5, 1, "V5_1"), (5, 9223372036854775807, "V5_2"), (5, 22000000000, "V5_3"); - """ + """ + + sql "DROP TABLE IF EXISTS `test_map_agg_decimal`;" + sql """ + CREATE TABLE `test_map_agg_decimal` ( + `id` int(11) NOT NULL, + `label_name` string NOT NULL, + `value_field` decimal(15,4) + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + COMMENT 'OLAP' + DISTRIBUTED BY HASH(`id`) BUCKETS 2 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "storage_format" = "V2", + "light_schema_change" = "true", + "disable_auto_compaction" = "false", + "enable_single_replica_compaction" = "false" + ); + """ + + sql """ + insert into `test_map_agg_decimal` values + (1, "k1", 1.2345), + (1, "k2", 2.4567), + (1, "k3", 5.9876), + (2, "k1", 2.4567), + (2, "k2", 3.33), + (2, "k3", 4.55), + (3, "k1", 188.998), + (3, "k2", 998.996), + (3, "k3", 1024.1024) + """ qt_sql1 """ WITH `labels` as ( @@ -155,7 +187,7 @@ suite("map_agg") { ORDER BY `id`; """ - qt_sql2 """ + qt_sql3 """ WITH `labels` as ( SELECT `id`, map_agg(`label_name`, `value_field`) m FROM test_map_agg_numeric_key GROUP BY `id` ) @@ -168,11 +200,25 @@ suite("map_agg") { ORDER BY `id`; """ - qt_sql3 """ + qt_sql4 """ select map_agg(k, v) from (select 'key' as k, array('ab', 'efg', null) v) a; """ - sql "DROP TABLE `test_map_agg`" - sql "DROP TABLE `test_map_agg_nullable`" - sql "DROP TABLE `test_map_agg_numeric_key`" + qt_sql5 """ + WITH `labels` as ( + SELECT `id`, map_agg(`label_name`, `value_field`) m FROM test_map_agg_decimal GROUP BY `id` + ) + SELECT + id, + m["k1"] LA, + m["k2"] LB, + m["k3"] LC + FROM `labels` + ORDER BY `id`; + """ + + sql "DROP TABLE IF EXISTS `test_map_agg`" + sql "DROP TABLE IF EXISTS `test_map_agg_nullable`" + sql "DROP TABLE IF EXISTS `test_map_agg_numeric_key`" + sql "DROP TABLE IF EXISTS `test_map_agg_decimal`" } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org