Support BACKUP ALL command.

This commit is contained in:
Vitaly Baranov 2023-03-30 00:11:13 +02:00
parent 3e9f4750f3
commit 42c2ccb7cc
2 changed files with 52 additions and 8 deletions

View File

@ -103,7 +103,7 @@ namespace
});
}
bool parseElement(IParser::Pos & pos, Expected & expected, bool allow_all, Element & element)
bool parseElement(IParser::Pos & pos, Expected & expected, Element & element)
{
return IParserBase::wrapParseImpl(pos, [&]
{
@ -169,7 +169,7 @@ namespace
return true;
}
if (allow_all && ParserKeyword{"ALL"}.ignore(pos, expected))
if (ParserKeyword{"ALL"}.ignore(pos, expected))
{
element.type = ElementType::ALL;
parseExceptDatabases(pos, expected, element.except_databases);
@ -181,7 +181,7 @@ namespace
});
}
bool parseElements(IParser::Pos & pos, Expected & expected, bool allow_all, std::vector<Element> & elements)
bool parseElements(IParser::Pos & pos, Expected & expected, std::vector<Element> & elements)
{
return IParserBase::wrapParseImpl(pos, [&]
{
@ -190,7 +190,7 @@ namespace
auto parse_element = [&]
{
Element element;
if (parseElement(pos, expected, allow_all, element))
if (parseElement(pos, expected, element))
{
result.emplace_back(std::move(element));
return true;
@ -334,11 +334,8 @@ bool ParserBackupQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
else
return false;
/// Disable "ALL" if this is a RESTORE command.
bool allow_all = (kind == Kind::RESTORE);
std::vector<Element> elements;
if (!parseElements(pos, expected, allow_all, elements))
if (!parseElements(pos, expected, elements))
return false;
String cluster;

View File

@ -1184,6 +1184,53 @@ def test_restore_partition():
)
def test_backup_all():
create_and_fill_table()
session_id = new_session_id()
instance.http_query(
"CREATE TEMPORARY TABLE temp_tbl(s String)", params={"session_id": session_id}
)
instance.http_query(
"INSERT INTO temp_tbl VALUES ('q'), ('w'), ('e')",
params={"session_id": session_id},
)
instance.query("CREATE FUNCTION two_and_half AS (x) -> x * 2.5")
instance.query("CREATE USER u1 IDENTIFIED BY 'qwe123' SETTINGS custom_a = 1")
backup_name = new_backup_name()
instance.http_query(
f"BACKUP ALL TO {backup_name}",
params={"session_id": session_id},
)
instance.query("DROP TABLE test.table")
instance.query("DROP FUNCTION two_and_half")
instance.query("DROP USER u1")
session_id = new_session_id()
instance.http_query(
f"RESTORE ALL FROM {backup_name}",
params={"session_id": session_id},
method="POST",
)
assert instance.query("SELECT count(), sum(x) FROM test.table") == "100\t4950\n"
assert instance.http_query(
"SELECT * FROM temp_tbl ORDER BY s", params={"session_id": session_id}
) == TSV([["e"], ["q"], ["w"]])
assert instance.query("SELECT two_and_half(6)") == "15\n"
assert (
instance.query("SHOW CREATE USER u1")
== "CREATE USER u1 IDENTIFIED WITH sha256_password SETTINGS custom_a = 1\n"
)
def test_operation_id():
create_and_fill_table(n=30)