/
AlterTableTestCase.scala
1068 lines (891 loc) · 62 KB
/
AlterTableTestCase.scala
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
/*
* 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 org.apache.carbondata.cluster.sdv.generated
import org.apache.spark.SPARK_VERSION
import org.apache.spark.sql.Row
import org.apache.spark.sql.common.util._
import org.apache.spark.util.SparkUtil
import org.scalatest.BeforeAndAfterAll
import org.apache.carbondata.common.constants.LoggerAction
import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException
import org.apache.carbondata.core.constants.CarbonCommonConstants
import org.apache.carbondata.core.util.CarbonProperties
import org.apache.spark.sql.catalyst.analysis.NoSuchTableException
import org.apache.carbondata.spark.exception.ProcessMetaDataException
/**
* Test Class for AlterTableTestCase to verify all scenerios
*/
class AlterTableTestCase extends QueryTest with BeforeAndAfterAll {
//Check alter table using with alter command in lower case
test("RenameTable_001_01", Include) {
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""alter table test1 rename to test2""").collect
checkAnswer(s"""select count(*) from test2""",
Seq(Row(1)), "AlterTableTestCase_RenameTable_001_01")
sql(s"""drop table if exists test2""").collect
}
//Check alter table using with alter command in upper & lower case
test("RenameTable_001_02", Include) {
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""alter table Test1 RENAME to teSt2""").collect
sql(s"""insert into test2 select 'yy',2""").collect
checkAnswer(s"""select count(*) from test2""",
Seq(Row(2)), "AlterTableTestCase_RenameTable_001_02")
sql(s"""drop table if exists test2""").collect
}
//Check alter table using with alter command in upper case
test("RenameTable_001_03", Include) {
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""alter table test1 RENAME TO test2""").collect
checkAnswer(s"""select count(*) from test2""",
Seq(Row(1)), "AlterTableTestCase_RenameTable_001_03")
sql(s"""drop table if exists test2""").collect
}
//Check alter table where target table speficifed with database name
test("RenameTable_001_04", Include) {
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""alter table test1 RENAME TO defAult.test2""").collect
checkAnswer(s"""select count(*) from test2""",
Seq(Row(1)), "AlterTableTestCase_RenameTable_001_04")
}
//Check alter table run multiple times, revert back the name to original
test("RenameTable_001_06", Include) {
sql(s"""drop table if exists test2""").collect
sql(s"""drop table if exists test1""").collect
sql(s"""drop table if exists test3""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""alter table test1 rename to test2""").collect
sql(s"""alter table test2 rename to test3""").collect
sql(s"""alter table test3 rename to test1""").collect
checkAnswer(s"""select count(*) from test1""",
Seq(Row(1)), "AlterTableTestCase_RenameTable_001_06")
sql(s"""drop table if exists test1""").collect
}
//Check data load after table rename
test("RenameTable_001_07_1", Include) {
sql(s"""drop table if exists test2""").collect
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""alter table test1 RENAME TO test2""").collect
sql(s"""Insert into test2 select 'yy',2""").collect
checkAnswer(s"""select count(*) from test2""",
Seq(Row(2)), "AlterTableTestCase_RenameTable_001_07_1")
}
//Check data load after table rename
test("RenameTable_001_07_2", Include) {
checkAnswer(s"""select name from test2 where name = 'yy'""",
Seq(Row("yy")), "AlterTableTestCase_RenameTable_001_07_2")
sql(s"""drop table if exists test2""").collect
}
//Check alter table when the altered name is already present in the database
test("RenameTable_001_08", Include) {
intercept[Exception] {
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""create table test2 (name string, id int) stored by 'carbondata'""").collect
sql(s"""alter table test1 RENAME TO test2""").collect
}
sql(s"""drop table if exists test1""").collect
sql(s"""drop table if exists test2""").collect
}
//Check alter table when the altered name is given multiple times
test("RenameTable_001_09", Include) {
intercept[Exception] {
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""alter table test1 RENAME TO test2 test3""").collect
}
sql(s"""drop table if exists test1""").collect
}
//Check delete column for dimension column
test("DeleteCol_001_01", Include) {
intercept[Exception] {
sql(s"""create table test1 (name string, id int) stored by 'carbondata' TBLPROPERTIES('DICTIONARY_INCLUDE'='id') """).collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""alter table test1 drop columns (name)""").collect
sql(s"""select name from test1""").collect
}
sql(s"""drop table if exists test1""").collect
}
//Check delete column for measure column
test("DeleteCol_001_02", Include) {
intercept[Exception] {
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""alter table test1 drop columns (id)""").collect
sql(s"""select id from test1""").collect
}
sql(s"""drop table if exists test1""").collect
}
//Check delete column for measure and dimension column
test("DeleteCol_001_03", Include) {
intercept[Exception] {
sql(s"""create table test1 (name string, country string, upd_time timestamp, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx','yy',current_timestamp,1""").collect
sql(s"""alter table test1 drop columns (id,name)""").collect
sql(s"""select id,name from test1""").collect
}
sql(s"""drop table if exists test1""").collect
}
//Check delete column for multiple column
test("DeleteCol_001_04", Include) {
intercept[Exception] {
sql(s"""create table test1 (name string, country string, upd_time timestamp, id int) stored by 'carbondata' TBLPROPERTIES('DICTIONARY_INCLUDE'='id')""").collect
sql(s"""insert into test1 select 'xx','yy',current_timestamp,1""").collect
sql(s"""alter table test1 drop columns (name, upd_time)""").collect
sql(s"""select name, upd_time from test1""").collect
}
sql(s"""drop table if exists test1""").collect
}
//Check delete column for all columns
test("DeleteCol_001_05", Include) {
sql(s"""create table test1 (name string, country string, upd_time timestamp, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx','yy',current_timestamp,1""").collect
sql(s"""alter table test1 drop columns (name, upd_time, country,id)""").collect
sql(s"""drop table if exists test1""").collect
}
//Check delete column for include dictionary column
test("DeleteCol_001_06", Include) {
intercept[Exception] {
sql(s"""create table test1 (name string, id int) stored by 'carbondata' TBLPROPERTIES('DICTIONARY_INCLUDE'='id')""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""alter table test1 drop columns (id)""").collect
sql(s"""select id from test1""").collect
}
sql(s"""drop table if exists test1""").collect
}
//Check delete column for timestamp column
test("DeleteCol_001_08", Include) {
intercept[Exception] {
sql(s"""create table test1 (name string, country string, upd_time timestamp, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx','yy',current_timestamp,1""").collect
sql(s"""alter table test1 drop columns (upd_time)""").collect
sql(s"""select upd_time from test1""").collect
}
sql(s"""drop table if exists test1""").collect
}
//Check the drop of added column will remove the column from table
test("DeleteCol_001_09_1", Include) {
sql(s"""create table test1 (name string, country string, upd_time timestamp, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx','yy',current_timestamp,1""").collect
sql(s"""alter table test1 add columns (name2 string)""").collect
sql(s"""insert into test1 select 'xx','yy',current_timestamp,1,'abc'""").collect
checkAnswer(s"""select count(id) from test1 where name2 = 'abc'""",
Seq(Row(1)), "AlterTableTestCase_DeleteCol_001_09_1")
sql(s"""drop table if exists test1""").collect
}
//Check the drop of added column will remove the column from table
test("DeleteCol_001_09_2", Include) {
intercept[Exception] {
sql(s"""create table test1 (name string, country string, upd_time timestamp, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx','yy',current_timestamp,1""").collect
sql(s"""alter table test1 add columns (name2 string)""").collect
sql(s"""insert into test1 select 'xx','yy',current_timestamp,1,'abc'""").collect
sql(s"""alter table test1 drop columns (name2)""").collect
sql(s"""select count(id) from test1 where name2 = 'abc'""").collect
}
sql(s"""drop table if exists test1""").collect
}
//Drop a column and add it again with a default value
test("DeleteCol_001_10", Include) {
sql(s"""create table test1 (name string, country string, upd_time timestamp, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx','yy',current_timestamp,1""").collect
sql(s"""alter table test1 drop columns (id)""").collect
sql(s"""alter table test1 add columns (id bigint) tblproperties('default.value.id'='999')""").collect
checkAnswer(s"""select id from test1""",
Seq(Row(999)), "AlterTableTestCase_DeleteCol_001_10")
sql(s"""drop table if exists test1""").collect
}
//Drop a column and add it again with a default value
test("DeleteCol_001_11", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, country string, upd_time timestamp, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx','yy',current_timestamp,1""").collect
sql(s"""alter table test1 drop columns (id)""").collect
sql(s"""insert into test1 select 'a','china',current_timestamp""").collect
sql(s"""alter table test1 add columns (id bigint) tblproperties('default.value.id'='999')""").collect
checkAnswer(s"""select id from test1""",
Seq(Row(999), Row(999)), "AlterTableTestCase_DeleteCol_001_11")
sql(s"""drop table if exists test1""").collect
}
//Check add column for multiple column adds
test("AddColumn_001_01", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (upd_time timestamp, country string)""").collect
checkAnswer(s"""select upd_time, country from test1""",
Seq(Row(null,null)), "AlterTableTestCase_AddColumn_001_01")
sql(s"""drop table if exists test1""").collect
}
//Check add column for dimension column and add table property to set default value
test("AddColumn_001_02", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""insert into test1 select 'xx',12""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (country string) TBLPROPERTIES('DEFAULT.VALUE.country'='China')""").collect
checkAnswer(s"""select count(country) from test1""",
Seq(Row(2)), "AlterTableTestCase_AddColumn_001_02")
sql(s"""drop table if exists test1""").collect
}
//Check add column to add a measure column
test("AddColumn_001_03", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (id1 int)""").collect
checkAnswer(s"""select id1 from test1""",
Seq(Row(null)), "AlterTableTestCase_AddColumn_001_03")
sql(s"""drop table if exists test1""").collect
}
//Check add column to add a measure column added with dictionary include
test("AddColumn_001_04", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""insert into test1 select 'xx',11""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (id1 int) tblproperties('dictionary_include'='id1')""").collect
checkAnswer(s"""select id1 from test1""",
Seq(Row(null), Row(null)), "AlterTableTestCase_AddColumn_001_04")
sql(s"""drop table if exists test1""").collect
}
//Check add column to add a measure column initialized with default value
ignore("AddColumn_001_05", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""insert into test1 select 'xx',11""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (price decimal(10,6)) TBLPROPERTIES('DEFAULT.VALUE.price'='11.111', 'dictionary_include'='price')""").collect
checkAnswer(s"""select sum(price) from test1 where price = 11.111""",
Seq(Row(22.222000)), "AlterTableTestCase_AddColumn_001_05")
sql(s"""drop table if exists test1""").collect
}
//Check add column to add a measure column initialized with default value which does not suite the data type
test("AddColumn_001_06", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (price bigint) TBLPROPERTIES('DEFAULT.VALUE.Price'='1.1','dictionary_include'='price')""").collect
checkAnswer(s"""select price from test1""",
Seq(Row(null)), "AlterTableTestCase_AddColumn_001_06")
sql(s"""drop table if exists test1""").collect
}
//Check add column to add a measure column initialized with default value on a empty table
test("AddColumn_001_07", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (price bigint) TBLPROPERTIES('DEFAULT.VALUE.Price'='11','dictionary_include'='price')""").collect
checkAnswer(s"""select count(id) from test1 where price = 11""",
Seq(Row(1)), "AlterTableTestCase_AddColumn_001_07")
sql(s"""drop table if exists test1""").collect
}
//Check add column to add a dim and measure column
test("AddColumn_001_08", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (id1 int, country string) tblproperties('dictionary_include'='id1')""").collect
checkAnswer(s"""select id1, country from test1""",
Seq(Row(null,null)), "AlterTableTestCase_AddColumn_001_08")
sql(s"""drop table if exists test1""").collect
}
//Check add column for measure and make it dictionary column
test("AddColumn_001_09", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx'""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (Id int) TBLPROPERTIES('DICTIONARY_INCLUDE'='id')""").collect
checkAnswer(s"""select id from test1""",
Seq(Row(null)), "AlterTableTestCase_AddColumn_001_09")
sql(s"""drop table if exists test1""").collect
}
//Check add column to add columns and exclude the dim col from dictionary
test("AddColumn_001_10", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx'""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (upd_time timestamp, country string) TBLPROPERTIES('DICTIONARY_EXCLUDE'='country')""").collect
checkAnswer(s"""select country, upd_time from test1""",
Seq(Row(null,null)), "AlterTableTestCase_AddColumn_001_10")
sql(s"""drop table if exists test1""").collect
}
//Check add column to add a timestamp column
test("AddColumn_001_11", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (upd_time timestamp)""").collect
checkAnswer(s"""select upd_time from test1""",
Seq(Row(null)), "AlterTableTestCase_AddColumn_001_11")
sql(s"""drop table if exists test1""").collect
}
//Check add column with option default value is given for an existing column
test("AddColumn_001_14", Include) {
intercept[Exception] {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx'""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (Id int) TBLPROPERTIES('DICTIONARY_INCLUDE'='id','default.value.name'='yy')""").collect
}
sql(s"""drop table if exists test1""").collect
}
//check alter column for small decimal to big decimal
test("AlterData_001_02", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, price decimal(3,2)) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1.2""").collect
sql(s"""alter table test1 change price price decimal(10,7)""").collect
sql(s"""insert into test1 select 'xx2',999.9999999""").collect
checkAnswer(s"""select name from test1 where price = 999.9999999""",
Seq(Row("xx2")), "AlterTableTestCase_AlterData_001_02")
sql(s"""drop table if exists test1""").collect
}
//check drop table after table rename using new name
test("DropTable_001_01", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, price decimal(3,2)) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1.2""").collect
sql(s"""alter table test1 rename to test2""").collect
sql(s"""drop table test2""").collect
}
//check drop table after table rename using old name
test("DropTable_001_02", Include) {
intercept[Exception] {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, price decimal(3,2)) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1.2""").collect
sql(s"""alter table test1 rename to test2""").collect
sql(s"""drop table test1""").collect
}
sql(s"""drop table if exists test2""").collect
}
//check drop table after table rename using new name, after table load
test("DropTable_001_03", Include) {
sql(s"""create table test1 (name string, price decimal(3,2)) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1.2""").collect
sql(s"""alter table test1 rename to test2""").collect
sql(s"""insert into test2 select 'yy',1""").collect
sql(s"""drop table test2""").collect
}
//check drop table after alter table name, using new name when table is empty
test("DropTable_001_04", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, price decimal(3,2)) stored by 'carbondata'""").collect
sql(s"""alter table test1 rename to test2""").collect
sql(s"""drop table test2""").collect
}
//check drop table when table is altered by adding columns
test("DropTable_001_05", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata' TBLPROPERTIES('DICTIONARY_INCLUDE'='id')""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (upd_time timestamp, country string) TBLPROPERTIES( 'DEFAULT.VALUE.country'='China')""").collect
sql(s"""insert into test1 select 'yy',1,current_timestamp,'xx'""").collect
sql(s"""drop table if exists test1""").collect
}
//Check schema changes and carbon dictionary additions for alter table when new column added
test("StorageFi_001_02", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (country string, name string) stored by 'carbondata' """).collect
sql(s"""insert into test1 select 'xx','uu'""").collect
sql(s"""alter table test1 add columns (price decimal(10,4)) tblproperties('dictionary_include'='price','DEFAULT.VALUE.price'='11.111')""").collect
sql(s"""drop table if exists test1""").collect
}
//Check dictionary cache is loaded with new added column when query is run
ignore("Dictionary_001_01", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id decimal(3,2),country string) stored by 'carbondata' """).collect
sql(s"""insert into test1 select 'xx',1.22,'china'""").collect
sql(s"""alter table test1 add columns (price decimal(10,4)) tblproperties('dictionary_include'='price','DEFAULT.VALUE.price'='11.111')""").collect
checkAnswer(s"""select * from test1""",
Seq(Row("xx",1.22,"china",11.1110)), "AlterTableTestCase_Dictionary_001_01")
sql(s"""drop table if exists test1""").collect
}
//Check if dropped column is removed from driver side LRU cache
test("Dictionary_001_02", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id decimal(3,2),country string) stored by 'carbondata' """).collect
sql(s"""insert into test1 select 'xx',1.22,'china'""").collect
sql(s"""alter table test1 drop columns (country)""").collect
checkAnswer(s"""select * from test1""",
Seq(Row("xx",1.22)), "AlterTableTestCase_Dictionary_001_02")
sql(s"""drop table if exists test1""").collect
}
//Check if dropped column is removed from driver side LRU cache at driver side
test("Dictionary_001_03", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id decimal(3,2),country string) stored by 'carbondata' """).collect
sql(s"""insert into test1 select 'xx',1.22,'china'""").collect
sql(s"""alter table test1 drop columns(country)""").collect
checkAnswer(s"""select * from test1""",
Seq(Row("xx",1.22)), "AlterTableTestCase_Dictionary_001_03")
sql(s"""drop table if exists test1""").collect
}
//Check table load works fine after alter table name
test("Dataload_001_01", Include) {
sql(s"""drop table if exists t_carbn01t""").collect
sql(s"""drop table if exists t_carbn01""").collect
sql(s"""create table default.t_carbn01(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""alter table t_carbn01 rename to t_carbn01t""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01t options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""drop table if exists t_carbn01t""").collect
}
//Check table load into old table after alter table name
test("Dataload_001_02", Include) {
sql(s"""drop table if exists default.t_carbn01""").collect
sql(s"""create table default.t_carbn01(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""alter table t_carbn01 rename to t_carbn01t""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01t options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
checkAnswer(s"""select count(item_name) from t_carbn01t""",
Seq(Row(20)), "AlterTableTestCase_Dataload_001_02")
sql(s"""drop table if exists t_carbn01t""").collect
}
//Check table load works fine after alter table name
test("Dataload_001_03", Include) {
sql(s"""drop table if exists default.t_carbn01""").collect
sql(s"""create table default.t_carbn01(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""alter table t_carbn01 change Profit Profit Decimal(10,4)""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""drop table if exists t_carbn01""").collect
}
//Check table load works fine after alter table name
test("Dataload_001_04", Include) {
sql(s"""drop table if exists default.t_carbn01""").collect
sql(s"""create table default.t_carbn01(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""alter table t_carbn01 add columns (item_code1 string, item_code2 string)""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive2.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date,item_code1, item_code2')""").collect
checkAnswer(s"""select count(item_name) from t_carbn01""",
Seq(Row(20)), "AlterTableTestCase_Dataload_001_04")
sql(s"""drop table if exists t_carbn01""").collect
}
//Check table load works fine after alter table name
test("Dataload_001_05", Include) {
sql(s"""drop table if exists default.t_carbn01""").collect
sql(s"""create table default.t_carbn01(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""alter table t_carbn01 drop columns (Update_time, create_date)""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive2.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name')""").collect
checkAnswer(s"""select count(item_name) from t_carbn01""",
Seq(Row(20)), "AlterTableTestCase_Dataload_001_05")
sql(s"""drop table if exists t_carbn01""").collect
}
//Check if alter table(add column) is supported when data load is happening
test("Concurrent_alter_001_01", Include) {
sql(s"""drop table if exists default.t_carbn01""").collect
sql(s"""create table default.t_carbn01(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""alter table t_carbn01 add columns (item_code1 string, item_code2 string)""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive2.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date,item_code1,item_code2')""").collect
sql(s"""drop table if exists t_carbn01""").collect
}
//Check if alter table(delete column) is supported when data load is happening
test("Concurrent_alter_001_02", Include) {
sql(s"""drop table if exists default.t_carbn01""").collect
sql(s"""create table default.t_carbn01(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""alter table t_carbn01 drop columns (Update_time, create_date)""").collect
sql(s"""drop table if exists t_carbn01""").collect
}
//Check if alter table(change column) is supported when data load is happening
test("Concurrent_alter_001_03", Include) {
sql(s"""drop table if exists default.t_carbn01""").collect
sql(s"""create table default.t_carbn01(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""alter table t_carbn01 change Profit Profit Decimal(10,4)""").collect
sql(s"""drop table if exists t_carbn01""").collect
}
//Check if alter table(rename) is supported when data load is happening
test("Concurrent_alter_001_04", Include) {
sql(s"""drop table if exists default.t_carbn01""").collect
sql(s"""create table default.t_carbn01(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""alter table t_carbn01 rename to t_carbn01t""").collect
sql(s"""drop table if exists t_carbn01t""").collect
}
//check table insert works fine after alter table to add a column
test("Insertint_001_03", Include) {
sql(s"""drop table if exists default.t_carbn01""").collect
sql(s"""drop table if exists default.t_carbn02""").collect
sql(s"""create table default.t_carbn01(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""create table default.t_carbn02(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""alter table t_carbn02 add columns (item_name1 string)""").collect
sql(s"""insert into t_carbn02 select *, 'xxx' from t_carbn01""").collect
sql(s"""Select count(*) from t_carbn02""").collect
sql(s"""drop table if exists t_carbn01""").collect
sql(s"""drop table if exists t_carbn02""").collect
}
//check table insert works fine after alter table to add a column
test("Insertint_001_04", Include) {
sql(s"""drop table if exists default.t_carbn01""").collect
sql(s"""drop table if exists default.t_carbn02""").collect
sql(s"""create table default.t_carbn01(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""create table default.t_carbn02(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""alter table t_carbn02 change Profit Profit decimal(10,4)""").collect
sql(s"""insert into t_carbn02 select * from t_carbn01""").collect
sql(s"""Select count(*) from t_carbn02""").collect
sql(s"""drop table if exists t_carbn01""").collect
sql(s"""drop table if exists t_carbn02""").collect
}
//check table insert works fine after alter table to drop columns
test("Insertint_001_05", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test2 (country string, name string, state_id int,id int) stored by 'carbondata' """).collect
sql(s"""create table test1 (country string, state_id int) stored by 'carbondata' """).collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""alter table test2 drop columns (name, id)""").collect
sql(s"""insert into test2 select * from test1""").collect
checkAnswer(s"""Select count(*) from test2""",
Seq(Row(1)), "AlterTableTestCase_Insertint_001_05")
sql(s"""drop table if exists test2""").collect
sql(s"""drop table if exists test1""").collect
}
//Check show segments on old table After altering the Table name.
test("Showsegme_001_01", Include) {
intercept[Exception] {
sql(s"""create table test1 (country string, id int) stored by 'carbondata'""").collect
sql(s"""alter table test1 rename to test2""").collect
sql(s"""show segments for table test1""").collect
}
sql(s"""drop table if exists test2""").collect
}
//Check vertical compaction on old table after altering the table name
test("Compaction_001_01", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""drop table if exists test2""").collect
sql(s"""create table test1(name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""insert into test1 select 'xe',2""").collect
sql(s"""insert into test1 select 'xr',3""").collect
sql(s"""alter table test1 rename to test2""").collect
sql(s"""alter table test2 compact 'minor'""").collect
sql(s"""drop table if exists test2""").collect
}
//Check vertical compaction on new table when all segments are created before alter table name.
test("Compaction_001_02", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""drop table if exists test2""").collect
sql(s"""create table test1(name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""insert into test1 select 'xe',2""").collect
sql(s"""insert into test1 select 'xr',3""").collect
sql(s"""alter table test1 rename to test2""").collect
sql(s"""alter table test2 compact 'minor'""").collect
checkAnswer(s"""select name from test2 where id =2""",
Seq(Row("xe")), "AlterTableTestCase_Compaction_001_02")
sql(s"""drop table if exists test2""").collect
}
//Check vertical compaction on new table when some of the segments are created after altering the table name
test("Compaction_001_03", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""drop table if exists test2""").collect
sql(s"""create table test1(name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""insert into test1 select 'xe',2""").collect
sql(s"""alter table test1 rename to test2""").collect
sql(s"""insert into test2 select 'xr',3""").collect
sql(s"""alter table test2 compact 'minor'""").collect
checkAnswer(s"""select name from test2 where id =2""",
Seq(Row("xe")), "AlterTableTestCase_Compaction_001_03")
sql(s"""drop table if exists test2""").collect
}
//Check vertical compaction on new table after altering the table name multiple times and and segments created after alter
test("Compaction_001_04", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""drop table if exists test2""").collect
sql(s"""drop table if exists test3""").collect
sql(s"""create table test1(name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""alter table test1 rename to test2""").collect
sql(s"""insert into test2 select 'xe',2""").collect
sql(s"""alter table test2 rename to test3""").collect
sql(s"""insert into test3 select 'xr',3""").collect
sql(s"""alter table test3 compact 'minor'""").collect
checkAnswer(s"""select name from test3 where id =2""",
Seq(Row("xe")), "AlterTableTestCase_Compaction_001_04")
sql(s"""drop table if exists test3""").collect
}
//Check vertical compaction(major) on new table name when part of the segments are created before altering the table name
test("Compaction_001_05", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""drop table if exists test2""").collect
sql(s"""create table test1(name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""insert into test1 select 'xe',2""").collect
sql(s"""alter table test1 rename to test2""").collect
sql(s"""insert into test2 select 'xr',3""").collect
sql(s"""alter table test2 compact 'major'""").collect
sql(s"""select name from test2 where id =2""").collect
sql(s"""drop table if exists test2""").collect
}
//Check vertical compaction when all segments are created before drop column, check dropped column is not used in the compation
test("Compaction_001_06", Include) {
intercept[Exception] {
sql(s"""drop table if exists test1""").collect
sql(s"""drop table if exists test2""").collect
sql(s"""create table test1(name string, country string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx','china',1""").collect
sql(s"""insert into test1 select 'xe','china',2""").collect
sql(s"""insert into test1 select 'xe','china',3""").collect
sql(s"""alter table test1 drop columns (country)""").collect
sql(s"""alter table test1 compact 'minor'""").collect
sql(s"""select country from test1 where country='china'""").collect
}
sql(s"""drop table if exists test1""").collect
}
//Check vertical compaction when some of the segments are created before drop column, check dropped column is not used in the compation
test("Compaction_001_07", Include) {
intercept[Exception] {
sql(s"""drop table if exists test1""").collect
sql(s"""drop table if exists test2""").collect
sql(s"""create table test1(name string, country string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx','china',1""").collect
sql(s"""insert into test1 select 'xe','china',2""").collect
sql(s"""alter table test1 drop columns (country)""").collect
sql(s"""insert into test1 select 'xe',3""").collect
sql(s"""alter table test1 compact 'minor'""").collect
sql(s"""select country from test1 where country='china'""").collect
}
sql(s"""drop table if exists test1""").collect
}
//Check vertical compaction for multiple drop column, check dropped column is not used in the compation
test("Compaction_001_08", Include) {
intercept[Exception] {
sql(s"""drop table if exists test1""").collect
sql(s"""drop table if exists test2""").collect
sql(s"""create table test1(name string, country string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx','china',1""").collect
sql(s"""alter table test1 drop columns (country)""").collect
sql(s"""insert into test1 select 'xe',3""").collect
sql(s"""alter table test1 drop columns (id)""").collect
sql(s"""insert into test1 select 'xe'""").collect
sql(s"""alter table test1 compact 'minor'""").collect
sql(s"""select country from test1 where id=1""").collect
}
sql(s"""drop table if exists test1""").collect
}
//Check vertical compaction on altered table for column add, when all segments crreated before table alter. Ensure added column in the compacted segment
test("Compaction_001_09", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""drop table if exists test2""").collect
sql(s"""create table test1(name string) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx3'""").collect
sql(s"""insert into test1 select 'xx2'""").collect
sql(s"""insert into test1 select 'xx1'""").collect
sql(s"""alter table test1 add columns (country string)""").collect
sql(s"""alter table test1 compact 'minor'""").collect
checkAnswer(s"""select country from test1 group by country""",
Seq(Row(null)), "AlterTableTestCase_Compaction_001_09")
sql(s"""drop table if exists test1""").collect
}
//Check vertical compaction on altered table for column add, when some of the segments crreated before table alter. Ensure added column in the compacted segment
test("Compaction_001_10", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1(name string) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx1'""").collect
sql(s"""insert into test1 select 'xx2'""").collect
sql(s"""alter table test1 add columns (country string)""").collect
sql(s"""insert into test1 select 'xx1','china'""").collect
sql(s"""alter table test1 compact 'minor'""").collect
checkAnswer(s"""select country from test1 group by country""",
Seq(Row(null), Row("china")), "AlterTableTestCase_Compaction_001_10")
sql(s"""drop table if exists test1""").collect
}
//Check vertical compaction on multiple altered table for column add, when some of the segments crreated after table alter. Ensure added column in the compacted segment
test("Compaction_001_11", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1(name string) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx1'""").collect
sql(s"""insert into test1 select 'xx2'""").collect
sql(s"""alter table test1 add columns (id int) tblproperties('dictionary_include'='id')""").collect
sql(s"""insert into test1 select 'xx1',1""").collect
sql(s"""alter table test1 add columns (country string)""").collect
sql(s"""insert into test1 select 'xx1',1, 'china'""").collect
sql(s"""alter table test1 compact 'minor'""").collect
checkAnswer(s"""select country from test1 group by country""",
Seq(Row(null), Row("china")), "AlterTableTestCase_Compaction_001_11")
sql(s"""drop table if exists test1""").collect
}
//Check vertical compaction on altered table for change column datatype, when some of the segments crreated after table alter. Ensure added column in the compacted segment
test("Compaction_001_12", Include) {
sql(s"""drop table if exists default.test1""").collect
sql(s"""create table test1(name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx1',1""").collect
sql(s"""insert into test1 select 'xx2',2""").collect
sql(s"""alter table test1 change id id bigint """).collect
sql(s"""insert into test1 select 'xx2',2999999999""").collect
sql(s"""alter table test1 compact 'minor'""").collect
checkAnswer(s"""select id from test1""",
Seq(Row(1),Row(2), Row(2999999999L)), "AlterTableTestCase_Compaction_001_12")
sql(s"""drop table if exists test1""").collect
}
test("Compaction_001_13", Include) {
sql("drop table if exists no_table")
var ex = intercept[MalformedCarbonCommandException] {
sql("alter table no_table compact 'major'")
}
assertResult("Table or view 'no_table' not found in database 'default' or not carbon fileformat")(ex.getMessage)
}
//Check bad record locaion isnot changed when table name is altered
test("BadRecords_001_01", Include) {
sql(s"""drop table if exists default.t_carbn01""").collect
sql(s"""create table default.t_carbn01(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1_Bad.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\','BAD_RECORDS_LOGGER_ENABLE'='true', 'BAD_RECORDS_ACTION'='REDIRECT', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""alter table default.t_carbn01 rename to default.t_carbn01t""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1_Bad.csv' INTO table default.t_carbn01t options ('DELIMITER'=',', 'QUOTECHAR'='\','BAD_RECORDS_LOGGER_ENABLE'='true', 'BAD_RECORDS_ACTION'='REDIRECT', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""drop table if exists default.t_carbn01t""").collect
}
//Check bad record locaion isnot changed when table name is altered
test("BadRecords_001_02", Include) {
sql(s"""drop table if exists default.t_carbn01""").collect
sql(s"""create table default.t_carbn01(Active_status String,Item_type_cd INT,Qty_day_avg INT,Qty_total INT,Sell_price BIGINT,Sell_pricep DOUBLE,Discount_price DOUBLE,Profit DECIMAL(3,2),Item_code String,Item_name String,Outlet_name String,Update_time TIMESTAMP,Create_date String)STORED BY 'org.apache.carbondata.format'""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/InsertData/T_Hive1_Bad.csv' INTO table default.t_carbn01 options ('DELIMITER'=',', 'QUOTECHAR'='\','BAD_RECORDS_LOGGER_ENABLE'='true', 'BAD_RECORDS_ACTION'='REDIRECT', 'FILEHEADER'='Active_status,Item_type_cd,Qty_day_avg,Qty_total,Sell_price,Sell_pricep,Discount_price,Profit,Item_code,Item_name,Outlet_name,Update_time,Create_date')""").collect
sql(s"""alter table t_carbn01 drop columns (item_name)""").collect
sql(s"""drop table if exists default.t_carbn01""").collect
}
//Check for bad record handling while latering the table if added column is set with default value which is a bad record
test("BadRecords_001_03", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""insert into test1 select 'xx',12""").collect
sql(s"""ALTER TABLE test1 ADD COLUMNS (id2 int) TBLPROPERTIES('include_dictionary'='id2','DEFAULT.VALUE.id2'='China')""").collect
checkAnswer(s"""select * from test1 where id = 1""",
Seq(Row("xx",1,null)), "AlterTableTestCase_BadRecords_001_03")
sql(s"""drop table if exists test1""").collect
}
//Check delete segment is not allowed on old table name when table name is altered
test("DeleteSeg_001_01", Include) {
intercept[Exception] {
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""insert into test1 select 'xx',12""").collect
sql(s"""alter table test1 rename to test2""").collect
sql(s"""delete from table test1 where segment.id in (0)""").collect
}
sql(s"""drop table if exists test2""").collect
}
//Check delete segment is allowed on new table name when table name is altered
test("DeleteSeg_001_02", Include) {
sql(s"""drop table if exists test1""").collect
sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
sql(s"""insert into test1 select 'xx',1""").collect
sql(s"""insert into test1 select 'xx',12""").collect
sql(s"""alter table test1 rename to test2""").collect
sql(s"""delete from table test2 where segment.id in (0)""").collect
checkAnswer(s"""Select * from test2""",
Seq(Row("xx",12)), "AlterTableTestCase_DeleteSeg_001_02")
sql(s"""drop table if exists test2""").collect
}
//Check alter the table name,alter the table name again with first name and fire Select query
test("AlterTable-001-AltersameTablename-001-TC001", Include) {
sql(s"""drop table if exists uniqdata""").collect
sql(s"""drop table if exists uniqdata1""").collect
sql(s"""CREATE TABLE uniqdata (CUST_ID int,CUST_NAME String,ACTIVE_EMUI_VERSION string, DOB timestamp, DOJ timestamp, BIGINT_COLUMN1 bigint,BIGINT_COLUMN2 bigint,DECIMAL_COLUMN1 decimal(30,10), DECIMAL_COLUMN2 decimal(36,10),Double_COLUMN1 double, Double_COLUMN2 double,INTEGER_COLUMN1 int) STORED BY 'org.apache.carbondata.format' TBLPROPERTIES('DICTIONARY_INCLUDE'='BIGINT_COLUMN1,BIGINT_COLUMN2,DECIMAL_COLUMN1,DECIMAL_COLUMN2,INTEGER_COLUMN1,CUST_ID')""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/uniqdata/2000_UniqData.csv' into table uniqdata OPTIONS('DELIMITER'=',' , 'QUOTECHAR'='"','BAD_RECORDS_LOGGER_ENABLE'='TRUE', 'BAD_RECORDS_ACTION'='FORCE','FILEHEADER'='CUST_ID,CUST_NAME,ACTIVE_EMUI_VERSION,DOB,DOJ,BIGINT_COLUMN1,BIGINT_COLUMN2,DECIMAL_COLUMN1,DECIMAL_COLUMN2,Double_COLUMN1,Double_COLUMN2,INTEGER_COLUMN1')""").collect
sql(s"""alter table uniqdata RENAME TO uniqdata1""").collect
sql(s"""alter table uniqdata1 RENAME TO uniqdata""").collect
sql(s"""select * from uniqdata where cust_name like 'Cust%'""").collect
sql(s"""drop table if exists uniqdata""").collect
sql(s"""drop table if exists uniqdata1""").collect
}
//Check select query after alter the int to Bigint and decimal Lower Precision to higher precision
test("AlterTable-007-selectquery-001-TC002", Include) {
sql(s"""CREATE TABLE uniqdata1 (CUST_ID int,CUST_NAME String,ACTIVE_EMUI_VERSION string, DOB timestamp, DOJ timestamp, BIGINT_COLUMN1 bigint,BIGINT_COLUMN2 bigint,DECIMAL_COLUMN1 decimal(30,10), DECIMAL_COLUMN2 decimal(36,10),Double_COLUMN1 double, Double_COLUMN2 double,INTEGER_COLUMN1 int) STORED BY 'org.apache.carbondata.format' TBLPROPERTIES('DICTIONARY_INCLUDE'='BIGINT_COLUMN1,BIGINT_COLUMN2,DECIMAL_COLUMN1,DECIMAL_COLUMN2,INTEGER_COLUMN1,CUST_ID')""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/uniqdata/2000_UniqData.csv' into table uniqdata1 OPTIONS('DELIMITER'=',' , 'QUOTECHAR'='"','BAD_RECORDS_LOGGER_ENABLE'='TRUE', 'BAD_RECORDS_ACTION'='FORCE','FILEHEADER'='CUST_ID,CUST_NAME,ACTIVE_EMUI_VERSION,DOB,DOJ,BIGINT_COLUMN1,BIGINT_COLUMN2,DECIMAL_COLUMN1,DECIMAL_COLUMN2,Double_COLUMN1,Double_COLUMN2,INTEGER_COLUMN1')""").collect
sql(s"""ALTER TABLE uniqdata1 CHANGE CUST_ID CUST_ID BIGINT""").collect
sql(s"""select * from uniqdata1 where cust_name like 'Cust%'""").collect
sql(s"""drop table if exists uniqdata1""").collect
}
//Check select query after alter from lower to higher precision
test("AlterTable-008-selectquery-001-TC003", Include) {
sql(s"""CREATE TABLE uniqdata1 (CUST_ID int,CUST_NAME String,ACTIVE_EMUI_VERSION string, DOB timestamp, DOJ timestamp, BIGINT_COLUMN1 bigint,BIGINT_COLUMN2 bigint,DECIMAL_COLUMN1 decimal(30,10), DECIMAL_COLUMN2 decimal(36,10),Double_COLUMN1 double, Double_COLUMN2 double,INTEGER_COLUMN1 int) STORED BY 'org.apache.carbondata.format' TBLPROPERTIES('DICTIONARY_INCLUDE'='BIGINT_COLUMN1,BIGINT_COLUMN2,DECIMAL_COLUMN1,DECIMAL_COLUMN2,INTEGER_COLUMN1,CUST_ID')""").collect
sql(s"""LOAD DATA INPATH '$resourcesPath/Data/uniqdata/2000_UniqData.csv' into table uniqdata1 OPTIONS('DELIMITER'=',' , 'QUOTECHAR'='"','BAD_RECORDS_LOGGER_ENABLE'='TRUE', 'BAD_RECORDS_ACTION'='FORCE','FILEHEADER'='CUST_ID,CUST_NAME,ACTIVE_EMUI_VERSION,DOB,DOJ,BIGINT_COLUMN1,BIGINT_COLUMN2,DECIMAL_COLUMN1,DECIMAL_COLUMN2,Double_COLUMN1,Double_COLUMN2,INTEGER_COLUMN1')""").collect
sql(s"""ALTER TABLE uniqdata1 CHANGE decimal_column1 decimal_column1 DECIMAL(31,11)""").collect