mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Merge pull request #31062 from Enmk/Governance/view_comment
Views with comment
This commit is contained in:
commit
33374f8b0a
@ -427,8 +427,11 @@ void ASTCreateQuery::formatQueryImpl(const FormatSettings & settings, FormatStat
|
||||
|
||||
if (select)
|
||||
{
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << " AS" << settings.nl_or_ws << (settings.hilite ? hilite_none : "");
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << " AS"
|
||||
<< (comment ? "(" : "")
|
||||
<< settings.nl_or_ws << (settings.hilite ? hilite_none : "");
|
||||
select->formatImpl(settings, state, frame);
|
||||
settings.ostr << (comment ? ")" : "");
|
||||
}
|
||||
|
||||
if (tables)
|
||||
|
@ -747,6 +747,7 @@ bool ParserCreateLiveViewQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & e
|
||||
if (!select_p.parse(pos, select, expected))
|
||||
return false;
|
||||
|
||||
auto comment = parseComment(pos, expected);
|
||||
|
||||
auto query = std::make_shared<ASTCreateQuery>();
|
||||
node = query;
|
||||
@ -781,6 +782,9 @@ bool ParserCreateLiveViewQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & e
|
||||
if (live_view_periodic_refresh)
|
||||
query->live_view_periodic_refresh.emplace(live_view_periodic_refresh->as<ASTLiteral &>().value.safeGet<UInt64>());
|
||||
|
||||
if (comment)
|
||||
query->set(query->comment, comment);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -280,7 +280,8 @@ StorageLiveView::StorageLiveView(
|
||||
const StorageID & table_id_,
|
||||
ContextPtr context_,
|
||||
const ASTCreateQuery & query,
|
||||
const ColumnsDescription & columns_)
|
||||
const ColumnsDescription & columns_,
|
||||
const String & comment)
|
||||
: IStorage(table_id_)
|
||||
, WithContext(context_->getGlobalContext())
|
||||
{
|
||||
@ -291,6 +292,9 @@ StorageLiveView::StorageLiveView(
|
||||
|
||||
StorageInMemoryMetadata storage_metadata;
|
||||
storage_metadata.setColumns(columns_);
|
||||
if (!comment.empty())
|
||||
storage_metadata.setComment(comment);
|
||||
|
||||
setInMemoryMetadata(storage_metadata);
|
||||
|
||||
if (!query.select)
|
||||
@ -621,7 +625,7 @@ void registerStorageLiveView(StorageFactory & factory)
|
||||
"Experimental LIVE VIEW feature is not enabled (the setting 'allow_experimental_live_view')",
|
||||
ErrorCodes::SUPPORT_IS_DISABLED);
|
||||
|
||||
return StorageLiveView::create(args.table_id, args.getLocalContext(), args.query, args.columns);
|
||||
return StorageLiveView::create(args.table_id, args.getLocalContext(), args.query, args.columns, args.comment);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -233,7 +233,7 @@ private:
|
||||
ContextPtr context_,
|
||||
const ASTCreateQuery & query,
|
||||
const ColumnsDescription & columns
|
||||
);
|
||||
, const String & comment);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -156,9 +156,6 @@ StoragePtr StorageFactory::get(
|
||||
throw Exception("Unknown table engine " + name, ErrorCodes::UNKNOWN_STORAGE);
|
||||
}
|
||||
|
||||
if (query.comment)
|
||||
comment = query.comment->as<ASTLiteral &>().value.get<String>();
|
||||
|
||||
auto check_feature = [&](String feature_description, FeatureMatcherFn feature_matcher_fn)
|
||||
{
|
||||
if (!feature_matcher_fn(it->second.features))
|
||||
@ -204,6 +201,9 @@ StoragePtr StorageFactory::get(
|
||||
}
|
||||
}
|
||||
|
||||
if (query.comment)
|
||||
comment = query.comment->as<ASTLiteral &>().value.get<String>();
|
||||
|
||||
ASTs empty_engine_args;
|
||||
Arguments arguments{
|
||||
.engine_name = name,
|
||||
|
@ -60,7 +60,8 @@ StorageMaterializedView::StorageMaterializedView(
|
||||
ContextPtr local_context,
|
||||
const ASTCreateQuery & query,
|
||||
const ColumnsDescription & columns_,
|
||||
bool attach_)
|
||||
bool attach_,
|
||||
const String & comment)
|
||||
: IStorage(table_id_), WithMutableContext(local_context->getGlobalContext())
|
||||
{
|
||||
StorageInMemoryMetadata storage_metadata;
|
||||
@ -81,6 +82,9 @@ StorageMaterializedView::StorageMaterializedView(
|
||||
|
||||
auto select = SelectQueryDescription::getSelectQueryFromASTForMatView(query.select->clone(), local_context);
|
||||
storage_metadata.setSelectQuery(select);
|
||||
if (!comment.empty())
|
||||
storage_metadata.setComment(comment);
|
||||
|
||||
setInMemoryMetadata(storage_metadata);
|
||||
|
||||
bool point_to_itself_by_uuid = has_inner_table && query.to_inner_uuid != UUIDHelpers::Nil
|
||||
@ -432,7 +436,7 @@ void registerStorageMaterializedView(StorageFactory & factory)
|
||||
/// Pass local_context here to convey setting for inner table
|
||||
return StorageMaterializedView::create(
|
||||
args.table_id, args.getLocalContext(), args.query,
|
||||
args.columns, args.attach);
|
||||
args.columns, args.attach, args.comment);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,8 @@ protected:
|
||||
ContextPtr local_context,
|
||||
const ASTCreateQuery & query,
|
||||
const ColumnsDescription & columns_,
|
||||
bool attach_);
|
||||
bool attach_,
|
||||
const String & comment);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
live_view_comment_test LiveView live view
|
||||
materialized_view_comment_test MaterializedView materialized view
|
||||
view_comment_test View simple view
|
12
tests/queries/0_stateless/02048_views_with_comment.sql
Normal file
12
tests/queries/0_stateless/02048_views_with_comment.sql
Normal file
@ -0,0 +1,12 @@
|
||||
-- Make sure that any kind of `VIEW` can be created with a `COMMENT` clause
|
||||
-- and value of that clause is visible as `comment` column of `system.tables` table.
|
||||
|
||||
CREATE VIEW view_comment_test AS (SELECT 1) COMMENT 'simple view';
|
||||
CREATE MATERIALIZED VIEW materialized_view_comment_test TO test1 (a UInt64) AS (SELECT 1) COMMENT 'materialized view';
|
||||
|
||||
SET allow_experimental_live_view=1;
|
||||
CREATE LIVE VIEW live_view_comment_test AS (SELECT 1) COMMENT 'live view';
|
||||
|
||||
SYSTEM FLUSH LOGS;
|
||||
|
||||
SELECT name, engine, comment FROM system.tables WHERE database == currentDatabase() ORDER BY name;
|
Loading…
Reference in New Issue
Block a user