New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CREATE TABLE AS table_function() #6057
Changes from 9 commits
7382cb4
20a846d
1ab0893
c9ec169
d1e6e6e
1aca3da
6ba4408
3abf1b2
f9d1214
b035ede
6c6af60
d279a68
42efc10
9ffbf65
0320de9
21ebb72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,7 +216,11 @@ void ASTCreateQuery::formatQueryImpl(const FormatSettings & settings, FormatStat | |
<< (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table); | ||
formatOnCluster(settings); | ||
} | ||
|
||
if (as_table_function) | ||
{ | ||
settings.ostr << (settings.hilite ? hilite_keyword : "") << " AS " << (settings.hilite ? hilite_none : ""); | ||
as_table_function->formatImpl(settings, state, frame); | ||
} | ||
if (!to_table.empty()) | ||
{ | ||
settings.ostr | ||
|
@@ -231,7 +235,7 @@ void ASTCreateQuery::formatQueryImpl(const FormatSettings & settings, FormatStat | |
<< (!as_database.empty() ? backQuoteIfNeed(as_database) + "." : "") << backQuoteIfNeed(as_table); | ||
} | ||
|
||
if (columns_list) | ||
if (columns_list && !as_table_function) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It shouldn't be able to parse CREATE table (columns_list) AS table_function(...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Test will be added, but this code actually prevents printing a frame with columns in metadata sql file, so it can simply be ATTACH table AS table_function(). Here comes the next question, why was columns_list initialized. (It responds to your last comment on this topic) It is initialized with setColumns() to avoid duplicating some code in initialization of a table. But I am not sure if it is right. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tried to fix it with if clause |
||
{ | ||
settings.ostr << (settings.one_line ? " (" : "\n("); | ||
FormatStateStacked frame_nested = frame; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ namespace ErrorCodes | |
extern const int LOGICAL_ERROR; | ||
} | ||
|
||
StoragePtr ITableFunctionXDBC::executeImpl(const ASTPtr & ast_function, const Context & context) const | ||
StoragePtr ITableFunctionXDBC::executeImpl(const ASTPtr & ast_function, const Context & context, const std::string & table_name) const | ||
{ | ||
const auto & args_func = ast_function->as<ASTFunction &>(); | ||
|
||
|
@@ -45,18 +45,18 @@ StoragePtr ITableFunctionXDBC::executeImpl(const ASTPtr & ast_function, const Co | |
|
||
std::string connection_string; | ||
std::string schema_name; | ||
std::string table_name; | ||
std::string remote_table_name; | ||
|
||
if (args.size() == 3) | ||
{ | ||
connection_string = args[0]->as<ASTLiteral &>().value.safeGet<String>(); | ||
schema_name = args[1]->as<ASTLiteral &>().value.safeGet<String>(); | ||
table_name = args[2]->as<ASTLiteral &>().value.safeGet<String>(); | ||
remote_table_name = args[2]->as<ASTLiteral &>().value.safeGet<String>(); | ||
} | ||
else if (args.size() == 2) | ||
{ | ||
connection_string = args[0]->as<ASTLiteral &>().value.safeGet<String>(); | ||
table_name = args[1]->as<ASTLiteral &>().value.safeGet<String>(); | ||
remote_table_name = args[1]->as<ASTLiteral &>().value.safeGet<String>(); | ||
} | ||
|
||
/* Infer external table structure */ | ||
|
@@ -68,15 +68,18 @@ StoragePtr ITableFunctionXDBC::executeImpl(const ASTPtr & ast_function, const Co | |
columns_info_uri.addQueryParameter("connection_string", connection_string); | ||
if (!schema_name.empty()) | ||
columns_info_uri.addQueryParameter("schema", schema_name); | ||
columns_info_uri.addQueryParameter("table", table_name); | ||
columns_info_uri.addQueryParameter("table", remote_table_name); | ||
|
||
ReadWriteBufferFromHTTP buf(columns_info_uri, Poco::Net::HTTPRequest::HTTP_POST, nullptr); | ||
|
||
std::string columns_info; | ||
readStringBinary(columns_info, buf); | ||
NamesAndTypesList columns = NamesAndTypesList::parse(columns_info); | ||
|
||
auto result = std::make_shared<StorageXDBC>(getDatabaseName(), table_name, schema_name, table_name, ColumnsDescription{columns}, context, helper); | ||
///If table_name was not specified by user, it will have the same name as remote_table_name | ||
std::string local_table_name = (table_name == getName()) ? remote_table_name : table_name; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is strange. |
||
|
||
auto result = std::make_shared<StorageXDBC>(getDatabaseName(), local_table_name, schema_name, remote_table_name, ColumnsDescription{columns}, context, helper); | ||
|
||
if (!result) | ||
throw Exception("Failed to instantiate storage from table function " + getName(), ErrorCodes::UNKNOWN_EXCEPTION); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?