@@ -1500,4 +1500,109 @@ public void testAlterTableKeys() throws JSQLParserException {
1500
1500
AlterExpression alterExpEnable = alterEnable .getAlterExpressions ().get (0 );
1501
1501
assertEquals (AlterOperation .ENABLE_KEYS , alterExpEnable .getOperation ());
1502
1502
}
1503
+
1504
+ @ Test
1505
+ public void testAlterTablePartitionByRangeColumns () throws JSQLParserException {
1506
+ String sql = "ALTER TABLE `payment_lock` " +
1507
+ "PARTITION BY RANGE COLUMNS(`created_at`) (" +
1508
+ "PARTITION p20210217 VALUES LESS THAN ('20210218') ENGINE = InnoDB, " +
1509
+ "PARTITION p20210218 VALUES LESS THAN ('20210219') ENGINE = InnoDB);" ;
1510
+ Statement stmt = CCJSqlParserUtil .parse (sql );
1511
+ assertInstanceOf (Alter .class , stmt );
1512
+ Alter alter = (Alter ) stmt ;
1513
+ assertEquals ("`payment_lock`" , alter .getTable ().getFullyQualifiedName ());
1514
+
1515
+ List <AlterExpression > alterExpressions = alter .getAlterExpressions ();
1516
+ assertNotNull (alterExpressions );
1517
+ assertEquals (1 , alterExpressions .size ());
1518
+
1519
+ AlterExpression partitionExp = alterExpressions .get (0 );
1520
+ assertEquals (AlterOperation .PARTITION_BY , partitionExp .getOperation ());
1521
+ List <PartitionDefinition > partitions = partitionExp .getPartitionDefinitions ();
1522
+ assertNotNull (partitions );
1523
+ assertEquals (2 , partitions .size ());
1524
+
1525
+ assertEquals ("p20210217" , partitions .get (0 ).getPartitionName ());
1526
+ assertEquals ("VALUES LESS THAN" , partitions .get (0 ).getPartitionOperation ());
1527
+ assertEquals (Collections .singletonList ("'20210218'" ), partitions .get (0 ).getValues ());
1528
+
1529
+ assertEquals ("p20210218" , partitions .get (1 ).getPartitionName ());
1530
+ assertEquals ("VALUES LESS THAN" , partitions .get (1 ).getPartitionOperation ());
1531
+ assertEquals (Collections .singletonList ("'20210219'" ), partitions .get (1 ).getValues ());
1532
+
1533
+ assertSqlCanBeParsedAndDeparsed (sql );
1534
+ }
1535
+
1536
+ @ Test
1537
+ public void testAlterTablePartitionByRangeUnixTimestamp () throws JSQLParserException {
1538
+ String sql = "ALTER TABLE `test`.`pipeline_service_metadata_history` " +
1539
+ "PARTITION BY RANGE (FLOOR(UNIX_TIMESTAMP(requested_at))) (" +
1540
+ "PARTITION p202104 VALUES LESS THAN (UNIX_TIMESTAMP('2021-05-01 00:00:00')) ENGINE = InnoDB, "
1541
+ +
1542
+ "PARTITION p202105 VALUES LESS THAN (UNIX_TIMESTAMP('2021-06-01 00:00:00')) ENGINE = InnoDB);" ;
1543
+ Statement stmt = CCJSqlParserUtil .parse (sql );
1544
+ assertInstanceOf (Alter .class , stmt );
1545
+ Alter alter = (Alter ) stmt ;
1546
+ assertEquals ("`test`.`pipeline_service_metadata_history`" ,
1547
+ alter .getTable ().getFullyQualifiedName ());
1548
+
1549
+ List <AlterExpression > alterExpressions = alter .getAlterExpressions ();
1550
+ assertNotNull (alterExpressions );
1551
+ assertEquals (1 , alterExpressions .size ());
1552
+
1553
+ AlterExpression partitionExp = alterExpressions .get (0 );
1554
+ assertEquals (AlterOperation .PARTITION_BY , partitionExp .getOperation ());
1555
+ List <PartitionDefinition > partitions = partitionExp .getPartitionDefinitions ();
1556
+ assertNotNull (partitions );
1557
+ assertEquals (2 , partitions .size ());
1558
+
1559
+ assertEquals ("p202104" , partitions .get (0 ).getPartitionName ());
1560
+ assertEquals ("VALUES LESS THAN" , partitions .get (0 ).getPartitionOperation ());
1561
+ assertEquals (Collections .singletonList ("UNIX_TIMESTAMP('2021-05-01 00:00:00')" ),
1562
+ partitions .get (0 ).getValues ());
1563
+
1564
+ assertEquals ("p202105" , partitions .get (1 ).getPartitionName ());
1565
+ assertEquals ("VALUES LESS THAN" , partitions .get (1 ).getPartitionOperation ());
1566
+ assertEquals (Collections .singletonList ("UNIX_TIMESTAMP('2021-06-01 00:00:00')" ),
1567
+ partitions .get (1 ).getValues ());
1568
+
1569
+ assertSqlCanBeParsedAndDeparsed (sql );
1570
+ }
1571
+
1572
+ @ Test
1573
+ public void testAlterTablePartitionByRangeUnixTimestamp2 () throws JSQLParserException {
1574
+ String sql = "ALTER TABLE MP_MNEWS.PUR_MNEWS_CONTS " +
1575
+ "PARTITION BY RANGE (UNIX_TIMESTAMP(REG_DATE_TS)) (" +
1576
+ "PARTITION p202007 VALUES LESS THAN (1596207600) ENGINE = InnoDB, " +
1577
+ "PARTITION p202008 VALUES LESS THAN (1598886000) ENGINE = InnoDB, " +
1578
+ "PARTITION p202009 VALUES LESS THAN (1601478000) ENGINE = InnoDB);" ;
1579
+ Statement stmt = CCJSqlParserUtil .parse (sql );
1580
+ assertInstanceOf (Alter .class , stmt );
1581
+ Alter alter = (Alter ) stmt ;
1582
+ assertEquals ("MP_MNEWS.PUR_MNEWS_CONTS" , alter .getTable ().getFullyQualifiedName ());
1583
+
1584
+ List <AlterExpression > alterExpressions = alter .getAlterExpressions ();
1585
+ assertNotNull (alterExpressions );
1586
+ assertEquals (1 , alterExpressions .size ());
1587
+
1588
+ AlterExpression partitionExp = alterExpressions .get (0 );
1589
+ assertEquals (AlterOperation .PARTITION_BY , partitionExp .getOperation ());
1590
+ List <PartitionDefinition > partitions = partitionExp .getPartitionDefinitions ();
1591
+ assertNotNull (partitions );
1592
+ assertEquals (3 , partitions .size ());
1593
+
1594
+ assertEquals ("p202007" , partitions .get (0 ).getPartitionName ());
1595
+ assertEquals ("VALUES LESS THAN" , partitions .get (0 ).getPartitionOperation ());
1596
+ assertEquals (Collections .singletonList ("1596207600" ), partitions .get (0 ).getValues ());
1597
+
1598
+ assertEquals ("p202008" , partitions .get (1 ).getPartitionName ());
1599
+ assertEquals ("VALUES LESS THAN" , partitions .get (1 ).getPartitionOperation ());
1600
+ assertEquals (Collections .singletonList ("1598886000" ), partitions .get (1 ).getValues ());
1601
+
1602
+ assertEquals ("p202009" , partitions .get (2 ).getPartitionName ());
1603
+ assertEquals ("VALUES LESS THAN" , partitions .get (2 ).getPartitionOperation ());
1604
+ assertEquals (Collections .singletonList ("1601478000" ), partitions .get (2 ).getValues ());
1605
+
1606
+ assertSqlCanBeParsedAndDeparsed (sql );
1607
+ }
1503
1608
}
0 commit comments