mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Fix parsing of partition expressions surrounded by parens
This commit is contained in:
parent
407b7a4651
commit
69273b4645
@ -8,6 +8,7 @@
|
||||
#include <Parsers/ASTIdentifier.h>
|
||||
#include <Common/typeid_cast.h>
|
||||
#include <Parsers/ASTQueryParameter.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -18,8 +19,6 @@ bool ParserPartition::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
||||
ParserKeyword s_all("ALL");
|
||||
ParserStringLiteral parser_string_literal;
|
||||
ParserSubstitution parser_substitution;
|
||||
ParserLiteral literal_parser;
|
||||
ParserTupleOfLiterals tuple_of_literals;
|
||||
ParserExpression parser_expr;
|
||||
|
||||
auto partition = std::make_shared<ASTPartition>();
|
||||
@ -45,34 +44,35 @@ bool ParserPartition::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
||||
{
|
||||
ASTPtr value;
|
||||
std::optional<size_t> fields_count;
|
||||
if (literal_parser.parse(pos, value, expected) || tuple_of_literals.parse(pos, value, expected))
|
||||
{
|
||||
auto * literal = value->as<ASTLiteral>();
|
||||
if (literal->value.getType() == Field::Types::Tuple)
|
||||
{
|
||||
fields_count = literal->value.get<const Tuple &>().size();
|
||||
}
|
||||
else
|
||||
{
|
||||
fields_count = 1;
|
||||
}
|
||||
}
|
||||
else if (parser_substitution.parse(pos, value, expected))
|
||||
if (parser_substitution.parse(pos, value, expected))
|
||||
{
|
||||
/// It can be tuple substitution
|
||||
fields_count = std::nullopt;
|
||||
}
|
||||
else if (parser_expr.parse(pos, value, expected))
|
||||
{
|
||||
const auto * tuple_ast = value->as<ASTFunction>();
|
||||
if (tuple_ast && tuple_ast->name == "tuple")
|
||||
if (const auto * tuple_ast = value->as<ASTFunction>(); tuple_ast)
|
||||
{
|
||||
if (tuple_ast->name != "tuple")
|
||||
return false;
|
||||
|
||||
const auto * arguments_ast = tuple_ast->arguments->as<ASTExpressionList>();
|
||||
if (arguments_ast)
|
||||
fields_count = arguments_ast->children.size();
|
||||
else
|
||||
fields_count = 0;
|
||||
}
|
||||
else if (const auto* literal_ast = value->as<ASTLiteral>(); literal_ast)
|
||||
{
|
||||
if (literal_ast->value.getType() == Field::Types::Tuple)
|
||||
{
|
||||
fields_count = literal_ast->value.get<const Tuple &>().size();
|
||||
}
|
||||
else
|
||||
{
|
||||
fields_count = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
@ -7,3 +7,8 @@
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
|
@ -10,6 +10,24 @@ PARTITION BY toMonday(EventDate);
|
||||
|
||||
INSERT INTO test VALUES(toDate('2023-10-09'));
|
||||
|
||||
ALTER TABLE test DROP PARTITION ('2023-10-09');
|
||||
|
||||
SELECT count() FROM test;
|
||||
|
||||
INSERT INTO test VALUES(toDate('2023-10-09'));
|
||||
|
||||
ALTER TABLE test DROP PARTITION (('2023-10-09'));
|
||||
|
||||
SELECT count() FROM test;
|
||||
|
||||
INSERT INTO test VALUES(toDate('2023-10-09'));
|
||||
|
||||
ALTER TABLE test DROP PARTITION '2023-10-09';
|
||||
|
||||
SELECT count() FROM test;
|
||||
|
||||
INSERT INTO test VALUES(toDate('2023-10-09'));
|
||||
|
||||
SET param_partition='2023-10-09';
|
||||
|
||||
ALTER TABLE test DROP PARTITION {partition:String};
|
||||
@ -51,6 +69,17 @@ ENGINE = MergeTree
|
||||
ORDER BY tuple()
|
||||
PARTITION BY (a * b, b * b);
|
||||
|
||||
INSERT INTO test2 VALUES(1, 2);
|
||||
|
||||
ALTER TABLE test2 DROP PARTITION tuple(2, 4);
|
||||
|
||||
SELECT count() FROM test2;
|
||||
|
||||
INSERT INTO test2 VALUES(1, 2);
|
||||
|
||||
ALTER TABLE test2 DROP PARTITION (2, 4);
|
||||
|
||||
SELECT count() FROM test2;
|
||||
|
||||
INSERT INTO test2 VALUES(1, 2);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user