Skip to content

Commit 132b231

Browse files
committed
Fix S3 table function as table
1 parent 024a0b4 commit 132b231

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

src/Interpreters/InterpreterCreateQuery.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,8 +1918,7 @@ bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create,
19181918
auto table_function_ast = create.as_table_function->ptr();
19191919
auto table_function = TableFunctionFactory::instance().get(table_function_ast, getContext());
19201920

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

19241923
/// In case of CREATE AS table_function() query we should use global context
19251924
/// in storage creation because there will be no query context on server startup

src/TableFunctions/ITableFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ITableFunction : public std::enable_shared_from_this<ITableFunction>
7878

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

81-
virtual bool canBeUsedToCreateTable() const { return true; }
81+
virtual void validateUseToCreateTable() const {}
8282

8383
/// Create storage according to the query.
8484
StoragePtr

src/TableFunctions/ITableFunctionCluster.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace ErrorCodes
1515
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
1616
extern const int CLUSTER_DOESNT_EXIST;
1717
extern const int LOGICAL_ERROR;
18+
extern const int BAD_ARGUMENTS;
1819
}
1920

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

38-
bool canBeUsedToCreateTable() const override { return false; }
39+
void validateUseToCreateTable() const override
40+
{
41+
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Table function '{}' cannot be used to create a table", getName());
42+
}
3943

4044
protected:
4145
void parseArguments(const ASTPtr & ast, ContextPtr context) override

src/TableFunctions/TableFunctionObjectStorageClusterFallback.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Setting
1515
namespace ErrorCodes
1616
{
1717
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
18+
extern const int BAD_ARGUMENTS;
1819
}
1920

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

121+
template <typename Definition, typename Base>
122+
void TableFunctionObjectStorageClusterFallback<Definition, Base>::validateUseToCreateTable() const
123+
{
124+
if (is_cluster_function)
125+
throw Exception(
126+
ErrorCodes::BAD_ARGUMENTS,
127+
"Table function '{}' cannot be used to create a table in cluster mode",
128+
getName());
129+
}
130+
120131
#if USE_AWS_S3
121132
using TableFunctionS3ClusterFallback = TableFunctionObjectStorageClusterFallback<S3ClusterFallbackDefinition, TableFunctionS3Cluster>;
122133
#endif

src/TableFunctions/TableFunctionObjectStorageClusterFallback.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class TableFunctionObjectStorageClusterFallback : public Base
2626

2727
String getName() const override { return name; }
2828

29+
void validateUseToCreateTable() const override;
30+
2931
private:
3032
const char * getStorageTypeName() const override
3133
{

0 commit comments

Comments
 (0)