Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Interpreters/InterpreterCreateQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1918,8 +1918,7 @@ bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create,
auto table_function_ast = create.as_table_function->ptr();
auto table_function = TableFunctionFactory::instance().get(table_function_ast, getContext());

if (!table_function->canBeUsedToCreateTable())
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Table function '{}' cannot be used to create a table", table_function->getName());
table_function->validateUseToCreateTable();

/// In case of CREATE AS table_function() query we should use global context
/// in storage creation because there will be no query context on server startup
Expand Down
2 changes: 1 addition & 1 deletion src/TableFunctions/ITableFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ITableFunction : public std::enable_shared_from_this<ITableFunction>

virtual bool supportsReadingSubsetOfColumns(const ContextPtr &) { return true; }

virtual bool canBeUsedToCreateTable() const { return true; }
virtual void validateUseToCreateTable() const {}

/// Create storage according to the query.
StoragePtr
Expand Down
6 changes: 5 additions & 1 deletion src/TableFunctions/ITableFunctionCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace ErrorCodes
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
extern const int CLUSTER_DOESNT_EXIST;
extern const int LOGICAL_ERROR;
extern const int BAD_ARGUMENTS;
}

/// Base class for *Cluster table functions that require cluster_name for the first argument.
Expand All @@ -35,7 +36,10 @@ class ITableFunctionCluster : public Base
args.insert(args.begin(), cluster_name_arg);
}

bool canBeUsedToCreateTable() const override { return false; }
void validateUseToCreateTable() const override
{
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Table function '{}' cannot be used to create a table", getName());
}

protected:
void parseArguments(const ASTPtr & ast, ContextPtr context) override
Expand Down
11 changes: 11 additions & 0 deletions src/TableFunctions/TableFunctionObjectStorageClusterFallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Setting
namespace ErrorCodes
{
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
extern const int BAD_ARGUMENTS;
}

struct S3ClusterFallbackDefinition
Expand Down Expand Up @@ -117,6 +118,16 @@ StoragePtr TableFunctionObjectStorageClusterFallback<Definition, Base>::executeI
return BaseSimple::executeImpl(ast_function, context, table_name, cached_columns, is_insert_query);
}

template <typename Definition, typename Base>
void TableFunctionObjectStorageClusterFallback<Definition, Base>::validateUseToCreateTable() const
{
if (is_cluster_function)
throw Exception(
ErrorCodes::BAD_ARGUMENTS,
"Table function '{}' cannot be used to create a table in cluster mode",
getName());
}

#if USE_AWS_S3
using TableFunctionS3ClusterFallback = TableFunctionObjectStorageClusterFallback<S3ClusterFallbackDefinition, TableFunctionS3Cluster>;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class TableFunctionObjectStorageClusterFallback : public Base

String getName() const override { return name; }

void validateUseToCreateTable() const override;

private:
const char * getStorageTypeName() const override
{
Expand Down
Loading