2022-06-23 20:04:06 +00:00
|
|
|
#include <Storages/checkAndGetLiteralArgument.h>
|
|
|
|
#include <Core/Field.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int BAD_ARGUMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T checkAndGetLiteralArgument(const ASTPtr & arg, const String & arg_name)
|
|
|
|
{
|
2023-07-05 14:56:11 +00:00
|
|
|
if (arg->as<ASTLiteral>())
|
|
|
|
return checkAndGetLiteralArgument<T>(*arg->as<ASTLiteral>(), arg_name);
|
|
|
|
|
|
|
|
throw Exception(
|
|
|
|
ErrorCodes::BAD_ARGUMENTS,
|
|
|
|
"Argument '{}' must be a literal, get {} (value: {})",
|
|
|
|
arg_name,
|
|
|
|
arg->getID(),
|
|
|
|
arg->formatForErrorMessage());
|
2022-06-23 20:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T checkAndGetLiteralArgument(const ASTLiteral & arg, const String & arg_name)
|
|
|
|
{
|
2022-06-24 14:00:22 +00:00
|
|
|
auto requested_type = Field::TypeToEnum<NearestFieldType<std::decay_t<T>>>::value;
|
|
|
|
auto provided_type = arg.value.getType();
|
|
|
|
if (requested_type != provided_type)
|
|
|
|
throw Exception(
|
|
|
|
ErrorCodes::BAD_ARGUMENTS,
|
|
|
|
"Argument '{}' must be a literal with type {}, got {}",
|
|
|
|
arg_name,
|
|
|
|
fieldTypeToString(requested_type),
|
|
|
|
fieldTypeToString(provided_type));
|
2022-06-23 20:04:06 +00:00
|
|
|
|
2022-06-24 14:00:22 +00:00
|
|
|
return arg.value.safeGet<T>();
|
2022-06-23 20:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template String checkAndGetLiteralArgument(const ASTPtr &, const String &);
|
|
|
|
template UInt64 checkAndGetLiteralArgument(const ASTPtr &, const String &);
|
2022-06-24 11:58:12 +00:00
|
|
|
template UInt8 checkAndGetLiteralArgument(const ASTPtr &, const String &);
|
2022-06-23 22:54:05 +00:00
|
|
|
template bool checkAndGetLiteralArgument(const ASTPtr &, const String &);
|
2022-06-23 20:04:06 +00:00
|
|
|
template String checkAndGetLiteralArgument(const ASTLiteral &, const String &);
|
2023-01-20 21:16:55 +00:00
|
|
|
template UInt64 checkAndGetLiteralArgument(const ASTLiteral &, const String &);
|
2022-06-23 20:04:06 +00:00
|
|
|
}
|