fix error

This commit is contained in:
hexiaoting 2021-03-03 17:18:53 +08:00
parent e116346cbb
commit 4fe75ad168
4 changed files with 10 additions and 15 deletions

View File

@ -16,7 +16,7 @@ namespace
{ {
template <typename T> template <typename T>
struct SumSimple struct SumCountType
{ {
/// @note It uses slow Decimal128 (cause we need such a variant). sumWithOverflow is faster for Decimal32/64 /// @note It uses slow Decimal128 (cause we need such a variant). sumWithOverflow is faster for Decimal32/64
using ResultType = std::conditional_t<IsDecimalNumber<T>, using ResultType = std::conditional_t<IsDecimalNumber<T>,
@ -27,8 +27,7 @@ struct SumSimple
}; };
template <typename T> using AggregateFunctionSumCountFunc = typename SumCountType<T>::Function;
template <typename T> using AggregateFunctionSumCountSimple = typename SumSimple<T>::Function;
template <template <typename> class Function> template <template <typename> class Function>
AggregateFunctionPtr createAggregateFunctionSumCount(const std::string & name, const DataTypes & argument_types, const Array & parameters) AggregateFunctionPtr createAggregateFunctionSumCount(const std::string & name, const DataTypes & argument_types, const Array & parameters)
@ -53,7 +52,7 @@ AggregateFunctionPtr createAggregateFunctionSumCount(const std::string & name, c
void registerAggregateFunctionSumCount(AggregateFunctionFactory & factory) void registerAggregateFunctionSumCount(AggregateFunctionFactory & factory)
{ {
factory.registerFunction("sumCount", createAggregateFunctionSumCount<AggregateFunctionSumCountSimple>); factory.registerFunction("sumCount", createAggregateFunctionSumCount<AggregateFunctionSumCountFunc>);
} }
} }

View File

@ -189,13 +189,9 @@ public:
{ {
DataTypes types; DataTypes types;
if constexpr (IsDecimalNumber<T>) if constexpr (IsDecimalNumber<T>)
{
types.emplace_back(std::make_shared<ResultDataType>(ResultDataType::maxPrecision(), scale)); types.emplace_back(std::make_shared<ResultDataType>(ResultDataType::maxPrecision(), scale));
}
else else
{
types.emplace_back(std::make_shared<ResultDataType>()); types.emplace_back(std::make_shared<ResultDataType>());
}
types.emplace_back(std::make_shared<DataTypeUInt64>()); types.emplace_back(std::make_shared<DataTypeUInt64>());

View File

@ -409,7 +409,7 @@ class IColumn;
M(Bool, allow_non_metadata_alters, true, "Allow to execute alters which affects not only tables metadata, but also data on disk", 0) \ M(Bool, allow_non_metadata_alters, true, "Allow to execute alters which affects not only tables metadata, but also data on disk", 0) \
M(Bool, enable_global_with_statement, true, "Propagate WITH statements to UNION queries and all subqueries", 0) \ M(Bool, enable_global_with_statement, true, "Propagate WITH statements to UNION queries and all subqueries", 0) \
M(Bool, aggregate_functions_null_for_empty, false, "Rewrite all aggregate functions in a query, adding -OrNull suffix to them", 0) \ M(Bool, aggregate_functions_null_for_empty, false, "Rewrite all aggregate functions in a query, adding -OrNull suffix to them", 0) \
M(Bool, optimize_fuse_sum_count_avg, false, "If enabled, Fuse aggregate functions when exsit at least two: sum, avg, count functions with identical argument to sumCount", 0) \ M(Bool, optimize_fuse_sum_count_avg, false, "If enabled, Fuse aggregate functions when exists at least two: sum, avg, count functions with identical argument to sumCount", 0) \
M(Bool, flatten_nested, true, "If true, columns of type Nested will be flatten to separate array columns instead of one array of tuples", 0) \ M(Bool, flatten_nested, true, "If true, columns of type Nested will be flatten to separate array columns instead of one array of tuples", 0) \
M(Bool, asterisk_include_materialized_columns, false, "Include MATERIALIZED columns for wildcard query", 0) \ M(Bool, asterisk_include_materialized_columns, false, "Include MATERIALIZED columns for wildcard query", 0) \
M(Bool, asterisk_include_alias_columns, false, "Include ALIAS columns for wildcard query", 0) \ M(Bool, asterisk_include_alias_columns, false, "Include ALIAS columns for wildcard query", 0) \

View File

@ -188,7 +188,7 @@ struct CustomizeFuseAggregateFunctionsData
std::map<String, UInt8> fuse_info; std::map<String, UInt8> fuse_info;
inline UInt8 BitCount(UInt8 n) const static inline UInt8 bitCount(UInt8 n)
{ {
UInt8 c = 0; UInt8 c = 0;
for (c = 0; n; n >>= 1) for (c = 0; n; n >>= 1)
@ -204,14 +204,14 @@ struct CustomizeFuseAggregateFunctionsData
if (!ident) if (!ident)
return; return;
auto column = fuse_info.find(ident->name()); auto column = fuse_info.find(ident->name());
if (column != fuse_info.end() && BitCount(column->second) > 1) if (column != fuse_info.end() && bitCount(column->second) > 1)
{ {
auto func_base = makeASTFunction("sumCount", func.arguments->children.at(0)->clone()); auto func_base = makeASTFunction("sumCount", func.arguments->children.at(0)->clone());
auto exp_list = std::make_shared<ASTExpressionList>(); auto exp_list = std::make_shared<ASTExpressionList>();
if (func.name == "sum" || func.name == "count") if (func.name == "sum" || func.name == "count")
{ {
// Rewrite "sum" to sumCount().1, rewrite "count" to sumCount().2 /// Rewrite "sum" to sumCount().1, rewrite "count" to sumCount().2
UInt8 idx = (func.name == "sum" ? 1 : 2); UInt8 idx = (func.name == "sum" ? 1 : 2);
func.name = "tupleElement"; func.name = "tupleElement";
exp_list->children.push_back(func_base); exp_list->children.push_back(func_base);
@ -219,7 +219,7 @@ struct CustomizeFuseAggregateFunctionsData
} }
else else
{ {
// Rewrite "avg" to sumCount().1 / sumCount().2 /// Rewrite "avg" to sumCount().1 / sumCount().2
auto new_arg1 = makeASTFunction("tupleElement", func_base, std::make_shared<ASTLiteral>(UInt8(1))); auto new_arg1 = makeASTFunction("tupleElement", func_base, std::make_shared<ASTLiteral>(UInt8(1)));
auto new_arg2 = makeASTFunction("tupleElement", func_base, std::make_shared<ASTLiteral>(UInt8(2))); auto new_arg2 = makeASTFunction("tupleElement", func_base, std::make_shared<ASTLiteral>(UInt8(2)));
func.name = "divide"; func.name = "divide";