forked from StarRocks/starrocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlterTest.java
1431 lines (1259 loc) · 69.1 KB
/
AlterTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is made available under Elastic License 2.0.
// This file is based on code available under the Apache license here:
// https://github.com/apache/incubator-doris/blob/master/fe/fe-core/src/test/java/org/apache/doris/alter/AlterTest.java
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.starrocks.alter;
import com.google.common.collect.Lists;
import com.starrocks.analysis.AddPartitionClause;
import com.starrocks.analysis.AlterDatabaseRename;
import com.starrocks.analysis.AlterSystemStmt;
import com.starrocks.analysis.AlterTableStmt;
import com.starrocks.analysis.CreateTableStmt;
import com.starrocks.analysis.CreateUserStmt;
import com.starrocks.analysis.DateLiteral;
import com.starrocks.analysis.DropMaterializedViewStmt;
import com.starrocks.analysis.DropTableStmt;
import com.starrocks.analysis.GrantStmt;
import com.starrocks.analysis.UserIdentity;
import com.starrocks.catalog.DataProperty;
import com.starrocks.catalog.Database;
import com.starrocks.catalog.MaterializedIndex;
import com.starrocks.catalog.OlapTable;
import com.starrocks.catalog.Partition;
import com.starrocks.catalog.Table;
import com.starrocks.catalog.Type;
import com.starrocks.common.AnalysisException;
import com.starrocks.common.Config;
import com.starrocks.common.DdlException;
import com.starrocks.common.FeConstants;
import com.starrocks.common.util.TimeUtils;
import com.starrocks.mysql.privilege.Auth;
import com.starrocks.qe.ConnectContext;
import com.starrocks.scheduler.Constants;
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.sql.ast.AlterMaterializedViewStatement;
import com.starrocks.sql.ast.CancelRefreshMaterializedViewStatement;
import com.starrocks.sql.ast.CreateMaterializedViewStatement;
import com.starrocks.sql.ast.RefreshMaterializedViewStatement;
import com.starrocks.thrift.TStorageMedium;
import com.starrocks.utframe.StarRocksAssert;
import com.starrocks.utframe.UtFrameUtils;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.List;
import java.util.Map;
public class AlterTest {
private static ConnectContext connectContext;
private static StarRocksAssert starRocksAssert;
@BeforeClass
public static void beforeClass() throws Exception {
FeConstants.runningUnitTest = true;
FeConstants.default_scheduler_interval_millisecond = 100;
Config.dynamic_partition_enable = true;
Config.dynamic_partition_check_interval_seconds = 1;
Config.enable_strict_storage_medium_check = false;
UtFrameUtils.createMinStarRocksCluster();
// create connect context
connectContext = UtFrameUtils.createDefaultCtx();
starRocksAssert = new StarRocksAssert(connectContext);
starRocksAssert.withDatabase("test").useDatabase("test")
.withTable("CREATE TABLE test.tbl1\n" +
"(\n" +
" k1 date,\n" +
" k2 int,\n" +
" v1 int sum\n" +
")\n" +
"PARTITION BY RANGE(k1)\n" +
"(\n" +
" PARTITION p1 values less than('2020-02-01'),\n" +
" PARTITION p2 values less than('2020-03-01')\n" +
")\n" +
"DISTRIBUTED BY HASH(k2) BUCKETS 3\n" +
"PROPERTIES('replication_num' = '1');")
.withTable("CREATE TABLE test.tbl2\n" +
"(\n" +
" k1 date,\n" +
" v1 int sum\n" +
")\n" +
"DISTRIBUTED BY HASH (k1) BUCKETS 3\n" +
"PROPERTIES('replication_num' = '1');")
.withTable("CREATE TABLE test.tbl3\n" +
"(\n" +
" k1 date,\n" +
" k2 int,\n" +
" v1 int sum\n" +
")\n" +
"PARTITION BY RANGE(k1)\n" +
"(\n" +
" PARTITION p1 values less than('2020-02-01'),\n" +
" PARTITION p2 values less than('2020-03-01')\n" +
")\n" +
"DISTRIBUTED BY HASH(k2) BUCKETS 3\n" +
"PROPERTIES('replication_num' = '1');")
.withTable("CREATE TABLE test.tbl4\n" +
"(\n" +
" k1 date,\n" +
" k2 int,\n" +
" v1 int sum\n" +
")\n" +
"PARTITION BY RANGE(k1)\n" +
"(\n" +
" PARTITION p1 values less than('2020-02-01'),\n" +
" PARTITION p2 values less than('2020-03-01'),\n" +
" PARTITION p3 values less than('2020-04-01'),\n" +
" PARTITION p4 values less than('2020-05-01')\n" +
")\n" +
"DISTRIBUTED BY HASH(k2) BUCKETS 3\n" +
"PROPERTIES" +
"(" +
" 'replication_num' = '1',\n" +
" 'in_memory' = 'false',\n" +
" 'storage_medium' = 'SSD',\n" +
" 'storage_cooldown_time' = '9999-12-31 00:00:00'\n" +
");");
}
@AfterClass
public static void tearDown() throws Exception {
ConnectContext ctx = starRocksAssert.getCtx();
String dropSQL = "drop table test_partition_exception";
DropTableStmt dropTableStmt = (DropTableStmt) UtFrameUtils.parseAndAnalyzeStmt(dropSQL, ctx);
try {
GlobalStateMgr.getCurrentState().dropTable(dropTableStmt);
} catch (Exception ex) {
}
}
private static void checkTableStateToNormal(OlapTable tb) throws InterruptedException {
// waiting table state to normal
int retryTimes = 5;
while (tb.getState() != OlapTable.OlapTableState.NORMAL && retryTimes > 0) {
Thread.sleep(5000);
retryTimes--;
}
Assert.assertEquals(OlapTable.OlapTableState.NORMAL, tb.getState());
}
private static void createTable(String sql) throws Exception {
CreateTableStmt createTableStmt = (CreateTableStmt) UtFrameUtils.parseStmtWithNewParser(sql, connectContext);
GlobalStateMgr.getCurrentState().createTable(createTableStmt);
}
private static void createMaterializedView(String sql) throws Exception {
Config.enable_experimental_mv = true;
CreateMaterializedViewStatement createMaterializedViewStatement =
(CreateMaterializedViewStatement) UtFrameUtils.parseStmtWithNewParser(sql, connectContext);
GlobalStateMgr.getCurrentState().createMaterializedView(createMaterializedViewStatement);
}
private static void dropMaterializedView(String sql) throws Exception {
Config.enable_experimental_mv = true;
DropMaterializedViewStmt dropMaterializedViewStmt =
(DropMaterializedViewStmt) UtFrameUtils.parseStmtWithNewParser(sql, connectContext);
GlobalStateMgr.getCurrentState().dropMaterializedView(dropMaterializedViewStmt);
}
private static void alterMaterializedView(String sql, boolean expectedException) throws Exception {
AlterMaterializedViewStatement alterMaterializedViewStatement =
(AlterMaterializedViewStatement) UtFrameUtils.parseStmtWithNewParser(sql, connectContext);
try {
GlobalStateMgr.getCurrentState().alterMaterializedView(alterMaterializedViewStatement);
if (expectedException) {
Assert.fail();
}
} catch (Exception e) {
e.printStackTrace();
if (!expectedException) {
Assert.fail();
}
}
}
private static void refreshMaterializedView(String sql, boolean expectedException) throws Exception {
RefreshMaterializedViewStatement refreshMaterializedViewStatement =
(RefreshMaterializedViewStatement) UtFrameUtils.parseStmtWithNewParser(sql, connectContext);
try {
GlobalStateMgr.getCurrentState().getLocalMetastore()
.refreshMaterializedView(refreshMaterializedViewStatement.getMvName().getDb(),
refreshMaterializedViewStatement.getMvName().getTbl(),
Constants.TaskRunPriority.LOWEST.value());
if (expectedException) {
Assert.fail();
}
} catch (Exception e) {
e.printStackTrace();
if (!expectedException) {
Assert.fail();
}
}
}
private static void cancelRefreshMaterializedView(String sql, boolean expectedException) throws Exception {
CancelRefreshMaterializedViewStatement cancelRefresh =
(CancelRefreshMaterializedViewStatement) UtFrameUtils.parseStmtWithNewParser(sql, connectContext);
try {
GlobalStateMgr.getCurrentState().getLocalMetastore()
.cancelRefreshMaterializedView(cancelRefresh.getMvName().getDb(),
cancelRefresh.getMvName().getTbl());
if (expectedException) {
Assert.fail();
}
} catch (Exception e) {
e.printStackTrace();
if (!expectedException) {
Assert.fail();
}
}
}
private static void alterTable(String sql, boolean expectedException) throws Exception {
AlterTableStmt alterTableStmt = (AlterTableStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, connectContext);
try {
GlobalStateMgr.getCurrentState().alterTable(alterTableStmt);
if (expectedException) {
Assert.fail();
}
} catch (Exception e) {
e.printStackTrace();
if (!expectedException) {
Assert.fail();
}
}
}
private static void alterTableWithNewParser(String sql, boolean expectedException) throws Exception {
AlterTableStmt alterTableStmt = (AlterTableStmt) UtFrameUtils.parseStmtWithNewParser(sql, connectContext);
try {
GlobalStateMgr.getCurrentState().alterTable(alterTableStmt);
if (expectedException) {
Assert.fail();
}
} catch (Exception e) {
e.printStackTrace();
if (!expectedException) {
Assert.fail();
}
}
}
private static void alterTableWithExceptionMsg(String sql, String msg) throws Exception {
AlterTableStmt alterTableStmt = (AlterTableStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, connectContext);
try {
GlobalStateMgr.getCurrentState().alterTable(alterTableStmt);
} catch (Exception e) {
Assert.assertEquals(msg, e.getMessage());
}
}
private static void alterTableWithMewParserAndExceptionMsg(String sql, String msg) throws Exception {
AlterTableStmt alterTableStmt = (AlterTableStmt) UtFrameUtils.parseStmtWithNewParser(sql, connectContext);
try {
GlobalStateMgr.getCurrentState().alterTable(alterTableStmt);
} catch (Exception e) {
Assert.assertEquals(msg, e.getMessage());
}
}
@Test
public void testRenameMaterializedView() throws Exception {
starRocksAssert.useDatabase("test")
.withTable("CREATE TABLE test.testTable1\n" +
"(\n" +
" k1 date,\n" +
" k2 int,\n" +
" v1 int sum\n" +
")\n" +
"PARTITION BY RANGE(k1)\n" +
"(\n" +
" PARTITION p1 values less than('2020-02-01'),\n" +
" PARTITION p2 values less than('2020-03-01')\n" +
")\n" +
"DISTRIBUTED BY HASH(k2) BUCKETS 3\n" +
"PROPERTIES('replication_num' = '1');");
String sql = "create materialized view mv1 " +
"partition by k1 " +
"distributed by hash(k2) " +
"refresh async START('2122-12-31') EVERY(INTERVAL 1 HOUR) " +
"PROPERTIES (\n" +
"\"replication_num\" = \"1\"\n" +
") " +
"as select k1, k2 from test.testTable1;";
createMaterializedView(sql);
String alterStmt = "alter materialized view test.mv1 rename mv2";
alterMaterializedView(alterStmt, false);
dropMaterializedView("drop materialized view test.mv2");
}
@Test
public void testRenameTable() throws Exception {
starRocksAssert.useDatabase("test")
.withTable("CREATE TABLE test.testRenameTable1\n" +
"(\n" +
" k1 date,\n" +
" k2 int,\n" +
" v1 int sum\n" +
")\n" +
"PARTITION BY RANGE(k1)\n" +
"(\n" +
" PARTITION p1 values less than('2020-02-01'),\n" +
" PARTITION p2 values less than('2020-03-01')\n" +
")\n" +
"DISTRIBUTED BY HASH(k2) BUCKETS 3\n" +
"PROPERTIES('replication_num' = '1');");
String alterStmt = "alter table test.testRenameTable1 rename testRenameTable2";
alterTableWithNewParser(alterStmt, false);
}
@Test
public void testChangeMaterializedViewRefreshScheme() throws Exception {
starRocksAssert.useDatabase("test")
.withTable("CREATE TABLE test.testTable2\n" +
"(\n" +
" k1 date,\n" +
" k2 int,\n" +
" v1 int sum\n" +
")\n" +
"PARTITION BY RANGE(k1)\n" +
"(\n" +
" PARTITION p1 values less than('2020-02-01'),\n" +
" PARTITION p2 values less than('2020-03-01')\n" +
")\n" +
"DISTRIBUTED BY HASH(k2) BUCKETS 3\n" +
"PROPERTIES('replication_num' = '1');");
String sql = "create materialized view mv1 " +
"partition by k1 " +
"distributed by hash(k2) " +
"refresh async START('2122-12-31') EVERY(INTERVAL 1 HOUR) " +
"PROPERTIES (\n" +
"\"replication_num\" = \"1\"\n" +
") " +
"as select k1, k2 from test.testTable2;";
createMaterializedView(sql);
String alterStmt = "alter materialized view mv1 refresh async EVERY(INTERVAL 1 minute)";
alterMaterializedView(alterStmt, false);
alterStmt = "alter materialized view mv1 refresh manual";
alterMaterializedView(alterStmt, false);
dropMaterializedView("drop materialized view test.mv1");
}
@Test
public void testRefreshMaterializedView() throws Exception {
starRocksAssert.useDatabase("test")
.withTable("CREATE TABLE test.testTable3\n" +
"(\n" +
" k1 date,\n" +
" k2 int,\n" +
" v1 int sum\n" +
")\n" +
"PARTITION BY RANGE(k1)\n" +
"(\n" +
" PARTITION p1 values less than('2020-02-01'),\n" +
" PARTITION p2 values less than('2020-03-01')\n" +
")\n" +
"DISTRIBUTED BY HASH(k2) BUCKETS 3\n" +
"PROPERTIES('replication_num' = '1');");
String sql = "create materialized view mv1 " +
"partition by k1 " +
"distributed by hash(k2) " +
"refresh async START('2122-12-31') EVERY(INTERVAL 1 HOUR) " +
"PROPERTIES (\n" +
"\"replication_num\" = \"1\"\n" +
") " +
"as select k1, k2 from test.testTable3;";
createMaterializedView(sql);
String alterStmt = "refresh materialized view test.mv1";
refreshMaterializedView(alterStmt, false);
dropMaterializedView("drop materialized view test.mv1");
}
@Test
public void testCancelRefreshMaterializedView() throws Exception {
starRocksAssert.useDatabase("test")
.withTable("CREATE TABLE test.testTable4\n" +
"(\n" +
" k1 date,\n" +
" k2 int,\n" +
" v1 int sum\n" +
")\n" +
"PARTITION BY RANGE(k1)\n" +
"(\n" +
" PARTITION p1 values less than('2020-02-01'),\n" +
" PARTITION p2 values less than('2020-03-01')\n" +
")\n" +
"DISTRIBUTED BY HASH(k2) BUCKETS 3\n" +
"PROPERTIES('replication_num' = '1');");
String sql = "create materialized view mv1 " +
"partition by k1 " +
"distributed by hash(k2) " +
"refresh async START('2122-12-31') EVERY(INTERVAL 1 HOUR) " +
"PROPERTIES (\n" +
"\"replication_num\" = \"1\"\n" +
") " +
"as select k1, k2 from test.testTable4;";
createMaterializedView(sql);
String alterStmt = "refresh materialized view test.mv1";
refreshMaterializedView(alterStmt, false);
cancelRefreshMaterializedView("cancel refresh materialized view test.mv1", false);
dropMaterializedView("drop materialized view test.mv1");
}
@Test
public void testConflictAlterOperations() throws Exception {
Database db = GlobalStateMgr.getCurrentState().getDb("default_cluster:test");
OlapTable tbl = (OlapTable) db.getTable("tbl1");
String stmt =
"alter table test.tbl1 add partition p3 values less than('2020-04-01'), add partition p4 values less than('2020-05-01')";
alterTableWithNewParser(stmt, true);
stmt = "alter table test.tbl1 add partition p3 values less than('2020-04-01'), drop partition p4";
alterTableWithNewParser(stmt, true);
stmt = "alter table test.tbl1 drop partition p3, drop partition p4";
alterTableWithNewParser(stmt, true);
stmt = "alter table test.tbl1 drop partition p3, add column k3 int";
// alterTable(stmt, true);
// no conflict
stmt = "alter table test.tbl1 add column k3 int, add column k4 int";
alterTable(stmt, false);
waitSchemaChangeJobDone(false, tbl);
stmt = "alter table test.tbl1 add rollup r1 (k1)";
alterTable(stmt, false);
waitSchemaChangeJobDone(true, tbl);
stmt = "alter table test.tbl1 add rollup r2 (k1), r3 (k1)";
alterTable(stmt, false);
waitSchemaChangeJobDone(true, tbl);
// enable dynamic partition
// not adding the `start` property so that it won't drop the origin partition p1, p2 and p3
stmt = "alter table test.tbl1 set (\n" +
"'dynamic_partition.enable' = 'true',\n" +
"'dynamic_partition.time_unit' = 'DAY',\n" +
"'dynamic_partition.end' = '3',\n" +
"'dynamic_partition.prefix' = 'p',\n" +
"'dynamic_partition.buckets' = '3'\n" +
" );";
alterTableWithNewParser(stmt, false);
Assert.assertTrue(tbl.getTableProperty().getDynamicPartitionProperty().getEnable());
Assert.assertEquals(4, tbl.getIndexIdToSchema().size());
// add partition when dynamic partition is enable
stmt =
"alter table test.tbl1 add partition p3 values less than('2020-04-01') distributed by hash(k2) buckets 4 PROPERTIES ('replication_num' = '1')";
alterTableWithNewParser(stmt, true);
// add temp partition when dynamic partition is enable
stmt =
"alter table test.tbl1 add temporary partition tp3 values less than('2020-04-01') distributed by hash(k2) buckets 4 PROPERTIES ('replication_num' = '1')";
alterTableWithNewParser(stmt, false);
Assert.assertEquals(1, tbl.getTempPartitions().size());
// disable the dynamic partition
stmt = "alter table test.tbl1 set ('dynamic_partition.enable' = 'false')";
alterTableWithNewParser(stmt, false);
Assert.assertFalse(tbl.getTableProperty().getDynamicPartitionProperty().getEnable());
// add partition when dynamic partition is disable
stmt =
"alter table test.tbl1 add partition p3 values less than('2020-04-01') distributed by hash(k2) buckets 4";
alterTableWithNewParser(stmt, false);
// set table's default replication num
Assert.assertEquals(Short.valueOf("1"), tbl.getDefaultReplicationNum());
stmt = "alter table test.tbl1 set ('default.replication_num' = '3');";
alterTableWithNewParser(stmt, false);
Assert.assertEquals(Short.valueOf("3"), tbl.getDefaultReplicationNum());
// set range table's real replication num
Partition p1 = tbl.getPartition("p1");
Assert.assertEquals(Short.valueOf("1"), Short.valueOf(tbl.getPartitionInfo().getReplicationNum(p1.getId())));
stmt = "alter table test.tbl1 set ('replication_num' = '3');";
alterTableWithNewParser(stmt, true);
Assert.assertEquals(Short.valueOf("1"), Short.valueOf(tbl.getPartitionInfo().getReplicationNum(p1.getId())));
// set un-partitioned table's real replication num
OlapTable tbl2 = (OlapTable) db.getTable("tbl2");
Partition partition = tbl2.getPartition(tbl2.getName());
Assert.assertEquals(Short.valueOf("1"),
Short.valueOf(tbl2.getPartitionInfo().getReplicationNum(partition.getId())));
// partition replication num and table default replication num are updated at the same time in unpartitioned table
stmt = "alter table test.tbl2 set ('replication_num' = '3');";
alterTableWithNewParser(stmt, false);
Assert.assertEquals(Short.valueOf("3"),
Short.valueOf(tbl2.getPartitionInfo().getReplicationNum(partition.getId())));
Assert.assertEquals(Short.valueOf("3"), tbl2.getDefaultReplicationNum());
stmt = "alter table test.tbl2 set ('default.replication_num' = '2');";
alterTableWithNewParser(stmt, false);
Assert.assertEquals(Short.valueOf("2"),
Short.valueOf(tbl2.getPartitionInfo().getReplicationNum(partition.getId())));
Assert.assertEquals(Short.valueOf("2"), tbl2.getDefaultReplicationNum());
stmt = "alter table test.tbl2 modify partition tbl2 set ('replication_num' = '1');";
alterTableWithNewParser(stmt, false);
Assert.assertEquals(Short.valueOf("1"),
Short.valueOf(tbl2.getPartitionInfo().getReplicationNum(partition.getId())));
Assert.assertEquals(Short.valueOf("1"), tbl2.getDefaultReplicationNum());
Thread.sleep(5000); // sleep to wait dynamic partition scheduler run
// add partition without set replication num
stmt = "alter table test.tbl1 add partition p4 values less than('2020-04-10')";
alterTableWithNewParser(stmt, true);
// add partition when dynamic partition is disable
stmt = "alter table test.tbl1 add partition p4 values less than('2020-04-10') ('replication_num' = '1')";
alterTableWithNewParser(stmt, false);
stmt = "alter table test.tbl1 add TEMPORARY partition p5 values [('2020-04-10'), ('2020-05-10')) ('replication_num' = '1') " +
"DISTRIBUTED BY HASH(k2) BUCKETS 3 PROPERTIES('replication_num' = '1');";
alterTableWithNewParser(stmt, false);
//rename table
stmt = "alter table test.tbl1 rename newTableName";
alterTableWithNewParser(stmt, false);
}
// test batch update range partitions' properties
@Test
public void testBatchUpdatePartitionProperties() throws Exception {
Database db = GlobalStateMgr.getCurrentState().getDb("default_cluster:test");
OlapTable tbl4 = (OlapTable) db.getTable("tbl4");
Partition p1 = tbl4.getPartition("p1");
Partition p2 = tbl4.getPartition("p2");
Partition p3 = tbl4.getPartition("p3");
Partition p4 = tbl4.getPartition("p4");
// batch update replication_num property
String stmt = "alter table test.tbl4 modify partition (p1, p2, p4) set ('replication_num' = '3')";
List<Partition> partitionList = Lists.newArrayList(p1, p2, p4);
for (Partition partition : partitionList) {
Assert.assertEquals(Short.valueOf("1"),
Short.valueOf(tbl4.getPartitionInfo().getReplicationNum(partition.getId())));
}
alterTableWithNewParser(stmt, false);
for (Partition partition : partitionList) {
Assert.assertEquals(Short.valueOf("3"),
Short.valueOf(tbl4.getPartitionInfo().getReplicationNum(partition.getId())));
}
Assert.assertEquals(Short.valueOf("1"), Short.valueOf(tbl4.getPartitionInfo().getReplicationNum(p3.getId())));
// batch update in_memory property
stmt = "alter table test.tbl4 modify partition (p1, p2, p3) set ('in_memory' = 'true')";
partitionList = Lists.newArrayList(p1, p2, p3);
for (Partition partition : partitionList) {
Assert.assertEquals(false, tbl4.getPartitionInfo().getIsInMemory(partition.getId()));
}
alterTableWithNewParser(stmt, false);
for (Partition partition : partitionList) {
Assert.assertEquals(true, tbl4.getPartitionInfo().getIsInMemory(partition.getId()));
}
Assert.assertEquals(false, tbl4.getPartitionInfo().getIsInMemory(p4.getId()));
// batch update storage_medium and storage_cool_down properties
stmt = "alter table test.tbl4 modify partition (p2, p3, p4) set ('storage_medium' = 'HDD')";
DateLiteral dateLiteral = new DateLiteral("9999-12-31 00:00:00", Type.DATETIME);
long coolDownTimeMs = dateLiteral.unixTimestamp(TimeUtils.getTimeZone());
DataProperty oldDataProperty = new DataProperty(TStorageMedium.SSD, coolDownTimeMs);
partitionList = Lists.newArrayList(p2, p3, p4);
for (Partition partition : partitionList) {
Assert.assertEquals(oldDataProperty, tbl4.getPartitionInfo().getDataProperty(partition.getId()));
}
alterTableWithNewParser(stmt, false);
DataProperty newDataProperty = new DataProperty(TStorageMedium.HDD, DataProperty.MAX_COOLDOWN_TIME_MS);
for (Partition partition : partitionList) {
Assert.assertEquals(newDataProperty, tbl4.getPartitionInfo().getDataProperty(partition.getId()));
}
Assert.assertEquals(oldDataProperty, tbl4.getPartitionInfo().getDataProperty(p1.getId()));
// batch update range partitions' properties with *
stmt = "alter table test.tbl4 modify partition (*) set ('replication_num' = '1')";
partitionList = Lists.newArrayList(p1, p2, p3, p4);
alterTableWithNewParser(stmt, false);
for (Partition partition : partitionList) {
Assert.assertEquals(Short.valueOf("1"),
Short.valueOf(tbl4.getPartitionInfo().getReplicationNum(partition.getId())));
}
}
//Move test to Regression Testing
/*
@Test
public void testDynamicPartitionDropAndAdd() throws Exception {
// test day range
String stmt = "alter table test.tbl3 set (\n" +
"'dynamic_partition.enable' = 'true',\n" +
"'dynamic_partition.time_unit' = 'DAY',\n" +
"'dynamic_partition.start' = '-3',\n" +
"'dynamic_partition.end' = '3',\n" +
"'dynamic_partition.prefix' = 'p',\n" +
"'dynamic_partition.buckets' = '3'\n" +
" );";
alterTable(stmt, false);
Thread.sleep(5000); // sleep to wait dynamic partition scheduler run
Database db = GlobalStateMgr.getCurrentState().getDb("default_cluster:test");
OlapTable tbl = (OlapTable) db.getTable("tbl3");
Assert.assertEquals(4, tbl.getPartitionNames().size());
Assert.assertNull(tbl.getPartition("p1"));
Assert.assertNull(tbl.getPartition("p2"));
}
*/
private void waitSchemaChangeJobDone(boolean rollupJob, OlapTable tb) throws InterruptedException {
Map<Long, AlterJobV2> alterJobs = GlobalStateMgr.getCurrentState().getSchemaChangeHandler().getAlterJobsV2();
if (rollupJob) {
alterJobs = GlobalStateMgr.getCurrentState().getRollupHandler().getAlterJobsV2();
}
for (AlterJobV2 alterJobV2 : alterJobs.values()) {
while (!alterJobV2.getJobState().isFinalState()) {
System.out.println(
"alter job " + alterJobV2.getJobId() + " is running. state: " + alterJobV2.getJobState());
Thread.sleep(1000);
}
System.out.println(alterJobV2.getType() + " alter job " + alterJobV2.getJobId() + " is done. state: " +
alterJobV2.getJobState());
Assert.assertEquals(AlterJobV2.JobState.FINISHED, alterJobV2.getJobState());
}
checkTableStateToNormal(tb);
}
@Test
public void testSetDynamicPropertiesInNormalTable() throws Exception {
String tableName = "no_dynamic_table";
String createOlapTblStmt = "CREATE TABLE test.`" + tableName + "` (\n" +
" `k1` date NULL COMMENT \"\",\n" +
" `k2` int NULL COMMENT \"\",\n" +
" `k3` smallint NULL COMMENT \"\",\n" +
" `v1` varchar(2048) NULL COMMENT \"\",\n" +
" `v2` datetime NULL COMMENT \"\"\n" +
") ENGINE=OLAP\n" +
"DUPLICATE KEY(`k1`, `k2`, `k3`)\n" +
"COMMENT \"OLAP\"\n" +
"PARTITION BY RANGE (k1)\n" +
"(\n" +
"PARTITION p1 VALUES LESS THAN (\"2014-01-01\"),\n" +
"PARTITION p2 VALUES LESS THAN (\"2014-06-01\"),\n" +
"PARTITION p3 VALUES LESS THAN (\"2014-12-01\")\n" +
")\n" +
"DISTRIBUTED BY HASH(`k1`) BUCKETS 32\n" +
"PROPERTIES (\n" +
"\"replication_num\" = \"1\"\n" +
");";
createTable(createOlapTblStmt);
String alterStmt = "alter table test." + tableName + " set (\"dynamic_partition.enable\" = \"true\");";
String errorMsg = "Table default_cluster:test.no_dynamic_table is not a dynamic partition table. " +
"Use command `HELP ALTER TABLE` to see how to change a normal table to a dynamic partition table.";
alterTableWithMewParserAndExceptionMsg(alterStmt, errorMsg);
// test set dynamic properties in a no dynamic partition table
String stmt = "alter table test." + tableName + " set (\n" +
"'dynamic_partition.enable' = 'true',\n" +
"'dynamic_partition.time_unit' = 'DAY',\n" +
"'dynamic_partition.start' = '-3',\n" +
"'dynamic_partition.end' = '3',\n" +
"'dynamic_partition.prefix' = 'p',\n" +
"'dynamic_partition.buckets' = '3'\n" +
" );";
alterTableWithNewParser(stmt, false);
}
@Test
public void testSetDynamicPropertiesInDynamicPartitionTable() throws Exception {
String tableName = "dynamic_table";
String createOlapTblStmt = "CREATE TABLE test.`" + tableName + "` (\n" +
" `k1` date NULL COMMENT \"\",\n" +
" `k2` int NULL COMMENT \"\",\n" +
" `k3` smallint NULL COMMENT \"\",\n" +
" `v1` varchar(2048) NULL COMMENT \"\",\n" +
" `v2` datetime NULL COMMENT \"\"\n" +
") ENGINE=OLAP\n" +
"DUPLICATE KEY(`k1`, `k2`, `k3`)\n" +
"COMMENT \"OLAP\"\n" +
"PARTITION BY RANGE (k1)\n" +
"(\n" +
"PARTITION p1 VALUES LESS THAN (\"2014-01-01\"),\n" +
"PARTITION p2 VALUES LESS THAN (\"2014-06-01\"),\n" +
"PARTITION p3 VALUES LESS THAN (\"2014-12-01\")\n" +
")\n" +
"DISTRIBUTED BY HASH(`k1`) BUCKETS 32\n" +
"PROPERTIES (\n" +
"\"replication_num\" = \"1\",\n" +
"\"dynamic_partition.enable\" = \"true\",\n" +
"\"dynamic_partition.start\" = \"-3\",\n" +
"\"dynamic_partition.end\" = \"3\",\n" +
"\"dynamic_partition.time_unit\" = \"day\",\n" +
"\"dynamic_partition.prefix\" = \"p\",\n" +
"\"dynamic_partition.buckets\" = \"1\"\n" +
");";
createTable(createOlapTblStmt);
String alterStmt1 = "alter table test." + tableName + " set (\"dynamic_partition.enable\" = \"false\");";
alterTableWithNewParser(alterStmt1, false);
String alterStmt2 = "alter table test." + tableName + " set (\"dynamic_partition.time_unit\" = \"week\");";
alterTableWithNewParser(alterStmt2, false);
String alterStmt3 = "alter table test." + tableName + " set (\"dynamic_partition.start\" = \"-10\");";
alterTableWithNewParser(alterStmt3, false);
String alterStmt4 = "alter table test." + tableName + " set (\"dynamic_partition.end\" = \"10\");";
alterTableWithNewParser(alterStmt4, false);
String alterStmt5 = "alter table test." + tableName + " set (\"dynamic_partition.prefix\" = \"pp\");";
alterTableWithNewParser(alterStmt5, false);
String alterStmt6 = "alter table test." + tableName + " set (\"dynamic_partition.buckets\" = \"5\");";
alterTableWithNewParser(alterStmt6, false);
}
@Test
public void testSwapTable() throws Exception {
String stmt1 = "CREATE TABLE test.replace1\n" +
"(\n" +
" k1 int, k2 int, k3 int sum\n" +
")\n" +
"AGGREGATE KEY(k1, k2)\n" +
"DISTRIBUTED BY HASH(k1) BUCKETS 10\n" +
"rollup (\n" +
"r1(k1),\n" +
"r2(k2, k3)\n" +
")\n" +
"PROPERTIES(\"replication_num\" = \"1\");";
String stmt2 = "CREATE TABLE test.r1\n" +
"(\n" +
" k1 int, k2 int\n" +
")\n" +
"DISTRIBUTED BY HASH(k1) BUCKETS 11\n" +
"PROPERTIES(\"replication_num\" = \"1\");";
String stmt3 = "CREATE TABLE test.replace2\n" +
"(\n" +
" k1 int, k2 int\n" +
")\n" +
"DISTRIBUTED BY HASH(k1) BUCKETS 11\n" +
"PROPERTIES(\"replication_num\" = \"1\");";
String stmt4 = "CREATE TABLE test.replace3\n" +
"(\n" +
" k1 int, k2 int, k3 int sum\n" +
")\n" +
"PARTITION BY RANGE(k1)\n" +
"(\n" +
"\tPARTITION p1 values less than(\"100\"),\n" +
"\tPARTITION p2 values less than(\"200\")\n" +
")\n" +
"DISTRIBUTED BY HASH(k1) BUCKETS 1\n" +
"rollup (\n" +
"r3(k1),\n" +
"r4(k2, k3)\n" +
")\n" +
"PROPERTIES(\"replication_num\" = \"1\");";
createTable(stmt1);
createTable(stmt2);
createTable(stmt3);
createTable(stmt4);
Database db = GlobalStateMgr.getCurrentState().getDb("default_cluster:test");
// name conflict
String replaceStmt = "ALTER TABLE test.replace1 SWAP WITH r1";
alterTableWithNewParser(replaceStmt, true);
// replace1 with replace2
replaceStmt = "ALTER TABLE test.replace1 SWAP WITH replace2";
OlapTable replace1 = (OlapTable) db.getTable("replace1");
OlapTable replace2 = (OlapTable) db.getTable("replace2");
Assert.assertEquals(3,
replace1.getPartition("replace1").getMaterializedIndices(MaterializedIndex.IndexExtState.VISIBLE)
.size());
Assert.assertEquals(1,
replace2.getPartition("replace2").getMaterializedIndices(MaterializedIndex.IndexExtState.VISIBLE)
.size());
alterTableWithNewParser(replaceStmt, false);
replace1 = (OlapTable) db.getTable("replace1");
replace2 = (OlapTable) db.getTable("replace2");
Assert.assertEquals(1,
replace1.getPartition("replace1").getMaterializedIndices(MaterializedIndex.IndexExtState.VISIBLE)
.size());
Assert.assertEquals(3,
replace2.getPartition("replace2").getMaterializedIndices(MaterializedIndex.IndexExtState.VISIBLE)
.size());
Assert.assertEquals("replace1", replace1.getIndexNameById(replace1.getBaseIndexId()));
Assert.assertEquals("replace2", replace2.getIndexNameById(replace2.getBaseIndexId()));
}
@Test
public void testCatalogAddPartitionsDay() throws Exception {
ConnectContext ctx = starRocksAssert.getCtx();
String dropSQL = "drop table if exists test_partition";
DropTableStmt dropTableStmt = (DropTableStmt) UtFrameUtils.parseStmtWithNewParser(dropSQL, ctx);
GlobalStateMgr.getCurrentState().dropTable(dropTableStmt);
String createSQL = "CREATE TABLE test.test_partition (\n" +
" k2 DATE,\n" +
" k3 SMALLINT,\n" +
" v1 VARCHAR(2048),\n" +
" v2 DATETIME DEFAULT \"2014-02-04 15:36:00\"\n" +
")\n" +
"ENGINE=olap\n" +
"DUPLICATE KEY(k2, k3)\n" +
"PARTITION BY RANGE (k2) (\n" +
" START (\"20140101\") END (\"20140104\") EVERY (INTERVAL 1 DAY)\n" +
")\n" +
"DISTRIBUTED BY HASH(k2) BUCKETS 10\n" +
"PROPERTIES (\n" +
" \"replication_num\" = \"1\"\n" +
")";
CreateTableStmt createTableStmt = (CreateTableStmt) UtFrameUtils.parseStmtWithNewParser(createSQL, ctx);
GlobalStateMgr.getCurrentState().createTable(createTableStmt);
Database db = GlobalStateMgr.getCurrentState().getDb("default_cluster:test");
String alterSQL = "ALTER TABLE test_partition ADD\n" +
" PARTITIONS START (\"2017-01-03\") END (\"2017-01-07\") EVERY (interval 1 day)";
AlterTableStmt alterTableStmt = (AlterTableStmt) UtFrameUtils.parseStmtWithNewParser(alterSQL, ctx);
AddPartitionClause addPartitionClause = (AddPartitionClause) alterTableStmt.getOps().get(0);
GlobalStateMgr.getCurrentState().addPartitions(db, "test_partition", addPartitionClause);
Table table = GlobalStateMgr.getCurrentState().getDb("default_cluster:test")
.getTable("test_partition");
Assert.assertNotNull(table.getPartition("p20170103"));
Assert.assertNotNull(table.getPartition("p20170104"));
Assert.assertNotNull(table.getPartition("p20170105"));
Assert.assertNotNull(table.getPartition("p20170106"));
Assert.assertNull(table.getPartition("p20170107"));
dropSQL = "drop table test_partition";
dropTableStmt = (DropTableStmt) UtFrameUtils.parseStmtWithNewParser(dropSQL, ctx);
GlobalStateMgr.getCurrentState().dropTable(dropTableStmt);
}
@Test
public void testAddBackend() throws Exception {
ConnectContext ctx = starRocksAssert.getCtx();
String addBackendSql = "ALTER SYSTEM ADD BACKEND \"192.168.1.1:8080\",\"192.168.1.2:8080\"";
AlterSystemStmt addBackendStmt = (AlterSystemStmt) UtFrameUtils.parseStmtWithNewParser(addBackendSql, ctx);
String dropBackendSql = "ALTER SYSTEM DROP BACKEND \"192.168.1.1:8080\",\"192.168.1.2:8080\"";
AlterSystemStmt dropBackendStmt = (AlterSystemStmt) UtFrameUtils.parseStmtWithNewParser(dropBackendSql, ctx);
String addObserverSql = "ALTER SYSTEM ADD OBSERVER \"192.168.1.1:8080\"";
AlterSystemStmt addObserverStmt = (AlterSystemStmt) UtFrameUtils.parseStmtWithNewParser(addObserverSql, ctx);
String dropObserverSql = "ALTER SYSTEM DROP OBSERVER \"192.168.1.1:8080\"";
AlterSystemStmt dropObserverStmt = (AlterSystemStmt) UtFrameUtils.parseStmtWithNewParser(dropObserverSql, ctx);
String addFollowerSql = "ALTER SYSTEM ADD FOLLOWER \"192.168.1.1:8080\"";
AlterSystemStmt addFollowerStmt = (AlterSystemStmt) UtFrameUtils.parseStmtWithNewParser(addFollowerSql, ctx);
String dropFollowerSql = "ALTER SYSTEM DROP FOLLOWER \"192.168.1.1:8080\"";
AlterSystemStmt dropFollowerStmt = (AlterSystemStmt) UtFrameUtils.parseStmtWithNewParser(dropFollowerSql, ctx);
}
@Test
public void testCatalogAddPartitions5Day() throws Exception {
ConnectContext ctx = starRocksAssert.getCtx();
String createSQL = "CREATE TABLE test.test_partition (\n" +
" k2 DATE,\n" +
" k3 SMALLINT,\n" +
" v1 VARCHAR(2048),\n" +
" v2 DATETIME DEFAULT \"2014-02-04 15:36:00\"\n" +
")\n" +
"ENGINE=olap\n" +
"DUPLICATE KEY(k2, k3)\n" +
"PARTITION BY RANGE (k2) (\n" +
")\n" +
"DISTRIBUTED BY HASH(k2) BUCKETS 10\n" +
"PROPERTIES (\n" +
" \"replication_num\" = \"1\"\n" +
")";
CreateTableStmt createTableStmt = (CreateTableStmt) UtFrameUtils.parseStmtWithNewParser(createSQL, ctx);
GlobalStateMgr.getCurrentState().createTable(createTableStmt);
Database db = GlobalStateMgr.getCurrentState().getDb("default_cluster:test");
String alterSQL = "ALTER TABLE test_partition ADD\n" +
" PARTITIONS START (\"2017-01-03\") END (\"2017-01-15\") EVERY (interval 5 day)";
AlterTableStmt alterTableStmt = (AlterTableStmt) UtFrameUtils.parseStmtWithNewParser(alterSQL, ctx);
AddPartitionClause addPartitionClause = (AddPartitionClause) alterTableStmt.getOps().get(0);
GlobalStateMgr.getCurrentState().addPartitions(db, "test_partition", addPartitionClause);
Table table = GlobalStateMgr.getCurrentState().getDb("default_cluster:test")
.getTable("test_partition");
Assert.assertNotNull(table.getPartition("p20170103"));
Assert.assertNotNull(table.getPartition("p20170108"));
Assert.assertNotNull(table.getPartition("p20170113"));
String dropSQL = "drop table test_partition";
DropTableStmt dropTableStmt = (DropTableStmt) UtFrameUtils.parseStmtWithNewParser(dropSQL, ctx);
GlobalStateMgr.getCurrentState().dropTable(dropTableStmt);
}
@Test(expected = DdlException.class)
public void testCatalogAddPartitionsDayConflictException() throws Exception {
ConnectContext ctx = starRocksAssert.getCtx();
String createSQL = "CREATE TABLE test.test_partition_exception (\n" +
" k2 DATE,\n" +
" k3 SMALLINT,\n" +
" v1 VARCHAR(2048),\n" +
" v2 DATETIME DEFAULT \"2014-02-04 15:36:00\"\n" +
")\n" +
"ENGINE=olap\n" +
"DUPLICATE KEY(k2, k3)\n" +
"PARTITION BY RANGE (k2) (\n" +
" START (\"20140101\") END (\"20140104\") EVERY (INTERVAL 1 DAY)\n" +
")\n" +
"DISTRIBUTED BY HASH(k2) BUCKETS 10\n" +
"PROPERTIES (\n" +
" \"replication_num\" = \"1\"\n" +
")";
CreateTableStmt createTableStmt = (CreateTableStmt) UtFrameUtils.parseStmtWithNewParser(createSQL, ctx);
GlobalStateMgr.getCurrentState().createTable(createTableStmt);
Database db = GlobalStateMgr.getCurrentState().getDb("default_cluster:test");
String alterSQL = "ALTER TABLE test_partition_exception ADD\n" +
" PARTITIONS START (\"2014-01-01\") END (\"2014-01-04\") EVERY (interval 1 day)";
AlterTableStmt alterTableStmt = (AlterTableStmt) UtFrameUtils.parseStmtWithNewParser(alterSQL, ctx);
AddPartitionClause addPartitionClause = (AddPartitionClause) alterTableStmt.getOps().get(0);
GlobalStateMgr.getCurrentState().addPartitions(db, "test_partition_exception", addPartitionClause);
}
@Test
public void testCatalogAddPartitionsWeek() throws Exception {
ConnectContext ctx = starRocksAssert.getCtx();
String createSQL = "CREATE TABLE test.test_partition_week (\n" +
" k2 DATE,\n" +
" k3 SMALLINT,\n" +
" v1 VARCHAR(2048),\n" +
" v2 DATETIME DEFAULT \"2014-02-04 15:36:00\"\n" +
")\n" +
"ENGINE=olap\n" +
"DUPLICATE KEY(k2, k3)\n" +
"PARTITION BY RANGE (k2) (\n" +
")\n" +
"DISTRIBUTED BY HASH(k2) BUCKETS 10\n" +
"PROPERTIES (\n" +
" \"replication_num\" = \"1\"\n" +
")";
CreateTableStmt createTableStmt = (CreateTableStmt) UtFrameUtils.parseStmtWithNewParser(createSQL, ctx);
GlobalStateMgr.getCurrentState().createTable(createTableStmt);
Database db = GlobalStateMgr.getCurrentState().getDb("default_cluster:test");
String alterSQL = "ALTER TABLE test_partition_week ADD\n" +
" PARTITIONS START (\"2017-03-25\") END (\"2017-04-10\") EVERY (interval 1 week)";
AlterTableStmt alterTableStmt = (AlterTableStmt) UtFrameUtils.parseStmtWithNewParser(alterSQL, ctx);
AddPartitionClause addPartitionClause = (AddPartitionClause) alterTableStmt.getOps().get(0);
GlobalStateMgr.getCurrentState().addPartitions(db, "test_partition_week", addPartitionClause);
Table table = GlobalStateMgr.getCurrentState().getDb("default_cluster:test")
.getTable("test_partition_week");
Assert.assertNotNull(table.getPartition("p2017_13"));
Assert.assertNotNull(table.getPartition("p2017_14"));
Assert.assertNotNull(table.getPartition("p2017_15"));
String dropSQL = "drop table test_partition_week";
DropTableStmt dropTableStmt = (DropTableStmt) UtFrameUtils.parseStmtWithNewParser(dropSQL, ctx);
GlobalStateMgr.getCurrentState().dropTable(dropTableStmt);
}
@Test
public void testCatalogAddParitionsMonth() throws Exception {
ConnectContext ctx = starRocksAssert.getCtx();
String dropSQL = "drop table if exists test_partition";