From 04ee1d31d1d52f05c665b1ad562ae6b14f3d045b Mon Sep 17 00:00:00 2001 From: Lisen <38773813+yl-lisen@users.noreply.github.com> Date: Fri, 18 Oct 2024 10:08:59 +0800 Subject: [PATCH] fix show create stream syntax --- src/Parsers/ParserTablePropertiesQuery.cpp | 14 ++++-- src/Parsers/TablePropertiesQueriesASTs.h | 26 +++++++++- src/Parsers/tests/gtest_Parser.cpp | 57 ++++++++++++++++++++-- 3 files changed, 88 insertions(+), 9 deletions(-) diff --git a/src/Parsers/ParserTablePropertiesQuery.cpp b/src/Parsers/ParserTablePropertiesQuery.cpp index 535df67df78..0a6c785ba8d 100644 --- a/src/Parsers/ParserTablePropertiesQuery.cpp +++ b/src/Parsers/ParserTablePropertiesQuery.cpp @@ -20,6 +20,9 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & ParserKeyword s_create("CREATE"); ParserKeyword s_database("DATABASE"); ParserKeyword s_table("TABLE"); + /// proton: starts. + ParserKeyword s_stream("STREAM"); + /// proton: ends. ParserKeyword s_view("VIEW"); ParserKeyword s_dictionary("DICTIONARY"); ParserToken s_dot(TokenType::Dot); @@ -51,7 +54,9 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & if (s_temporary.ignore(pos, expected)) temporary = true; - if (s_table.checkWithoutMoving(pos, expected)) + /// proton: starts. + if (s_stream.checkWithoutMoving(pos, expected) || s_table.checkWithoutMoving(pos, expected)) + /// proton: ends. query = std::make_shared(); else if (s_dictionary.checkWithoutMoving(pos, expected)) query = std::make_shared(); @@ -96,8 +101,11 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & if (temporary || s_temporary.ignore(pos, expected)) query->temporary = true; - if (!s_table.ignore(pos, expected)) - s_dictionary.ignore(pos, expected); + /// proton: starts. + if (!s_stream.ignore(pos, expected)) + if (!s_table.ignore(pos, expected)) + s_dictionary.ignore(pos, expected); + /// proton: ends. } if (!name_p.parse(pos, table, expected)) return false; diff --git a/src/Parsers/TablePropertiesQueriesASTs.h b/src/Parsers/TablePropertiesQueriesASTs.h index e125c9bc7c7..f3c2ef5a1de 100644 --- a/src/Parsers/TablePropertiesQueriesASTs.h +++ b/src/Parsers/TablePropertiesQueriesASTs.h @@ -18,8 +18,8 @@ struct ASTExistsDatabaseQueryIDAndQueryNames struct ASTExistsTableQueryIDAndQueryNames { static constexpr auto ID = "ExistsTableQuery"; - static constexpr auto Query = "EXISTS TABLE"; - static constexpr auto QueryTemporary = "EXISTS TEMPORARY TABLE"; + static constexpr auto Query = "EXISTS STREAM"; + static constexpr auto QueryTemporary = "EXISTS TEMPORARY STREAM"; }; struct ASTExistsViewQueryIDAndQueryNames @@ -86,6 +86,17 @@ using ASTShowCreateDictionaryQuery = ASTQueryWithTableAndOutputImpl { protected: + /// proton: starts + ASTPtr clone() const override + { + auto res = std::make_shared(*this); + res->children.clear(); + cloneOutputOptions(*res); + cloneTableOptions(*res); + return res; + } + /// proton: ends + void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override { settings.ostr << (settings.hilite ? hilite_keyword : "") << ASTExistsDatabaseQueryIDAndQueryNames::Query @@ -96,6 +107,17 @@ class ASTExistsDatabaseQuery : public ASTQueryWithTableAndOutputImpl { protected: + /// proton: starts + ASTPtr clone() const override + { + auto res = std::make_shared(*this); + res->children.clear(); + cloneOutputOptions(*res); + cloneTableOptions(*res); + return res; + } + /// proton: ends + void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override { settings.ostr << (settings.hilite ? hilite_keyword : "") << ASTShowCreateDatabaseQueryIDAndQueryNames::Query diff --git a/src/Parsers/tests/gtest_Parser.cpp b/src/Parsers/tests/gtest_Parser.cpp index f28b4030d01..37d2db72b44 100644 --- a/src/Parsers/tests/gtest_Parser.cpp +++ b/src/Parsers/tests/gtest_Parser.cpp @@ -3,6 +3,7 @@ #include /// proton: starts #include +#include /// proton: ends #include #include @@ -236,9 +237,7 @@ INSTANTIATE_TEST_SUITE_P(ParserCreateStreamQuery, ParserTest, "CREATE STREAM tests\n(\n `device` string\n)" } }))); -/// proton: ends -/// proton: starts. ALTER STREAM test cases INSTANTIATE_TEST_SUITE_P(ParserAlterStreamQuery, ParserTest, ::testing::Combine( ::testing::Values(std::make_shared()), @@ -260,9 +259,7 @@ INSTANTIATE_TEST_SUITE_P(ParserAlterStreamQuery, ParserTest, "ALTER STREAM tests\n DROP COLUMN id1" } }))); -/// proton: ends -/// proton: starts. DROP STREAM test cases INSTANTIATE_TEST_SUITE_P(ParserDropStreamQuery, ParserTest, ::testing::Combine( ::testing::Values(std::make_shared()), @@ -280,4 +277,56 @@ INSTANTIATE_TEST_SUITE_P(ParserDropStreamQuery, ParserTest, "TRUNCATE STREAM tests" } }))); + + +INSTANTIATE_TEST_SUITE_P(ParserTablePropertiesQuery, ParserTest, + ::testing::Combine( + ::testing::Values(std::make_shared()), + ::testing::ValuesIn(std::initializer_list{ + { + "SHOW CREATE DATABASE db", + "SHOW CREATE DATABASE db", + }, + { + "SHOW CREATE STREAM test", + "SHOW CREATE STREAM test", + }, + { + "SHOW CREATE STREAM db.test", + "SHOW CREATE STREAM db.test", + }, + { + "SHOW CREATE TABLE db.test", + "SHOW CREATE STREAM db.test", + }, + { + "SHOW CREATE VIEW db.testv", + "SHOW CREATE VIEW db.testv", + }, + { + "SHOW CREATE DICTIONARY db.testd", + "SHOW CREATE DICTIONARY db.testd", + }, + { + "EXISTS DATABASE db", + "EXISTS DATABASE db", + }, + { + "EXISTS STREAM db.test", + "EXISTS STREAM db.test", + }, + { + "EXISTS TABLE db.test", + "EXISTS STREAM db.test", + }, + { + "EXISTS VIEW db.testv", + "EXISTS VIEW db.testv", + }, + { + "EXISTS DICTIONARY db.testd", + "EXISTS DICTIONARY db.testd", + } + } +))); /// proton: ends