Skip to content

Commit fc5b616

Browse files
committed
fix merge and serialize problems
1 parent 8327f5d commit fc5b616

File tree

3 files changed

+101
-141
lines changed

3 files changed

+101
-141
lines changed

src/AggregateFunctions/AggregateFunctionFactory.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,16 @@ AggregateFunctionPtr AggregateFunctionFactory::getImpl(
179179
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::AggregateFunctionCombinator, combinator_name);
180180

181181
String nested_name = name.substr(0, name.size() - combinator_name.size());
182-
if (combinator_name == "_time_weighted" && nested_name == "avg")
183-
nested_name = "avg_weighted";
184-
else if (combinator_name == "_time_weighted" && nested_name == "median")
185-
nested_name = "median_timing_weighted";
186-
else if (combinator_name == "_time_weighted")
187-
throw Exception(ErrorCodes::ILLEGAL_AGGREGATION, "Combinator '{}' with {} is not supported", combinator_name, nested_name);
182+
183+
if (combinator_name == "_time_weighted")
184+
{
185+
if (nested_name == "avg")
186+
nested_name = "avg_weighted";
187+
else if (nested_name == "median")
188+
nested_name = "median_timing_weighted";
189+
else
190+
throw Exception(ErrorCodes::ILLEGAL_AGGREGATION, "Combinator '{}' with {} is not supported", combinator_name, nested_name);
191+
}
188192

189193
/// Nested identical combinators (i.e. uniqCombinedIfIf) is not
190194
/// supported (since they don't work -- silently).

src/AggregateFunctions/AggregateFunctionTimeWeighted.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
namespace DB
1414
{
1515

16-
namespace ErrorCodes
17-
{
18-
19-
}
20-
2116
namespace
2217
{
2318

@@ -29,21 +24,19 @@ class AggregateFunctionCombinatorTimeWeighted final : public IAggregateFunctionC
2924
DataTypes transformArguments(const DataTypes & arguments) const override
3025
{
3126
if (arguments.size() != 2 && arguments.size() != 3)
32-
throw Exception("Incorrect number of arguments for aggregate function with " + getName() + " suffix",
33-
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
34-
35-
const auto data_type = static_cast<const DataTypePtr>(arguments[0]);
36-
const auto data_type_time_weight = static_cast<const DataTypePtr>(arguments[1]);
27+
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Incorrect number of arguments for aggregate function with {} suffix", this->getName());
28+
29+
const auto & data_type_time_weight = arguments[1];
3730
const WhichDataType t_dt(data_type_time_weight);
3831

3932
if (!t_dt.isDateOrDate32() && !t_dt.isDateTime() && !t_dt.isDateTime64())
4033
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Types {} are non-conforming as time weighted arguments for aggregate function {}", data_type_time_weight->getName(), this->getName());
4134

4235
if (arguments.size() == 3)
4336
{
44-
const auto data_type_third_arg = static_cast<const DataTypePtr>(arguments[2]);
37+
const auto & data_type_third_arg = arguments[2];
4538

46-
if(data_type_third_arg->getTypeId() != data_type_time_weight->getTypeId())
39+
if(!data_type_third_arg->equals(*data_type_time_weight))
4740
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "The second and the third argument should be the same for aggregate function {}, but now it's {} and {}", this->getName(), data_type_third_arg->getName(), data_type_time_weight->getName());
4841
}
4942

@@ -94,9 +87,11 @@ class AggregateFunctionCombinatorTimeWeighted final : public IAggregateFunctionC
9487
const Array & params) const override
9588
{
9689
AggregateFunctionPtr ptr;
97-
const auto data_type = static_cast<const DataTypePtr>(arguments[0]);
98-
const auto data_type_time_weight = static_cast<const DataTypePtr>(arguments[1]);
90+
const auto & data_type = arguments[0];
91+
const auto & data_type_time_weight = arguments[1];
9992
ptr.reset(create(*data_type, *data_type_time_weight, nested_function, arguments, params));
93+
if(!ptr)
94+
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal argument types existed in {} function", this->getName());
10095

10196
return ptr;
10297
}

0 commit comments

Comments
 (0)