This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push: new fd11a6b493 [fix][feature](Function) fix return type && support hll_union_agg/group_concat agg to window function (#9119) fd11a6b493 is described below commit fd11a6b493d9465fb82b6309bb90e638cbe8ae5d Author: zhangstar333 <87313068+zhangstar...@users.noreply.github.com> AuthorDate: Sat May 7 20:44:04 2022 +0800 [fix][feature](Function) fix return type && support hll_union_agg/group_concat agg to window function (#9119) --- .../vec/aggregate_functions/aggregate_function.h | 2 +- .../aggregate_function_hll_union_agg.h | 4 +++ .../aggregate_function_stddev.h | 11 ++++-- .../java/org/apache/doris/catalog/FunctionSet.java | 8 ++--- .../data/correctness/test_select_variance_agg.out | 7 ++++ .../correctness/test_select_variance_agg.groovy | 41 ++++++++++++++++++++++ 6 files changed, 66 insertions(+), 7 deletions(-) diff --git a/be/src/vec/aggregate_functions/aggregate_function.h b/be/src/vec/aggregate_functions/aggregate_function.h index 56e404d9e9..d822dada79 100644 --- a/be/src/vec/aggregate_functions/aggregate_function.h +++ b/be/src/vec/aggregate_functions/aggregate_function.h @@ -159,7 +159,7 @@ public: } } //now this is use for sum/count/avg/min/max win function, other win function should override this function in class - //stddev_pop/stddev_samp/variance_pop/variance_samp + //stddev_pop/stddev_samp/variance_pop/variance_samp/hll_union_agg/group_concat void add_range_single_place(int64_t partition_start, int64_t partition_end, int64_t frame_start, int64_t frame_end, AggregateDataPtr place, const IColumn** columns, Arena* arena) const override { diff --git a/be/src/vec/aggregate_functions/aggregate_function_hll_union_agg.h b/be/src/vec/aggregate_functions/aggregate_function_hll_union_agg.h index fe335b0509..c41e7be7d9 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_hll_union_agg.h +++ b/be/src/vec/aggregate_functions/aggregate_function_hll_union_agg.h @@ -53,6 +53,8 @@ struct AggregateFunctionHLLData { HyperLogLog get() const { return dst_hll; } + void reset() { dst_hll.clear(); } + void add(const IColumn* column, size_t row_num) { if constexpr (is_nullable) { auto* nullable_column = check_and_get_column<const ColumnNullable>(*column); @@ -126,6 +128,8 @@ public: Arena*) const override { this->data(place).read(buf); } + + void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); } }; template <bool is_nullable = false> diff --git a/be/src/vec/aggregate_functions/aggregate_function_stddev.h b/be/src/vec/aggregate_functions/aggregate_function_stddev.h index d03774b26f..3531e8db49 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_stddev.h +++ b/be/src/vec/aggregate_functions/aggregate_function_stddev.h @@ -21,6 +21,7 @@ #include "vec/aggregate_functions/aggregate_function.h" #include "vec/columns/columns_number.h" #include "vec/data_types/data_type_decimal.h" +#include "vec/data_types/data_type_nullable.h" #include "vec/data_types/data_type_number.h" #include "vec/io/io_helper.h" namespace doris::vectorized { @@ -91,6 +92,8 @@ struct BaseData { count += 1; } + static DataTypePtr get_return_type() { return std::make_shared<DataTypeNumber<Float64>>(); } + double mean; double m2; int64_t count; @@ -175,6 +178,10 @@ struct BaseDatadecimal { count += 1; } + static DataTypePtr get_return_type() { + return std::make_shared<DataTypeDecimal<Decimal128>>(27, 9); + } + DecimalV2Value mean; DecimalV2Value m2; int64_t count; @@ -248,9 +255,9 @@ public: DataTypePtr get_return_type() const override { if constexpr (is_pop) { - return std::make_shared<DataTypeFloat64>(); + return Data::get_return_type(); } else { - return make_nullable(std::make_shared<DataTypeFloat64>()); + return make_nullable(Data::get_return_type()); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java index aed8231567..85d63ca599 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java @@ -1630,7 +1630,7 @@ public class FunctionSet<min_initIN9doris_udf12DecimalV2ValEEEvPNS2_15FunctionCo "_ZN5doris12HllFunctions9hll_mergeEPN9doris_udf15FunctionContextERKNS1_9StringValEPS4_", "_ZN5doris12HllFunctions13hll_serializeEPN9doris_udf15FunctionContextERKNS1_9StringValE", "_ZN5doris12HllFunctions12hll_finalizeEPN9doris_udf15FunctionContextERKNS1_9StringValE", - true, false, true, true)); + true, true, true, true)); // APPROX_COUNT_DISTINCT // alias of ndv, compute approx count distinct use HyperLogLog @@ -1651,7 +1651,7 @@ public class FunctionSet<min_initIN9doris_udf12DecimalV2ValEEEvPNS2_15FunctionCo "_ZN5doris12HllFunctions9hll_mergeEPN9doris_udf15FunctionContextERKNS1_9StringValEPS4_", "_ZN5doris12HllFunctions13hll_serializeEPN9doris_udf15FunctionContextERKNS1_9StringValE", "_ZN5doris12HllFunctions12hll_finalizeEPN9doris_udf15FunctionContextERKNS1_9StringValE", - true, false, true, true)); + true, true, true, true)); // BITMAP_UNION_INT addBuiltin(AggregateFunction.createBuiltin(BITMAP_UNION_INT, @@ -2315,7 +2315,7 @@ public class FunctionSet<min_initIN9doris_udf12DecimalV2ValEEEvPNS2_15FunctionCo prefix + "19string_concat_mergeEPN9doris_udf15FunctionContextERKNS1_9StringValEPS4_", stringValSerializeOrFinalize, prefix + "22string_concat_finalizeEPN9doris_udf15FunctionContextERKNS1_9StringValE", false, - false, false, true)); + true, false, true)); // Group_concat(string, string) vectorized addBuiltin(AggregateFunction.createBuiltin("group_concat", Lists.<Type>newArrayList(Type.VARCHAR, Type.VARCHAR), Type.VARCHAR, Type.VARCHAR, initNullString, @@ -2323,7 +2323,7 @@ public class FunctionSet<min_initIN9doris_udf12DecimalV2ValEEEvPNS2_15FunctionCo prefix + "19string_concat_mergeEPN9doris_udf15FunctionContextERKNS1_9StringValEPS4_", stringValSerializeOrFinalize, prefix + "22string_concat_finalizeEPN9doris_udf15FunctionContextERKNS1_9StringValE", false, - false, false, true)); + true, false, true)); // analytic functions // Rank diff --git a/regression-test/data/correctness/test_select_variance_agg.out b/regression-test/data/correctness/test_select_variance_agg.out new file mode 100644 index 0000000000..66ad4d8c9e --- /dev/null +++ b/regression-test/data/correctness/test_select_variance_agg.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select_default -- +31200.0 + +-- !select_default2 -- +564.666666667 + diff --git a/regression-test/suites/correctness/test_select_variance_agg.groovy b/regression-test/suites/correctness/test_select_variance_agg.groovy new file mode 100644 index 0000000000..318679fac5 --- /dev/null +++ b/regression-test/suites/correctness/test_select_variance_agg.groovy @@ -0,0 +1,41 @@ +// 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("test_select_variance_agg") { + def tableName = "test_variance" + + + sql """ DROP TABLE IF EXISTS ${tableName} """ + sql """ + CREATE TABLE ${tableName} ( `aa` int NULL COMMENT "", `bb` decimal(27,9) NULL COMMENT "" ) + ENGINE=OLAP UNIQUE KEY(`aa`) DISTRIBUTED BY HASH(`aa`) BUCKETS 3 + PROPERTIES ( "replication_allocation" = "tag.location.default: 1", "in_memory" = "false", "storage_format" = "V2" ); + """ + + sql """ INSERT INTO ${tableName} VALUES + (123,34), + (423,78), + (3,23); """ + + // test_vectorized + sql """ set enable_vectorized_engine = true; """ + + qt_select_default """ select variance(aa) from ${tableName}; """ + + qt_select_default2 """ select variance(bb) from ${tableName}; """ + + } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org