generateRandom: check that all arguments are literals

This commit is contained in:
Alexander Kuzmenkov 2020-06-05 21:45:48 +03:00
parent e22a711d2b
commit fc69811c7f

View File

@ -21,6 +21,7 @@ namespace DB
namespace ErrorCodes
{
extern const int BAD_ARGUMENTS;
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
extern const int LOGICAL_ERROR;
}
@ -44,6 +45,18 @@ StoragePtr TableFunctionGenerateRandom::executeImpl(const ASTPtr & ast_function,
" structure, [random_seed, max_string_length, max_array_length].",
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
// All the arguments must be literals.
for (const auto & arg : args)
{
if (!arg->as<const ASTLiteral>())
{
throw Exception(fmt::format(
"All arguments of table function '{}' must be literals. "
"Got '{}' instead", getName(), arg->formatForErrorMessage()),
ErrorCodes::BAD_ARGUMENTS);
}
}
/// Parsing first argument as table structure and creating a sample block
std::string structure = args[0]->as<const ASTLiteral &>().value.safeGet<String>();