@@ -733,11 +733,12 @@ func TestTemporalRangePartitioningNextRotation(t *testing.T) {
733
733
734
734
func TestTemporalRangePartitioningRetention (t * testing.T ) {
735
735
tcases := []struct {
736
- name string
737
- create string
738
- expire string
739
- expectStatement string
740
- expectErr error
736
+ name string
737
+ create string
738
+ expire string
739
+ expectStatement string
740
+ expectDistinctStatements []string
741
+ expectErr error
741
742
}{
742
743
{
743
744
name : "not partitioned" ,
@@ -789,6 +790,9 @@ func TestTemporalRangePartitioningRetention(t *testing.T) {
789
790
)` ,
790
791
expire : "2024-12-19 00:00:00" ,
791
792
expectStatement : "ALTER TABLE `t` DROP PARTITION `p0`" ,
793
+ expectDistinctStatements : []string {
794
+ "ALTER TABLE `t` DROP PARTITION `p0`" ,
795
+ },
792
796
},
793
797
{
794
798
name : "range columns over datetime, day interval with 7 days and MAXVALUE, single partition dropped, passed threshold" ,
@@ -801,6 +805,9 @@ func TestTemporalRangePartitioningRetention(t *testing.T) {
801
805
)` ,
802
806
expire : "2024-12-19 01:02:03" ,
803
807
expectStatement : "ALTER TABLE `t` DROP PARTITION `p0`" ,
808
+ expectDistinctStatements : []string {
809
+ "ALTER TABLE `t` DROP PARTITION `p0`" ,
810
+ },
804
811
},
805
812
{
806
813
name : "range columns over datetime, day interval with 7 days and MAXVALUE, two partitions dropped" ,
@@ -813,6 +820,10 @@ func TestTemporalRangePartitioningRetention(t *testing.T) {
813
820
)` ,
814
821
expire : "2024-12-20 00:00:00" ,
815
822
expectStatement : "ALTER TABLE `t` DROP PARTITION `p0`, `p20241220`" ,
823
+ expectDistinctStatements : []string {
824
+ "ALTER TABLE `t` DROP PARTITION `p0`" ,
825
+ "ALTER TABLE `t` DROP PARTITION `p20241220`" ,
826
+ },
816
827
},
817
828
{
818
829
name : "range columns over datetime, day interval with 7 days and MAXVALUE, two partitions dropped, passed threshold" ,
@@ -825,6 +836,10 @@ func TestTemporalRangePartitioningRetention(t *testing.T) {
825
836
)` ,
826
837
expire : "2024-12-20 23:59:59" ,
827
838
expectStatement : "ALTER TABLE `t` DROP PARTITION `p0`, `p20241220`" ,
839
+ expectDistinctStatements : []string {
840
+ "ALTER TABLE `t` DROP PARTITION `p0`" ,
841
+ "ALTER TABLE `t` DROP PARTITION `p20241220`" ,
842
+ },
828
843
},
829
844
{
830
845
name : "range columns over datetime, day interval with 7 days and MAXVALUE, error dropping all partitions" ,
@@ -872,6 +887,9 @@ func TestTemporalRangePartitioningRetention(t *testing.T) {
872
887
)` ,
873
888
expire : "2024-12-19 00:00:00" ,
874
889
expectStatement : "ALTER TABLE `t` DROP PARTITION `p0`" ,
890
+ expectDistinctStatements : []string {
891
+ "ALTER TABLE `t` DROP PARTITION `p0`" ,
892
+ },
875
893
},
876
894
{
877
895
name : "day interval using TO_DAYS, DATETIME, drop 2 partitions" ,
@@ -884,6 +902,10 @@ func TestTemporalRangePartitioningRetention(t *testing.T) {
884
902
)` ,
885
903
expire : "2024-12-20 00:00:00" ,
886
904
expectStatement : "ALTER TABLE `t` DROP PARTITION `p0`, `p20241219`" ,
905
+ expectDistinctStatements : []string {
906
+ "ALTER TABLE `t` DROP PARTITION `p0`" ,
907
+ "ALTER TABLE `t` DROP PARTITION `p20241219`" ,
908
+ },
887
909
},
888
910
{
889
911
name : "day interval using TO_DAYS, DATETIME, error dropping all partitions" ,
@@ -919,6 +941,9 @@ func TestTemporalRangePartitioningRetention(t *testing.T) {
919
941
)` ,
920
942
expire : "2024-12-19 00:00:00" ,
921
943
expectStatement : "ALTER TABLE `t` DROP PARTITION `p0`" ,
944
+ expectDistinctStatements : []string {
945
+ "ALTER TABLE `t` DROP PARTITION `p0`" ,
946
+ },
922
947
},
923
948
{
924
949
name : "day interval using TO_DAYS in expression, DATETIME, drop 2 partitions" ,
@@ -931,6 +956,10 @@ func TestTemporalRangePartitioningRetention(t *testing.T) {
931
956
)` ,
932
957
expire : "2024-12-20 00:00:00" ,
933
958
expectStatement : "ALTER TABLE `t` DROP PARTITION `p0`, `p20241219`" ,
959
+ expectDistinctStatements : []string {
960
+ "ALTER TABLE `t` DROP PARTITION `p0`" ,
961
+ "ALTER TABLE `t` DROP PARTITION `p20241219`" ,
962
+ },
934
963
},
935
964
{
936
965
name : "day interval using TO_DAYS in expression, DATETIME, error dropping all partitions" ,
@@ -960,20 +989,44 @@ func TestTemporalRangePartitioningRetention(t *testing.T) {
960
989
entity , err := NewCreateTableEntityFromSQL (env , tcase .create )
961
990
require .NoError (t , err )
962
991
963
- diff , err := TemporalRangePartitioningRetention (entity , expire )
964
- if tcase .expectErr != nil {
965
- require .Error (t , err )
966
- assert .EqualError (t , err , tcase .expectErr .Error ())
967
- return
968
- }
969
- require .NoError (t , err )
992
+ // Validate test input itself
970
993
if tcase .expectStatement == "" {
971
- assert . Nil (t , diff )
994
+ require . Empty (t , tcase . expectDistinctStatements )
972
995
} else {
973
- require .NotNil (t , diff )
974
- assert .Equal (t , tcase .expectStatement , diff .CanonicalStatementString ())
996
+ require .NotEmpty (t , tcase .expectDistinctStatements )
975
997
}
998
+ t .Run ("combined" , func (t * testing.T ) {
999
+ diffs , err := TemporalRangePartitioningRetention (entity , expire , false )
1000
+ if tcase .expectErr != nil {
1001
+ require .Error (t , err )
1002
+ assert .EqualError (t , err , tcase .expectErr .Error ())
1003
+ return
1004
+ }
1005
+ require .NoError (t , err )
1006
+ if tcase .expectStatement == "" {
1007
+ assert .Empty (t , diffs )
1008
+ } else {
1009
+ require .Len (t , diffs , 1 )
1010
+ assert .Equal (t , tcase .expectStatement , diffs [0 ].CanonicalStatementString ())
1011
+ }
1012
+ })
1013
+ t .Run ("distinct" , func (t * testing.T ) {
1014
+ diffs , err := TemporalRangePartitioningRetention (entity , expire , true )
1015
+ if tcase .expectErr != nil {
1016
+ require .Error (t , err )
1017
+ assert .EqualError (t , err , tcase .expectErr .Error ())
1018
+ return
1019
+ }
1020
+ require .NoError (t , err )
1021
+ if len (tcase .expectDistinctStatements ) == 0 {
1022
+ assert .Empty (t , diffs )
1023
+ } else {
1024
+ require .Len (t , diffs , len (tcase .expectDistinctStatements ))
1025
+ for i , diff := range diffs {
1026
+ assert .Equal (t , tcase .expectDistinctStatements [i ], diff .CanonicalStatementString ())
1027
+ }
1028
+ }
1029
+ })
976
1030
})
977
1031
}
978
-
979
1032
}
0 commit comments