Skip to content
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

enhancement: support comment for create external table #568

Merged
merged 1 commit into from
Feb 17, 2024
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
19 changes: 19 additions & 0 deletions src/Parsers/ParserCreateExternalTableQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
namespace DB
{

namespace
{
ASTPtr parseComment(IParser::Pos & pos, Expected & expected)
{
ParserKeyword s_comment("COMMENT");
ParserStringLiteral string_literal_parser;
ASTPtr comment;

s_comment.ignore(pos, expected) && string_literal_parser.parse(pos, comment, expected);

return comment;
}
}

bool DB::ParserCreateExternalTableQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected, [[ maybe_unused ]] bool hint)
{
ParserKeyword s_create("CREATE");
Expand Down Expand Up @@ -52,6 +66,8 @@ bool DB::ParserCreateExternalTableQuery::parseImpl(Pos & pos, ASTPtr & node, Exp
return false;
}

auto comment = parseComment(pos, expected);

auto create_query = std::make_shared<ASTCreateQuery>();
node = create_query;

Expand All @@ -72,6 +88,9 @@ bool DB::ParserCreateExternalTableQuery::parseImpl(Pos & pos, ASTPtr & node, Exp
if (create_query->table)
create_query->children.push_back(create_query->table);

if (comment)
create_query->set(create_query->comment, comment);

auto storage = std::make_shared<ASTStorage>();
storage->set(storage->engine, makeASTFunction("ExternalTable"));
storage->set(storage->settings, settings);
Expand Down
9 changes: 9 additions & 0 deletions src/Storages/ExternalTable/StorageExternalTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ namespace DB
StorageExternalTable::StorageExternalTable(
const StorageID & table_id,
std::unique_ptr<ExternalTableSettings> settings,
const String & comment,
bool is_attach,
ContextPtr context_)
: IStorage(table_id)
, WithContext(context_)
{
if (!comment.empty())
{
StorageInMemoryMetadata storage_metadata;
storage_metadata.setComment(comment);
setInMemoryMetadata(storage_metadata);
}

external_table = ExternalTableFactory::instance().getExternalTable(table_id.getTableName(), std::move(settings));

/// Two situations:
Expand Down Expand Up @@ -95,6 +103,7 @@ void registerStorageExternalTable(StorageFactory & factory)
return StorageExternalTable::create(
args.table_id,
std::move(settings),
args.comment,
args.attach,
args.getContext()->getGlobalContext());
};
Expand Down
1 change: 1 addition & 0 deletions src/Storages/ExternalTable/StorageExternalTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class StorageExternalTable final : public shared_ptr_helper<StorageExternalTable
StorageExternalTable(
const StorageID & table_id,
std::unique_ptr<ExternalTableSettings> settings,
const String & comment,
bool is_attach,
ContextPtr context_);

Expand Down
Loading