Merge pull request #12653 from zhang2014/feature/truncate_without_table

ISSUES-4006 support truncate table without table keyword
This commit is contained in:
alexey-milovidov 2020-07-22 21:43:04 +03:00 committed by GitHub
commit f75c242491
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 3 deletions

View File

@ -11,7 +11,7 @@ namespace DB
namespace
{
bool parseDropQuery(IParser::Pos & pos, ASTPtr & node, Expected & expected)
bool parseDropQuery(IParser::Pos & pos, ASTPtr & node, Expected & expected, bool optional_table_keyword = false)
{
ParserKeyword s_temporary("TEMPORARY");
ParserKeyword s_table("TABLE");
@ -55,7 +55,7 @@ bool parseDropQuery(IParser::Pos & pos, ASTPtr & node, Expected & expected)
else if (s_temporary.ignore(pos, expected))
temporary = true;
if (!is_view && !is_dictionary && !s_table.ignore(pos, expected))
if (!is_view && !is_dictionary && (!s_table.ignore(pos, expected) && !optional_table_keyword))
{
return false;
}
@ -114,7 +114,7 @@ bool parseDetachQuery(IParser::Pos & pos, ASTPtr & node, Expected & expected)
bool parseTruncateQuery(IParser::Pos & pos, ASTPtr & node, Expected & expected)
{
if (parseDropQuery(pos, node, expected))
if (parseDropQuery(pos, node, expected, true))
{
auto * drop_query = node->as<ASTDropQuery>();
drop_query->kind = ASTDropQuery::Kind::Truncate;

View File

@ -0,0 +1,3 @@
1
2
3

View File

@ -0,0 +1,12 @@
DROP TABLE IF EXISTS truncate_test;
CREATE TABLE truncate_test(uint8 UInt8) ENGINE = Log;
INSERT INTO truncate_test VALUES(1), (2), (3);
SELECT * FROM truncate_test ORDER BY uint8;
TRUNCATE truncate_test;
SELECT * FROM truncate_test ORDER BY uint8;