2017-12-20 07:36:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-10-04 17:46:36 +00:00
|
|
|
#include <Core/Field.h>
|
2017-12-20 07:36:30 +00:00
|
|
|
#include <DataTypes/IDataType.h>
|
2019-10-12 15:15:16 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
2017-12-20 07:36:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-11-19 14:25:42 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int AGGREGATE_FUNCTION_DOESNT_ALLOW_PARAMETERS;
|
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void assertNoParameters(const std::string & name, const Array & parameters)
|
|
|
|
{
|
|
|
|
if (!parameters.empty())
|
|
|
|
throw Exception("Aggregate function " + name + " cannot have parameters", ErrorCodes::AGGREGATE_FUNCTION_DOESNT_ALLOW_PARAMETERS);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void assertUnary(const std::string & name, const DataTypes & argument_types)
|
|
|
|
{
|
|
|
|
if (argument_types.size() != 1)
|
2019-12-28 04:23:08 +00:00
|
|
|
throw Exception("Aggregate function " + name + " requires single argument", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
2018-11-19 14:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void assertBinary(const std::string & name, const DataTypes & argument_types)
|
|
|
|
{
|
|
|
|
if (argument_types.size() != 2)
|
2019-12-28 04:23:08 +00:00
|
|
|
throw Exception("Aggregate function " + name + " requires two arguments", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
2018-11-19 14:25:42 +00:00
|
|
|
}
|
2017-12-20 07:36:30 +00:00
|
|
|
|
2019-10-12 15:15:16 +00:00
|
|
|
template<std::size_t maximal_arity>
|
|
|
|
inline void assertArityAtMost(const std::string & name, const DataTypes & argument_types)
|
|
|
|
{
|
|
|
|
if (argument_types.size() <= maximal_arity)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if constexpr (maximal_arity == 0)
|
|
|
|
throw Exception("Aggregate function " + name + " cannot have arguments",
|
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
|
|
|
|
if constexpr (maximal_arity == 1)
|
2019-10-13 18:37:01 +00:00
|
|
|
throw Exception("Aggregate function " + name + " requires zero or one argument",
|
2019-10-12 15:15:16 +00:00
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
|
2019-10-13 18:37:01 +00:00
|
|
|
throw Exception("Aggregate function " + name + " requires at most " + toString(maximal_arity) + " arguments",
|
2019-10-12 15:15:16 +00:00
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
}
|
|
|
|
|
2017-12-20 07:36:30 +00:00
|
|
|
}
|