Stricter checks

This commit is contained in:
Konstantin Bogdanov 2024-11-20 16:32:04 +01:00
parent 07821a576d
commit 5b1f7c258b
No known key found for this signature in database
3 changed files with 20 additions and 3 deletions

View File

@ -87,8 +87,15 @@ void StorageObjectStorageCluster::updateQueryToSendIfNeeded(
const ContextPtr & context)
{
auto * table_function = extractTableFunctionFromSelectQuery(query);
auto * expression_list = table_function->arguments->as<ASTExpressionList>();
if (!table_function)
{
throw Exception(
ErrorCodes::LOGICAL_ERROR,
"Expected SELECT query from table function {}, got '{}'",
configuration->getEngineName(), queryToString(query));
}
auto * expression_list = table_function->arguments->as<ASTExpressionList>();
if (!expression_list)
{
throw Exception(
@ -109,13 +116,15 @@ void StorageObjectStorageCluster::updateQueryToSendIfNeeded(
if (table_function->name == configuration->getTypeName())
configuration->addStructureAndFormatToArgsIfNeeded(args, structure, configuration->format, context);
else
else if (table_function->name == fmt::format("{}Cluster", configuration->getTypeName()))
{
ASTPtr cluster_name_arg = args.front();
args.erase(args.begin());
configuration->addStructureAndFormatToArgsIfNeeded(args, structure, configuration->format, context);
args.insert(args.begin(), cluster_name_arg);
}
else
throw Exception(ErrorCodes::LOGICAL_ERROR, "Unexpected table function name: {}", table_function->name);
}

View File

@ -83,6 +83,12 @@ StorageURLCluster::StorageURLCluster(
void StorageURLCluster::updateQueryToSendIfNeeded(ASTPtr & query, const StorageSnapshotPtr & storage_snapshot, const ContextPtr & context)
{
auto * table_function = extractTableFunctionFromSelectQuery(query);
if (!table_function)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Expected SELECT query from table function urlCluster, got '{}'", queryToString(query));
auto * expression_list = table_function->arguments->as<ASTExpressionList>();
if (!expression_list)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Expected SELECT query from table function urlCluster, got '{}'", queryToString(query));
TableFunctionURLCluster::updateStructureAndFormatArgumentsIfNeeded(
table_function,

View File

@ -35,13 +35,15 @@ public:
if (table_function->name == Base::name)
Base::updateStructureAndFormatArgumentsIfNeeded(args, structure_, format_, context);
else
else if (table_function->name == fmt::format("{}Cluster", Base::name))
{
ASTPtr cluster_name_arg = args.front();
args.erase(args.begin());
Base::updateStructureAndFormatArgumentsIfNeeded(args, structure_, format_, context);
args.insert(args.begin(), cluster_name_arg);
}
else
throw Exception(ErrorCodes::LOGICAL_ERROR, "Unexpected table function name: {}", table_function->name);
}
protected: