diff --git a/dbms/src/AggregateFunctions/AggregateFunctionMinMaxAny.h b/dbms/src/AggregateFunctions/AggregateFunctionMinMaxAny.h index db2978db6a0..ca5b1abae8f 100644 --- a/dbms/src/AggregateFunctions/AggregateFunctionMinMaxAny.h +++ b/dbms/src/AggregateFunctions/AggregateFunctionMinMaxAny.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,7 @@ struct SingleValueDataFixed { private: using Self = SingleValueDataFixed; + using ColVecType = std::conditional_t, ColumnDecimal, ColumnVector>; bool has_value = false; /// We need to remember if at least one value has been passed. This is necessary for AggregateFunctionIf. T value; @@ -39,9 +41,9 @@ public: void insertResultInto(IColumn & to) const { if (has()) - assert_cast &>(to).getData().push_back(value); + assert_cast(to).getData().push_back(value); else - assert_cast &>(to).insertDefault(); + assert_cast(to).insertDefault(); } void write(WriteBuffer & buf, const IDataType & /*data_type*/) const @@ -62,7 +64,7 @@ public: void change(const IColumn & column, size_t row_num, Arena *) { has_value = true; - value = assert_cast &>(column).getData()[row_num]; + value = assert_cast(column).getData()[row_num]; } /// Assuming to.has() @@ -113,7 +115,7 @@ public: bool changeIfLess(const IColumn & column, size_t row_num, Arena * arena) { - if (!has() || assert_cast &>(column).getData()[row_num] < value) + if (!has() || assert_cast(column).getData()[row_num] < value) { change(column, row_num, arena); return true; @@ -135,7 +137,7 @@ public: bool changeIfGreater(const IColumn & column, size_t row_num, Arena * arena) { - if (!has() || assert_cast &>(column).getData()[row_num] > value) + if (!has() || assert_cast(column).getData()[row_num] > value) { change(column, row_num, arena); return true; @@ -162,7 +164,7 @@ public: bool isEqualTo(const IColumn & column, size_t row_num) const { - return has() && assert_cast &>(column).getData()[row_num] == value; + return has() && assert_cast(column).getData()[row_num] == value; } }; diff --git a/dbms/src/AggregateFunctions/HelpersMinMaxAny.h b/dbms/src/AggregateFunctions/HelpersMinMaxAny.h index 277af31a6dc..dada68c9791 100644 --- a/dbms/src/AggregateFunctions/HelpersMinMaxAny.h +++ b/dbms/src/AggregateFunctions/HelpersMinMaxAny.h @@ -32,6 +32,12 @@ static IAggregateFunction * createAggregateFunctionSingleValue(const String & na return new AggregateFunctionTemplate>, false>(argument_type); if (which.idx == TypeIndex::DateTime) return new AggregateFunctionTemplate>, false>(argument_type); + if (which.idx == TypeIndex::Decimal32) + return new AggregateFunctionTemplate>, false>(argument_type); + if (which.idx == TypeIndex::Decimal64) + return new AggregateFunctionTemplate>, false>(argument_type); + if (which.idx == TypeIndex::Decimal128) + return new AggregateFunctionTemplate>, false>(argument_type); if (which.idx == TypeIndex::String) return new AggregateFunctionTemplate, true>(argument_type); @@ -54,6 +60,12 @@ static IAggregateFunction * createAggregateFunctionArgMinMaxSecond(const DataTyp return new AggregateFunctionArgMinMax>>, false>(res_type, val_type); if (which.idx == TypeIndex::DateTime) return new AggregateFunctionArgMinMax>>, false>(res_type, val_type); + if (which.idx == TypeIndex::Decimal32) + return new AggregateFunctionArgMinMax>>, false>(res_type, val_type); + if (which.idx == TypeIndex::Decimal64) + return new AggregateFunctionArgMinMax>>, false>(res_type, val_type); + if (which.idx == TypeIndex::Decimal128) + return new AggregateFunctionArgMinMax>>, false>(res_type, val_type); if (which.idx == TypeIndex::String) return new AggregateFunctionArgMinMax>, true>(res_type, val_type); @@ -80,6 +92,12 @@ static IAggregateFunction * createAggregateFunctionArgMinMax(const String & name return createAggregateFunctionArgMinMaxSecond>(res_type, val_type); if (which.idx == TypeIndex::DateTime) return createAggregateFunctionArgMinMaxSecond>(res_type, val_type); + if (which.idx == TypeIndex::Decimal32) + return createAggregateFunctionArgMinMaxSecond>(res_type, val_type); + if (which.idx == TypeIndex::Decimal64) + return createAggregateFunctionArgMinMaxSecond>(res_type, val_type); + if (which.idx == TypeIndex::Decimal128) + return createAggregateFunctionArgMinMaxSecond>(res_type, val_type); if (which.idx == TypeIndex::String) return createAggregateFunctionArgMinMaxSecond(res_type, val_type); diff --git a/dbms/tests/performance/decimal_aggregates.xml b/dbms/tests/performance/decimal_aggregates.xml new file mode 100644 index 00000000000..f22cb89de36 --- /dev/null +++ b/dbms/tests/performance/decimal_aggregates.xml @@ -0,0 +1,45 @@ + + loop + + CREATE TABLE t (x UInt64, d32 Decimal32(3), d64 Decimal64(4), d128 Decimal128(5)) ENGINE = Memory + INSERT INTO t SELECT number AS x, x AS d32, x AS d64, x d128 FROM numbers(1000000) + DROP TABLE IF EXISTS t + + + + 10 + + + + + + + + SELECT min(d32), max(d32), argMin(x, d32), argMax(x, d32) FROM t + SELECT min(d64), max(d64), argMin(x, d64), argMax(x, d64) FROM t + SELECT min(d128), max(d128), argMin(x, d128), argMax(x, d128) FROM t + + SELECT avg(d32), sum(d32), sumWithOverflow(d32) FROM t + SELECT avg(d64), sum(d64), sumWithOverflow(d64) FROM t + SELECT avg(d128), sum(d128), sumWithOverflow(d128) FROM t + + SELECT uniq(d32), uniqCombined(d32), uniqExact(d32), uniqHLL12(d32) FROM t + SELECT uniq(d64), uniqCombined(d64), uniqExact(d64), uniqHLL12(d64) FROM t + SELECT uniq(d128), uniqCombined(d128), uniqExact(d128), uniqHLL12(d128) FROM t + + SELECT median(d32), medianExact(d32), medianExactWeighted(d32, 2) FROM t + SELECT median(d64), medianExact(d64), medianExactWeighted(d64, 2) FROM t + SELECT median(d128), medianExact(d128), medianExactWeighted(d128, 2) FROM t + + SELECT quantile(d32), quantileExact(d32), quantileExactWeighted(d32, 2) FROM t + SELECT quantile(d64), quantileExact(d64), quantileExactWeighted(d64, 2) FROM t + SELECT quantile(d128), quantileExact(d128), quantileExactWeighted(d128, 2) FROM t + + SELECT quantilesExact(0.1, 0.9)(d32), quantilesExactWeighted(0.1, 0.9)(d32, 2) FROM t + SELECT quantilesExact(0.1, 0.9)(d64), quantilesExactWeighted(0.1, 0.9)(d64, 2) FROM t + SELECT quantilesExact(0.1, 0.9)(d128), quantilesExactWeighted(0.1, 0.9)(d128, 2) FROM t + + SELECT varPop(d32), varSamp(d32), stddevPop(d32) FROM t + SELECT varPop(d64), varSamp(d64), stddevPop(d64) FROM t + SELECT varPop(d128), varSamp(d128), stddevPop(d128) FROM t +