Merge pull request #11477 from ClickHouse/aku/generate-random

generateRandom: check that all arguments are literals
This commit is contained in:
alexey-milovidov 2020-06-06 12:08:24 +03:00 committed by GitHub
commit 937dd79880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View File

@ -822,7 +822,11 @@ const Block & Context::getScalar(const String & name) const
{
auto it = scalars.find(name);
if (scalars.end() == it)
throw Exception("Scalar " + backQuoteIfNeed(name) + " doesn't exist (internal bug)", ErrorCodes::LOGICAL_ERROR);
{
// This should be a logical error, but it fails the sql_fuzz test too
// often, so 'bad arguments' for now.
throw Exception("Scalar " + backQuoteIfNeed(name) + " doesn't exist (internal bug)", ErrorCodes::BAD_ARGUMENTS);
}
return it->second;
}

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>();

View File

@ -25,6 +25,7 @@ namespace DB
namespace ErrorCodes
{
extern const int BAD_ARGUMENTS;
extern const int LOGICAL_ERROR;
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
}
@ -75,6 +76,13 @@ StoragePtr TableFunctionValues::executeImpl(const ASTPtr & ast_function, const C
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
/// Parsing first argument as table structure and creating a sample block
if (!args[0]->as<const ASTLiteral>())
{
throw Exception(fmt::format(
"The first argument of table function '{}' must be a literal. "
"Got '{}' instead", getName(), args[0]->formatForErrorMessage()),
ErrorCodes::BAD_ARGUMENTS);
}
std::string structure = args[0]->as<ASTLiteral &>().value.safeGet<String>();
ColumnsDescription columns = parseColumnsListFromString(structure, context);