Skip to content

Commit

Permalink
fix show create stream syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
yl-lisen committed Oct 18, 2024
1 parent 803e902 commit 04ee1d3
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 9 deletions.
14 changes: 11 additions & 3 deletions src/Parsers/ParserTablePropertiesQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<ASTExistsTableQuery>();
else if (s_dictionary.checkWithoutMoving(pos, expected))
query = std::make_shared<ASTExistsDictionaryQuery>();
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 24 additions & 2 deletions src/Parsers/TablePropertiesQueriesASTs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,6 +86,17 @@ using ASTShowCreateDictionaryQuery = ASTQueryWithTableAndOutputImpl<ASTShowCreat
class ASTExistsDatabaseQuery : public ASTQueryWithTableAndOutputImpl<ASTExistsDatabaseQueryIDAndQueryNames>
{
protected:
/// proton: starts
ASTPtr clone() const override
{
auto res = std::make_shared<ASTExistsDatabaseQuery>(*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
Expand All @@ -96,6 +107,17 @@ class ASTExistsDatabaseQuery : public ASTQueryWithTableAndOutputImpl<ASTExistsDa
class ASTShowCreateDatabaseQuery : public ASTQueryWithTableAndOutputImpl<ASTShowCreateDatabaseQueryIDAndQueryNames>
{
protected:
/// proton: starts
ASTPtr clone() const override
{
auto res = std::make_shared<ASTShowCreateDatabaseQuery>(*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
Expand Down
57 changes: 53 additions & 4 deletions src/Parsers/tests/gtest_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Parsers/ParserCreateQuery.h>
/// proton: starts
#include <Parsers/ParserDropQuery.h>
#include <Parsers/ParserTablePropertiesQuery.h>
/// proton: ends
#include <Parsers/ParserOptimizeQuery.h>
#include <Parsers/ParserQueryWithOutput.h>
Expand Down Expand Up @@ -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<ParserAlterQuery>()),
Expand All @@ -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<ParserDropQuery>()),
Expand All @@ -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<ParserTablePropertiesQuery>()),
::testing::ValuesIn(std::initializer_list<ParserTestCase>{
{
"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

0 comments on commit 04ee1d3

Please sign in to comment.