File tree Expand file tree Collapse file tree 2 files changed +61
-6
lines changed
Expand file tree Collapse file tree 2 files changed +61
-6
lines changed Original file line number Diff line number Diff line change @@ -6628,12 +6628,18 @@ impl<'a> Parser<'a> {
66286628 partition: Partition::Part(self.parse_expr()?),
66296629 }
66306630 } else if self.parse_keyword(Keyword::PARTITION) {
6631- self.expect_token(&Token::LParen)?;
6632- let partitions = self.parse_comma_separated(Parser::parse_expr)?;
6633- self.expect_token(&Token::RParen)?;
6634- AlterTableOperation::DropPartitions {
6635- partitions,
6636- if_exists: false,
6631+ if self.peek_token().token == Token::LParen {
6632+ self.expect_token(&Token::LParen)?;
6633+ let partitions = self.parse_comma_separated(Parser::parse_expr)?;
6634+ self.expect_token(&Token::RParen)?;
6635+ AlterTableOperation::DropPartitions {
6636+ partitions,
6637+ if_exists: false,
6638+ }
6639+ } else {
6640+ AlterTableOperation::DropPartition {
6641+ partition: Partition::Expr(self.parse_expr()?),
6642+ }
66376643 }
66386644 } else if self.parse_keyword(Keyword::CONSTRAINT) {
66396645 let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
Original file line number Diff line number Diff line change @@ -612,6 +612,55 @@ fn parse_alter_table_drop_partition_and_part() {
612612 }
613613 _ => unreachable ! ( ) ,
614614 }
615+
616+ // DROP PARTITION with string literal (no parens)
617+ match clickhouse_and_generic ( )
618+ . verified_stmt ( "ALTER TABLE mt DROP PARTITION '2020-11-21'" )
619+ {
620+ Statement :: AlterTable {
621+ name, operations, ..
622+ } => {
623+ assert_eq ! ( "mt" , name. to_string( ) ) ;
624+ assert_eq ! (
625+ operations[ 0 ] ,
626+ AlterTableOperation :: DropPartition {
627+ partition: Partition :: Expr ( Expr :: Value ( Value :: SingleQuotedString (
628+ "2020-11-21" . to_string( )
629+ ) ) ) ,
630+ }
631+ ) ;
632+ }
633+ _ => unreachable ! ( ) ,
634+ }
635+
636+ // DROP PARTITION with numeric literal (no parens)
637+ match clickhouse_and_generic ( ) . verified_stmt ( "ALTER TABLE visits DROP PARTITION 201901" ) {
638+ Statement :: AlterTable {
639+ name, operations, ..
640+ } => {
641+ assert_eq ! ( "visits" , name. to_string( ) ) ;
642+ assert_eq ! (
643+ operations[ 0 ] ,
644+ AlterTableOperation :: DropPartition {
645+ partition: Partition :: Expr ( Expr :: Value ( Value :: Number (
646+ "201901" . to_string( ) ,
647+ false
648+ ) ) ) ,
649+ }
650+ ) ;
651+ }
652+ _ => unreachable ! ( ) ,
653+ }
654+
655+ // DROP PARTITION with tuple() function call
656+ clickhouse_and_generic ( ) . verified_stmt (
657+ "ALTER TABLE visits DROP PARTITION tuple(toYYYYMM(toDate('2019-01-25')))" ,
658+ ) ;
659+
660+ // Multiple statements: DROP PARTITION + DROP PART
661+ clickhouse_and_generic ( ) . parse_sql_statements (
662+ "ALTER TABLE mt DROP PARTITION '2020-11-21'; ALTER TABLE mt DROP PART 'all_4_4_0'" ,
663+ ) . unwrap ( ) ;
615664}
616665
617666#[ test]
You can’t perform that action at this time.
0 commit comments