mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Added support for SystemLog to specify COMMENT in ENGINE section
This commit is contained in:
parent
6bb6867a07
commit
1a096a87da
@ -43,6 +43,55 @@ namespace ErrorCodes
|
||||
extern const int LOGICAL_ERROR;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
class StorageWithComment : public IAST
|
||||
{
|
||||
public:
|
||||
ASTPtr storage;
|
||||
ASTPtr comment;
|
||||
|
||||
String getID(char) const override { return "Storage with comment definition"; }
|
||||
|
||||
ASTPtr clone() const override {
|
||||
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Method clone is not supported");
|
||||
}
|
||||
|
||||
void formatImpl(const FormatSettings &, FormatState &, FormatStateStacked) const override
|
||||
{
|
||||
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Method formatImpl is not supported");
|
||||
}
|
||||
};
|
||||
|
||||
class ParserStorageWithComment : public IParserBase
|
||||
{
|
||||
protected:
|
||||
const char * getName() const override { return "storage definition with comment"; }
|
||||
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override
|
||||
{
|
||||
ParserStorage storage_p;
|
||||
ASTPtr storage;
|
||||
|
||||
if (!storage_p.parse(pos, storage, expected))
|
||||
return false;
|
||||
|
||||
ParserKeyword s_comment("COMMENT");
|
||||
ParserStringLiteral string_literal_parser;
|
||||
ASTPtr comment;
|
||||
|
||||
if (s_comment.ignore(pos, expected))
|
||||
string_literal_parser.parse(pos, comment, expected);
|
||||
|
||||
auto storage_with_comment = std::make_shared<StorageWithComment>();
|
||||
storage_with_comment->storage = std::move(storage);
|
||||
storage_with_comment->comment = std::move(comment);
|
||||
|
||||
node = storage_with_comment;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@ -102,8 +151,9 @@ std::shared_ptr<TSystemLog> createSystemLog(
|
||||
engine += " TTL " + ttl;
|
||||
engine += " ORDER BY (event_date, event_time)";
|
||||
}
|
||||
|
||||
// Validate engine definition grammatically to prevent some configuration errors
|
||||
ParserStorage storage_parser;
|
||||
ParserStorageWithComment storage_parser;
|
||||
parseQuery(storage_parser, engine.data(), engine.data() + engine.size(),
|
||||
"Storage to create table for " + config_prefix, 0, DBMS_DEFAULT_MAX_PARSER_DEPTH);
|
||||
|
||||
@ -450,7 +500,6 @@ void SystemLog<LogElement>::prepareTable()
|
||||
is_prepared = true;
|
||||
}
|
||||
|
||||
|
||||
template <typename LogElement>
|
||||
ASTPtr SystemLog<LogElement>::getCreateTableQuery()
|
||||
{
|
||||
@ -465,11 +514,16 @@ ASTPtr SystemLog<LogElement>::getCreateTableQuery()
|
||||
new_columns_list->set(new_columns_list->columns, InterpreterCreateQuery::formatColumns(ordinary_columns, alias_columns));
|
||||
create->set(create->columns_list, new_columns_list);
|
||||
|
||||
ParserStorage storage_parser;
|
||||
ASTPtr storage_ast = parseQuery(
|
||||
ParserStorageWithComment storage_parser;
|
||||
|
||||
ASTPtr storage_with_comment_ast = parseQuery(
|
||||
storage_parser, storage_def.data(), storage_def.data() + storage_def.size(),
|
||||
"Storage to create table for " + LogElement::name(), 0, DBMS_DEFAULT_MAX_PARSER_DEPTH);
|
||||
create->set(create->storage, storage_ast);
|
||||
|
||||
StorageWithComment & storage_with_comment = storage_with_comment_ast->as<StorageWithComment &>();
|
||||
|
||||
create->set(create->storage, storage_with_comment.storage);
|
||||
create->set(create->comment, storage_with_comment.comment);
|
||||
|
||||
/// Write additional (default) settings for MergeTree engine to make it make it possible to compare ASTs
|
||||
/// and recreate tables on settings changes.
|
||||
|
42
tests/integration/test_system_logs_comment/test.py
Normal file
42
tests/integration/test_system_logs_comment/test.py
Normal file
@ -0,0 +1,42 @@
|
||||
# pylint: disable=line-too-long
|
||||
# pylint: disable=unused-argument
|
||||
# pylint: disable=redefined-outer-name
|
||||
|
||||
import pytest
|
||||
from helpers.cluster import ClickHouseCluster
|
||||
|
||||
cluster = ClickHouseCluster(__file__)
|
||||
node = cluster.add_instance('node_default', stay_alive=True)
|
||||
|
||||
@pytest.fixture(scope='module', autouse=True)
|
||||
def start_cluster():
|
||||
try:
|
||||
cluster.start()
|
||||
yield cluster
|
||||
finally:
|
||||
cluster.shutdown()
|
||||
|
||||
|
||||
def test_system_logs_comment():
|
||||
node.exec_in_container(['bash', '-c', f"""echo "
|
||||
<clickhouse>
|
||||
<query_log>
|
||||
<engine>ENGINE = MergeTree
|
||||
PARTITION BY (event_date)
|
||||
ORDER BY (event_time)
|
||||
TTL event_date + INTERVAL 14 DAY DELETE
|
||||
SETTINGS ttl_only_drop_parts=1
|
||||
COMMENT 'test_comment'
|
||||
</engine>
|
||||
<partition_by remove='remove'/>
|
||||
</query_log>
|
||||
</clickhouse>
|
||||
" > /etc/clickhouse-server/config.d/yyy-override-query_log.xml
|
||||
"""])
|
||||
node.restart_clickhouse()
|
||||
|
||||
node.query("select 1")
|
||||
node.query("system flush logs")
|
||||
|
||||
comment = node.query("SELECT comment FROM system.tables WHERE name = 'query_log'")
|
||||
assert comment =='test_comment\n'
|
Loading…
Reference in New Issue
Block a user