-
Notifications
You must be signed in to change notification settings - Fork 449
/
Copy pathAlterTableDdlTest.cpp
1967 lines (1800 loc) · 78.2 KB
/
AlterTableDdlTest.cpp
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
/*
* Copyright 2022 HEAVY.AI, Inc.
*
* Licensed 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.
*/
#include <gtest/gtest.h>
#include <boost/algorithm/string.hpp>
#include <boost/iterator/counting_iterator.hpp>
#include "boost/filesystem.hpp"
#include "Catalog/Catalog.h"
#include "DBHandlerTestHelpers.h"
#include "Fragmenter/InsertOrderFragmenter.h"
#include "Geospatial/Types.h"
#include "ImportExport/Importer.h"
#include "QueryEngine/ResultSet.h"
#include "QueryRunner/QueryRunner.h"
#include "Shared/UpdelRoll.h"
#include "Shared/scope.h"
#include "Tests/TestHelpers.h"
#include <tuple>
#ifndef BASE_PATH
#define BASE_PATH "./tmp"
#endif
using namespace Catalog_Namespace;
using namespace TestHelpers;
using QR = QueryRunner::QueryRunner;
extern bool g_test_drop_column_rollback;
namespace {
bool g_hoist_literals{true};
inline void run_ddl_statement(const std::string& input_str) {
QR::get()->runDDLStatement(input_str);
}
std::shared_ptr<ResultSet> run_query(const std::string& query_str) {
return QR::get()->runSQL(query_str, ExecutorDeviceType::CPU, g_hoist_literals, true);
}
std::unique_ptr<QR> get_qr_for_user(
const std::string& user_name,
const Catalog_Namespace::UserMetadata& user_metadata) {
auto session = std::make_unique<Catalog_Namespace::SessionInfo>(
Catalog_Namespace::SysCatalog::instance().getCatalog(user_name),
user_metadata,
ExecutorDeviceType::CPU,
"");
return std::make_unique<QR>(std::move(session));
}
template <typename E = std::runtime_error>
bool alter_common(const std::string& table,
const std::string& column,
const std::string& type,
const std::string& comp,
const std::string& val,
const std::string& val2,
const bool expect_throw = false) {
std::string alter_query = "alter table " + table + " add column " + column + " " + type;
if (val != "") {
alter_query += " default " + val;
}
if (comp != "") {
alter_query += " encoding " + comp;
}
if (expect_throw) {
EXPECT_THROW(run_ddl_statement(alter_query + ";"), E);
return true;
} else {
EXPECT_NO_THROW(run_ddl_statement(alter_query + ";"););
}
if (val2 != "") {
std::string query_str = "SELECT " + column + " FROM " + table;
auto rows = run_query(query_str + ";");
int r_cnt = 0;
while (true) {
auto crt_row = rows->getNextRow(true, true);
if (0 == crt_row.size()) {
break;
}
auto geo = v<NullableString>(crt_row[0]);
auto geo_s = boost::get<std::string>(&geo);
auto geo_v = boost::get<void*>(&geo);
#if 1
if (!geo_s && geo_v && *geo_v == nullptr && val2 == "NULL") {
++r_cnt;
}
if (!geo_v && geo_s && *geo_s == val2) {
++r_cnt;
}
#else
// somehow these do not work as advertised ...
using namespace Geospatial;
if (boost::iequals(type, "POINT") && GeoPoint(geo) == GeoPoint(val2))
++r_cnt;
else if (boost::iequals(type, "LINESTRING") &&
GeoLineString(geo) == GeoLineString(val2))
++r_cnt;
else if (boost::iequals(type, "POLYGON") && GeoPolygon(geo) == GeoPolygon(val2))
++r_cnt;
else if (boost::iequals(type, "MULTIPOLYGON") &&
GeoMultiPolygon(geo) == GeoMultiPolygon(val2))
++r_cnt;
#endif
}
return r_cnt == 100;
} else {
std::string query_str =
"SELECT count(*) FROM " + table + " WHERE " + column +
("" == val || boost::iequals("NULL", val) ? " IS NULL" : (" = " + val));
auto rows = run_query(query_str + ";");
auto crt_row = rows->getNextRow(true, true);
CHECK_EQ(size_t(1), crt_row.size());
auto r_cnt = v<int64_t>(crt_row[0]);
return r_cnt == 100;
}
}
void import_table_file(const std::string& table, const std::string& file) {
const auto query_str = std::string("COPY trips FROM '") +
"../../Tests/Import/datafiles/" + file +
"' WITH (header='true');";
auto stmt = QR::get()->createStatement(query_str);
auto copy_stmt = dynamic_cast<Parser::CopyTableStmt*>(stmt.get());
if (!copy_stmt) {
throw std::runtime_error("Expected a CopyTableStatment: " + query_str);
}
QR::get()->runImport(copy_stmt);
}
// don't use R"()" format; somehow it causes many blank lines
// to be output on console. how come?
const char* create_table_trips =
" CREATE TABLE trips ("
" medallion TEXT ENCODING DICT,"
" hack_license TEXT ENCODING DICT,"
" vendor_id TEXT ENCODING DICT,"
" rate_code_id SMALLINT,"
" store_and_fwd_flag TEXT ENCODING DICT,"
" pickup_datetime TIMESTAMP,"
" dropoff_datetime TIMESTAMP,"
" passenger_count SMALLINT,"
" trip_time_in_secs INTEGER,"
" trip_distance FLOAT,"
" pickup_longitude DECIMAL(14,7),"
" pickup_latitude DECIMAL(14,7),"
" dropoff_longitude DOUBLE,"
" dropoff_latitude DECIMAL(18,5),"
" deleted BOOLEAN"
" ) WITH (FRAGMENT_SIZE=50);"; // so 2 fragments here
void init_table_data(const std::string& table = "trips",
const std::string& create_table_cmd = create_table_trips,
const std::string& file = "trip_data_dir/trip_data_b.txt") {
run_ddl_statement("drop table if exists " + table + ";");
run_ddl_statement(create_table_cmd);
if (file.size()) {
import_table_file(table, file);
}
}
class AlterColumnTest : public ::testing::Test {
protected:
void SetUp() override { ASSERT_NO_THROW(init_table_data();); }
void TearDown() override { ASSERT_NO_THROW(run_ddl_statement("drop table trips;");); }
};
#define MT std::make_tuple
std::vector<std::tuple<std::string, std::string, std::string, std::string>> type_vals = {
MT("text", "none", "'abc'", ""),
MT("text", "dict(8)", "'ijk'", ""),
MT("text", "dict(32)", "'xyz'", ""),
MT("float", "", "1.25", ""),
MT("double", "", "1.25", ""),
MT("smallint", "", "123", ""),
MT("integer", "", "123", ""),
MT("bigint", "", "123", ""),
MT("bigint encoding fixed(8)", "", "", ""),
MT("bigint encoding fixed(16)", "", "", ""),
MT("bigint encoding fixed(32)", "", "", ""),
MT("decimal(8)", "", "123", ""),
MT("decimal(8,2)", "", "1.23", ""),
MT("date", "", "'2011-10-23'", ""),
MT("time", "", "'10:23:45'", ""),
MT("timestamp", "", "'2011-10-23 10:23:45'", ""),
MT("POINT", "", "'POINT (1 2)'", "POINT (1 2)"),
MT("LINESTRING", "", "'LINESTRING (1 1,2 2,3 3)'", "LINESTRING (1 1,2 2,3 3)"),
MT("POLYGON",
"",
"'POLYGON((0 0,0 9,9 9,9 0),(1 1,2 2,3 3))'",
"POLYGON ((9 0,9 9,0 9,0 0,9 0),(3 3,2 2,1 1,3 3))"),
MT("MULTIPOLYGON",
"",
"'MULTIPOLYGON(((0 0,0 9,9 9,9 0),(1 1,2 2,3 3)))'",
"MULTIPOLYGON (((9 0,9 9,0 9,0 0,9 0),(3 3,2 2,1 1,3 3)))"),
};
#undef MT
TEST_F(AlterColumnTest, Add_column_with_default) {
int cid = 0;
for (const auto& tv : type_vals) {
EXPECT_TRUE(alter_common("trips",
"x" + std::to_string(++cid),
std::get<0>(tv),
std::get<1>(tv),
std::get<2>(tv),
std::get<3>(tv),
false));
}
}
TEST_F(AlterColumnTest, Add_column_with_null) {
int cid = 0;
for (const auto& tv : type_vals) {
if (std::get<3>(tv) == "") {
EXPECT_TRUE(alter_common("trips",
"x" + std::to_string(++cid),
std::get<0>(tv),
std::get<1>(tv),
"",
"",
false));
} else {
// Geometry column
// Doesn't throw, no explicit default (default is NULL geo),
EXPECT_TRUE(alter_common("trips",
"x" + std::to_string(++cid),
std::get<0>(tv),
std::get<1>(tv),
"", // no explicit default (NULL geo)
"NULL",
false));
}
}
}
TEST(AlterColumnTest2, Drop_after_fail_to_add) {
EXPECT_NO_THROW(run_ddl_statement("drop table if exists t;"););
EXPECT_NO_THROW(run_ddl_statement("create table t(c1 int);"););
EXPECT_NO_THROW(run_query("insert into t values (10);"););
EXPECT_THROW(
run_ddl_statement("alter table t add column c2 TEXT NOT NULL ENCODING DICT;"),
std::runtime_error);
EXPECT_NO_THROW(run_ddl_statement("drop table t;"););
}
TEST(AlterColumnTest3, Add_col_to_sharded_table) {
EXPECT_NO_THROW(run_ddl_statement("drop table if exists x;"););
EXPECT_NO_THROW(run_ddl_statement(
"create table x (i text,SHARD KEY (i)) WITH (SHARD_COUNT = 2);"););
EXPECT_NO_THROW(run_ddl_statement("alter table x add column j int;"););
EXPECT_NO_THROW(run_query("insert into x values('0',0);"););
}
void drop_columns(const bool rollback, const std::vector<std::string>&& dropped_columns) {
g_test_drop_column_rollback = rollback;
std::vector<std::string> drop_column_phrases;
std::transform(
dropped_columns.begin(),
dropped_columns.end(),
std::back_inserter(drop_column_phrases),
[](const auto& dropped_column) -> auto{
using namespace std::string_literals;
return dropped_column;
});
std::string drop_column_statement = "alter table t drop column " +
boost::algorithm::join(drop_column_phrases, ",") +
";";
if (g_test_drop_column_rollback) {
EXPECT_THROW(run_ddl_statement(drop_column_statement), std::runtime_error);
for (const auto& dropped_column : dropped_columns) {
EXPECT_NO_THROW(run_query("select count(" + dropped_column + ") from t;"));
}
} else {
EXPECT_NO_THROW(run_ddl_statement(drop_column_statement););
for (const auto& dropped_column : dropped_columns) {
EXPECT_THROW(run_query("select count(" + dropped_column + ") from t;"),
std::exception);
}
}
const auto rows = run_query("select count(a), count(f) from t;");
const auto crt_row = rows->getNextRow(true, true);
CHECK_EQ(size_t(2), crt_row.size());
CHECK_EQ(v<int64_t>(crt_row[0]), 2);
CHECK_EQ(v<int64_t>(crt_row[1]), 2);
EXPECT_NO_THROW(run_query("select a from t;"));
}
class AlterColumnTest4 : public ::testing::Test {
protected:
void SetUp() override {
EXPECT_NO_THROW(run_ddl_statement("drop view if exists v;"););
EXPECT_NO_THROW(run_ddl_statement("drop table if exists t;"););
EXPECT_NO_THROW(
run_ddl_statement("create table t(a text, t text, b int, c point, shared "
"dictionary(t) references t(a)) with (fragment_size=1);"););
EXPECT_NO_THROW(run_ddl_statement("alter table t add d point;"););
EXPECT_NO_THROW(run_ddl_statement("alter table t add e int;"););
EXPECT_NO_THROW(run_ddl_statement("alter table t add f float;"););
EXPECT_NO_THROW(
run_query(
"insert into t values ('0', '0', 0, 'point(0 0)', 'point(0 0)', 0, 0);"););
EXPECT_NO_THROW(
run_query(
"insert into t values ('1', '1', 1, 'point(1 1)', 'point(1 1)', 1, 1);"););
g_test_drop_column_rollback = false;
}
void TearDown() override { EXPECT_NO_THROW(run_ddl_statement("drop table t;");); }
};
TEST_F(AlterColumnTest4, Consecutive_drop_columns_different_data_types) {
drop_columns(false, {"b"});
drop_columns(false, {"c", "d"});
drop_columns(false, {"e", "t"});
}
TEST_F(AlterColumnTest4, Drop_columns_rollback) {
drop_columns(true, {"a", "c", "d", "f"});
}
TEST_F(AlterColumnTest4, Drop_column_referenced_by_view) {
EXPECT_NO_THROW(run_ddl_statement("create view v as select b from t;"););
drop_columns(false, {"b"});
EXPECT_THROW(run_query("select count(b) from v;"), std::exception);
}
TEST_F(AlterColumnTest4, Alter_column_of_view) {
EXPECT_NO_THROW(run_ddl_statement("create view v as select b from t;"););
EXPECT_THROW(run_ddl_statement("alter table v add column i int;"), std::runtime_error);
EXPECT_THROW(run_ddl_statement("alter table v drop column b;"), std::runtime_error);
}
TEST_F(AlterColumnTest4, Alter_inexistent_table) {
EXPECT_THROW(run_ddl_statement("alter table xx drop column xxx;"), std::runtime_error);
}
TEST_F(AlterColumnTest4, Alter_inexistent_table_column) {
EXPECT_THROW(run_ddl_statement("alter table t drop column xxx;"), std::runtime_error);
}
TEST(AlterColumnTest5, Drop_the_only_column) {
EXPECT_NO_THROW(run_ddl_statement("drop table if exists x;"););
EXPECT_NO_THROW(run_ddl_statement("create table x (i int);"););
EXPECT_THROW(run_ddl_statement("alter table x drop column i;"), std::runtime_error);
}
TEST(AlterColumnTest5, Drop_sharding_column) {
EXPECT_NO_THROW(run_ddl_statement("drop table if exists x;"););
EXPECT_NO_THROW(
run_ddl_statement(
"create table x (i int, j int, SHARD KEY (i)) WITH (SHARD_COUNT = 2);"););
EXPECT_THROW(run_ddl_statement("alter table x drop column i;"), std::runtime_error);
}
TEST(AlterColumnTest5, DISABLED_Drop_temp_table_column) {
// TODO(adb): The Catalog still runs SQLite queries with drop column. While they are
// essentially no-op queries, we should disable running the queries for both alter and
// drop in a consistent way. Currently Alter/drop are disabled on temp tables.
EXPECT_NO_THROW(run_ddl_statement("drop table if exists x;"););
EXPECT_NO_THROW(run_ddl_statement("create TEMPORARY table x (i int, j int);"););
EXPECT_NO_THROW(run_query("insert into x values (0,0);"););
EXPECT_NO_THROW(run_query("insert into x values (1,1);"););
EXPECT_NO_THROW(run_ddl_statement("alter table x drop column j;"););
EXPECT_NO_THROW(run_query("select i from x;"));
}
TEST(AlterColumnTest5, Drop_table_by_unauthorized_user) {
using namespace std::string_literals;
auto admin = "admin"s;
auto admin_password = "HyperInteractive"s;
auto thief = "thief"s;
auto thief_password = "thief"s;
auto lucky = "lucky"s;
auto lucky_password = "lucky"s;
auto mydb = "mydb"s;
auto& sys_cat = Catalog_Namespace::SysCatalog::instance();
EXPECT_NO_THROW(run_ddl_statement("CREATE DATABASE mydb (owner='admin');"););
EXPECT_NO_THROW(run_ddl_statement("CREATE USER thief (password='thief');"););
EXPECT_NO_THROW(run_ddl_statement("CREATE USER lucky (password='lucky');"););
ScopeGuard scope_guard = [] {
run_ddl_statement("DROP USER lucky;");
run_ddl_statement("DROP USER thief;");
run_ddl_statement("DROP DATABASE mydb;");
};
// login to mydb as admin
Catalog_Namespace::UserMetadata user_meta1;
EXPECT_NO_THROW(sys_cat.login(mydb, admin, admin_password, user_meta1, false););
auto qr1 = get_qr_for_user(mydb, user_meta1);
auto dt = ExecutorDeviceType::CPU;
EXPECT_NO_THROW(qr1->runDDLStatement("CREATE TABLE x (i int, j int, k int);"));
EXPECT_NO_THROW(qr1->runSQL("insert into x values (0, 0, 0);", dt));
EXPECT_NO_THROW(qr1->runDDLStatement("alter table x drop column k;"));
EXPECT_NO_THROW(qr1->runSQL("select i from x;", dt));
EXPECT_NO_THROW(qr1->runDDLStatement("grant alter on table x to lucky;"));
// login to mydb as thief
Catalog_Namespace::UserMetadata user_meta2;
EXPECT_NO_THROW(sys_cat.login(mydb, thief, thief_password, user_meta2, false));
auto qr2 = get_qr_for_user(mydb, user_meta2);
EXPECT_THROW(qr2->runDDLStatement("alter table x drop column j;"), std::runtime_error);
// login to mydb as lucky
Catalog_Namespace::UserMetadata user_meta3;
EXPECT_NO_THROW(sys_cat.login(mydb, lucky, lucky_password, user_meta3, false));
auto qr3 = get_qr_for_user(mydb, user_meta3);
EXPECT_NO_THROW(qr3->runDDLStatement("alter table x drop column j;"));
}
} // namespace
class AlterTableSetMaxRowsTest : public DBHandlerTestFixture {
protected:
void SetUp() override {
DBHandlerTestFixture::SetUp();
sql("drop table if exists test_table;");
}
void TearDown() override {
sql("drop table if exists test_table;");
DBHandlerTestFixture::TearDown();
}
void insertRange(size_t start, size_t end) {
for (size_t i = start; i <= end; i++) {
sql("insert into test_table values (" + std::to_string(i) + ");");
}
}
void assertMaxRows(int64_t max_rows) {
auto td = getCatalog().getMetadataForTable("test_table", false);
ASSERT_EQ(max_rows, td->maxRows);
}
};
TEST_F(AlterTableSetMaxRowsTest, MaxRowsLessThanTableRows) {
sql("create table test_table (i integer) with (fragment_size = 2);");
insertRange(1, 5);
sqlAndCompareResult("select * from test_table;",
{{i(1)}, {i(2)}, {i(3)}, {i(4)}, {i(5)}});
sql("alter table test_table set max_rows = 4;");
assertMaxRows(4);
// Oldest fragment is deleted, so last 3 rows should remain.
sqlAndCompareResult("select * from test_table;", {{i(3)}, {i(4)}, {i(5)}});
}
TEST_F(AlterTableSetMaxRowsTest, MaxRowsLessThanTableRowsAndSingleFragment) {
sql("create table test_table (i integer) with (fragment_size = 10);");
insertRange(1, 5);
sqlAndCompareResult("select * from test_table;",
{{i(1)}, {i(2)}, {i(3)}, {i(4)}, {i(5)}});
sql("alter table test_table set max_rows = 4;");
assertMaxRows(4);
// max_rows should not delete the only fragment in a table
sqlAndCompareResult("select * from test_table;",
{{i(1)}, {i(2)}, {i(3)}, {i(4)}, {i(5)}});
}
TEST_F(AlterTableSetMaxRowsTest, MaxRowsGreaterThanTableRows) {
sql("create table test_table (i integer) with (fragment_size = 2);");
insertRange(1, 5);
sqlAndCompareResult("select * from test_table;",
{{i(1)}, {i(2)}, {i(3)}, {i(4)}, {i(5)}});
sql("alter table test_table set max_rows = 10;");
assertMaxRows(10);
sqlAndCompareResult("select * from test_table;",
{{i(1)}, {i(2)}, {i(3)}, {i(4)}, {i(5)}});
}
TEST_F(AlterTableSetMaxRowsTest, NegativeMaxRows) {
sql("create table test_table (i integer) with (fragment_size = 2);");
insertRange(1, 5);
sqlAndCompareResult("select * from test_table;",
{{i(1)}, {i(2)}, {i(3)}, {i(4)}, {i(5)}});
queryAndAssertException("alter table test_table set max_rows = -1;",
"Max rows cannot be a negative number.");
assertMaxRows(DEFAULT_MAX_ROWS);
sqlAndCompareResult("select * from test_table;",
{{i(1)}, {i(2)}, {i(3)}, {i(4)}, {i(5)}});
}
TEST_F(AlterTableSetMaxRowsTest, EmptyTable) {
sql("create table test_table (i integer);");
sql("alter table test_table set max_rows = 10;");
assertMaxRows(10);
sqlAndCompareResult("select * from test_table;", {});
}
class AlterTableAlterColumnTest : public DBHandlerTestFixture {
protected:
void SetUp() override {
DBHandlerTestFixture::SetUp();
sql("DROP TABLE IF EXISTS test_table;");
sql("DROP TABLE IF EXISTS test_temp_table;");
sql("DROP VIEW IF EXISTS test_view;");
sql("DROP FOREIGN TABLE IF EXISTS test_foreign_table;");
}
void TearDown() override {
sql("DROP TABLE IF EXISTS test_table;");
sql("DROP TABLE IF EXISTS test_temp_table;");
sql("DROP VIEW IF EXISTS test_view;");
sql("DROP FOREIGN TABLE IF EXISTS test_foreign_table;");
DBHandlerTestFixture::TearDown();
}
static void createTestUser() {
sql("CREATE USER test_user (password = 'test_pass');");
sql("GRANT ACCESS ON DATABASE " + shared::kDefaultDbName + " TO test_user;");
}
static void createTextTable(const std::vector<std::string>& column_names,
const std::vector<std::vector<std::string>>& values,
const std::string text_encoding = "ENCODING NONE",
const std::string table_name = "test_table",
const bool treat_null_value_as_string = false,
const std::string options_str = {}) {
std::string table_schema = " index INT";
for (const auto& column_name : column_names) {
if (!table_schema.empty()) {
table_schema += ", ";
}
table_schema += column_name + " TEXT " + text_encoding;
}
if (options_str.empty()) {
sql("CREATE TABLE " + table_name + " (" + table_schema + ");");
} else {
sql("CREATE TABLE " + table_name + " (" + table_schema + ") WITH (" + options_str +
");");
}
if (values.empty()) {
return;
}
std::string data_str{};
int index = 1;
for (const auto& row : values) {
std::string data_row = std::to_string(index++);
for (const auto& value : row) {
if (!data_row.empty()) {
data_row += ", ";
}
if (!treat_null_value_as_string && value == "NULL") {
data_row += value;
} else {
data_row += "'" + value + "'";
}
}
data_row = "(" + data_row + ")";
if (!data_str.empty()) {
data_str += ", ";
}
data_str += data_row;
}
sql("INSERT INTO " + table_name + " VALUES " + data_str + " ;");
}
std::list<const ColumnDescriptor*> getAllColumns(const std::string& table_name) {
auto& catalog = getCatalog();
auto tid = catalog.getTableId(table_name);
CHECK(tid.has_value());
return catalog.getAllColumnMetadataForTable(tid.value(), false, false, false);
}
void compareSchemaToReference(
const std::string& table_name,
const std::vector<std::pair<std::string, std::string>>& reference_schema) {
std::string ref_table_schema;
for (const auto& [column_name, column_type] : reference_schema) {
if (!ref_table_schema.empty()) {
ref_table_schema += ", ";
}
ref_table_schema += column_name + " " + column_type;
}
sql("DROP TABLE IF EXISTS reference_table;");
sql("CREATE TABLE reference_table (" + ref_table_schema + ");");
auto ref_cols = getAllColumns("reference_table");
auto orig_cols = getAllColumns(table_name);
ASSERT_EQ(ref_cols.size(), orig_cols.size());
for (auto rcd : ref_cols) {
auto cdit = std::find_if(
orig_cols.begin(), orig_cols.end(), [&rcd](const ColumnDescriptor* cd) {
return cd->columnName == rcd->columnName;
});
ASSERT_NE(cdit, orig_cols.end());
auto comparison_result =
ddl_utils::alter_column_utils::compare_column_descriptors(*cdit, rcd);
ASSERT_TRUE(comparison_result.sql_types_match);
ASSERT_TRUE(comparison_result.defaults_match);
}
sql("DROP TABLE reference_table;");
}
};
TEST_F(AlterTableAlterColumnTest, InvalidType) {
sql("create table test_table (a integer, b float);");
queryAndAssertException(
"ALTER TABLE test_table ALTER COLUMN a TYPE invalid_type NOT NULL;",
"Type definition for column a is invalid: `invalid_type`");
}
TEST_F(AlterTableAlterColumnTest, ScalarTypes) {
// clang-format off
createTextTable({"b", "t", "s", "i", "bi", "f", "dc", "tm", "tp", "dt", "dict_text"},
{{"True", "100", "30000", "2000000000", "9000000000000000000",
"10.1", "100.1234", "00:00:10", "1/1/2000 00:00:59", "1/1/2000",
"text_1"},
{"False", "110", "30500", "2000500000", "9000000050000000000",
"100.12", "2.1234", "00:10:00", "6/15/2020 00:59:59", "6/15/2020",
"text_2"},
{"True", "120", "31000", "2100000000", "9100000000000000000",
"1000.123", "100.1", "10:00:00", "12/31/2500 23:59:59",
"12/31/2500", "text_3"},
{"NULL", "NULL", "NULL", "NULL", "NULL",
"NULL", "NULL", "NULL", "NULL",
"NULL", "NULL"}} );
// clang-format on
std::string alter_column_command =
"ALTER TABLE test_table"
" ALTER COLUMN b TYPE BOOLEAN"
", ALTER COLUMN t TYPE TINYINT"
", ALTER COLUMN s TYPE SMALLINT"
", ALTER COLUMN i TYPE INT"
", ALTER COLUMN bi TYPE BIGINT"
", ALTER COLUMN f TYPE FLOAT"
", ALTER COLUMN dc TYPE DECIMAL(10,5)"
", ALTER COLUMN tm TYPE TIME"
", ALTER COLUMN tp TYPE TIMESTAMP"
", ALTER COLUMN dt TYPE DATE"
", ALTER COLUMN dict_text TYPE TEXT ENCODING DICT(32);";
sql(alter_column_command);
// clang-format off
auto expected_values = std::vector<std::vector<NullableTargetValue>>{
{1L, True, 100L, 30000L, 2000000000L, 9000000000000000000L, 10.1f, 100.1234,
"00:00:10", "1/1/2000 00:00:59", "1/1/2000", "text_1"},
{2L, False, 110L, 30500L, 2000500000L, 9000000050000000000L, 100.12f,
2.1234, "00:10:00", "6/15/2020 00:59:59", "6/15/2020", "text_2"},
{3L, True, 120L, 31000L, 2100000000L, 9100000000000000000L, 1000.123f,
100.1, "10:00:00", "12/31/2500 23:59:59", "12/31/2500", "text_3"},
{4L, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null}
};
// clang-format on
sqlAndCompareResult("SELECT * FROM test_table ORDER BY index;", expected_values);
auto reference_schema = std::vector<std::pair<std::string, std::string>>{
{"index", "INT"},
{"b", "BOOLEAN"},
{"t", "TINYINT"},
{"s", "SMALLINT"},
{"i", "INT"},
{"bi", "BIGINT"},
{"f", "FLOAT"},
{"dc", "DECIMAL(10,5)"},
{"tm", "TIME"},
{"tp", "TIMESTAMP"},
{"dt", "DATE"},
{"dict_text", "TEXT ENCODING DICT(32)"},
};
compareSchemaToReference("test_table", reference_schema);
}
TEST_F(AlterTableAlterColumnTest, ArrayTypes) {
// clang-format off
createTextTable(
{"b", "t", "s", "i", "bi", "f", "tm", "tp", "dt", "dict_text",
"fixedpoint"},
{{"{True}", "{50, 100}", "{30000, 20000}", "{2000000000}",
"{9000000000000000000}", "{10.1, 11.1}", "{\"00:00:10\"}",
"{\"1/1/2000 00:00:59\", \"1/1/2010 00:00:59\"}",
"{\"1/1/2000\", \"2/2/2000\"}", "{\"text_1\"}", "{1.23,2.34}"},
{"{False, True}", "{110}", "{30500}", "{2000500000}",
"{9000000050000000000}", "{100.12}", "{\"00:10:00\", \"00:20:00\"}",
"{\"6/15/2020 00:59:59\"}", "{\"6/15/2020\"}",
"{\"text_2\", \"text_3\"}", "{3.456,4.5,5.6}"},
{"{True}", "{120}", "{31000}", "{2100000000, 200000000}",
"{9100000000000000000, 9200000000000000000}", "{1000.123}",
"{\"10:00:00\"}", "{\"12/31/2500 23:59:59\"}", "{\"12/31/2500\"}",
"{\"text_4\"}", "{6.78}"},
{"NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL",
"NULL", "NULL"}});
// clang-format on
std::string alter_column_command =
"ALTER TABLE test_table"
" ALTER COLUMN b TYPE BOOLEAN[]"
", ALTER COLUMN t TYPE TINYINT[]"
", ALTER COLUMN s TYPE SMALLINT[]"
", ALTER COLUMN i TYPE INT[]"
", ALTER COLUMN bi TYPE BIGINT[]"
", ALTER COLUMN f TYPE FLOAT[]"
", ALTER COLUMN tm TYPE TIME[]"
", ALTER COLUMN tp TYPE TIMESTAMP[]"
", ALTER COLUMN dt TYPE DATE[]"
", ALTER COLUMN dict_text TYPE TEXT[]"
", ALTER COLUMN fixedpoint TYPE DECIMAL(10,5)[];";
sql(alter_column_command);
// clang-format off
auto expected_values = std::vector<std::vector<NullableTargetValue>>{
{1L, array({True}), array({50L, 100L}), array({30000L, 20000L}),
array({2000000000L}), array({9000000000000000000L}),
array({10.1f, 11.1f}), array({"00:00:10"}),
array({"1/1/2000 00:00:59", "1/1/2010 00:00:59"}),
array({"1/1/2000", "2/2/2000"}), array({"text_1"}), array({1.23, 2.34})},
{2L, array({False, True}), array({110L}), array({30500L}),
array({2000500000L}), array({9000000050000000000L}), array({100.12f}),
array({"00:10:00", "00:20:00"}), array({"6/15/2020 00:59:59"}),
array({"6/15/2020"}), array({"text_2", "text_3"}),
array({3.456, 4.5, 5.6})},
{3L, array({True}), array({120L}), array({31000L}),
array({2100000000L, 200000000L}),
array({9100000000000000000L, 9200000000000000000L}), array({1000.123f}),
array({"10:00:00"}), array({"12/31/2500 23:59:59"}),
array({"12/31/2500"}), array({"text_4"}), array({6.78})},
{4L, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null}};
// clang-format on
sqlAndCompareResult("SELECT * FROM test_table ORDER BY index;", expected_values);
auto reference_schema = std::vector<std::pair<std::string, std::string>>{
{"index", "INT"},
{"b", "BOOLEAN[]"},
{"t", "TINYINT[]"},
{"s", "SMALLINT[]"},
{"i", "INT[]"},
{"bi", "BIGINT[]"},
{"f", "FLOAT[]"},
{"tm", "TIME[]"},
{"tp", "TIMESTAMP[]"},
{"dt", "DATE[]"},
{"dict_text", "TEXT[]"},
{"fixedpoint", "DECIMAL(10,5)[]"},
};
compareSchemaToReference("test_table", reference_schema);
}
TEST_F(AlterTableAlterColumnTest, FixedLengthArrayTypes) {
// clang-format off
createTextTable(
{"b", "t", "s", "i", "bi", "f", "tm", "tp", "dt", "dict_text",
"fixedpoint"},
{{"{True,False}", "{50, 100}", "{30000, 20000}", "{2000000000,-100000}",
"{9000000000000000000,-9000000000000000000}", "{10.1, 11.1}",
"{\"00:00:10\",\"01:00:10\"}",
"{\"1/1/2000 00:00:59\", \"1/1/2010 00:00:59\"}",
"{\"1/1/2000\", \"2/2/2000\"}", "{\"text_1\",\"text_2\"}",
"{1.23,2.34}"},
{"{False, True}", "{110,101}", "{30500,10001}", "{2000500000,-23233}",
"{9000000050000000000,-9200000000000000000}", "{100.12,2.22}",
"{\"00:10:00\", \"00:20:00\"}",
"{\"6/15/2020 00:59:59\",\"8/22/2020 00:00:59\"}",
"{\"6/15/2020\",\"8/22/2020\"}", "{\"text_3\", \"text_4\"}",
"{3.456,4.5}"},
{"{True,True}", "{120,44}", "{31000,8123}", "{2100000000, 200000000}",
"{9100000000000000000, 9200000000000000000}", "{1000.123,1392.22}",
"{\"10:00:00\",\"20:00:00\"}",
"{\"12/31/2500 23:59:59\",\"1/1/2500 23:59:59\"}",
"{\"12/31/2500\",\"1/1/2500\"}", "{\"text_5\",\"text_6\"}",
"{6.78,5.6}"},
{"NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL",
"NULL", "NULL"}});
// clang-format on
std::string alter_column_command =
"ALTER TABLE test_table"
" ALTER COLUMN b TYPE BOOLEAN[2]"
", ALTER COLUMN t TYPE TINYINT[2]"
", ALTER COLUMN s TYPE SMALLINT[2]"
", ALTER COLUMN i TYPE INT[2]"
", ALTER COLUMN bi TYPE BIGINT[2]"
", ALTER COLUMN f TYPE FLOAT[2]"
", ALTER COLUMN tm TYPE TIME[2]"
", ALTER COLUMN tp TYPE TIMESTAMP[2]"
", ALTER COLUMN dt TYPE DATE[2]"
", ALTER COLUMN dict_text TYPE TEXT[2]"
", ALTER COLUMN fixedpoint TYPE DECIMAL(10,5)[2];";
sql(alter_column_command);
// clang-format off
auto expected_values = std::vector<std::vector<NullableTargetValue>>{
{1L, array({True, False}), array({50L, 100L}), array({30000L, 20000L}),
array({2000000000L, -100000L}),
array({9000000000000000000L, -9000000000000000000L}),
array({10.1f, 11.1f}), array({"00:00:10", "01:00:10"}),
array({"1/1/2000 00:00:59", "1/1/2010 00:00:59"}),
array({"1/1/2000", "2/2/2000"}), array({"text_1", "text_2"}),
array({1.23, 2.34})},
{2L, array({False, True}), array({110L, 101L}), array({30500L, 10001L}),
array({2000500000L, -23233L}),
array({9000000050000000000L, -9200000000000000000L}),
array({100.12f, 2.22f}), array({"00:10:00", "00:20:00"}),
array({"6/15/2020 00:59:59", "8/22/2020 00:00:59"}),
array({"6/15/2020", "8/22/2020"}), array({"text_3", "text_4"}),
array({3.456, 4.5})},
{3L, array({True, True}), array({120L, 44L}), array({31000L, 8123L}),
array({2100000000L, 200000000L}),
array({9100000000000000000L, 9200000000000000000L}),
array({1000.123f, 1392.22f}), array({"10:00:00", "20:00:00"}),
array({"12/31/2500 23:59:59", "1/1/2500 23:59:59"}),
array({"12/31/2500", "1/1/2500"}), array({"text_5", "text_6"}),
array({6.78, 5.6})},
{4L, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null}};
// clang-format on
sqlAndCompareResult("SELECT * FROM test_table ORDER BY index;", expected_values);
auto reference_schema = std::vector<std::pair<std::string, std::string>>{
{"index", "INT"},
{"b", "BOOLEAN[2]"},
{"t", "TINYINT[2]"},
{"s", "SMALLINT[2]"},
{"i", "INT[2]"},
{"bi", "BIGINT[2]"},
{"f", "FLOAT[2]"},
{"tm", "TIME[2]"},
{"tp", "TIMESTAMP[2]"},
{"dt", "DATE[2]"},
{"dict_text", "TEXT[2]"},
{"fixedpoint", "DECIMAL(10,5)[2]"},
};
compareSchemaToReference("test_table", reference_schema);
}
TEST_F(AlterTableAlterColumnTest, GeoTypes) {
// clang-format off
createTextTable(
{"p", "mpoint", "l", "mlinestring", "poly", "multipoly"},
{{"POINT (0 0)", "MULTIPOINT (0 0,1 1)", "LINESTRING (0 0,0 0)",
"MULTILINESTRING ((0 0,1 1),(2 2,3 3))", "POLYGON ((0 0,1 0,1 1,0 1,0 0))",
"MULTIPOLYGON (((0 0,1 0,0 1,0 0)))"},
{"NULL", "NULL", "NULL", "NULL", "NULL", "NULL"},
{"POINT (1 1)", "MULTIPOINT (1 1,2 2)", "LINESTRING (1 1,2 2,3 3)",
"MULTILINESTRING ((1 1,2 2),(3 3,4 4))", "POLYGON ((5 4,7 4,6 5,5 4))",
"MULTIPOLYGON (((0 0,1 0,0 1,0 0)),((0 0,2 0,0 2,0 0)))"},
{"POINT (2 2)", "MULTIPOINT (3 4,4 3,0 0)", "LINESTRING (2 2,3 3)", "MULTILINESTRING ((2 2,3 3),(4 4,5 5))", "POLYGON ((1 1,3 1,2 3,1 1))",
"MULTIPOLYGON (((0 0,3 0,0 3,0 0)),((0 0,1 0,0 1,0 0)),((0 0,2 0,0 2,0 "
"0)))"},
{"NULL", "NULL", "NULL", "NULL", "NULL", "NULL"}});
// clang-format on
std::string alter_column_command =
"ALTER TABLE test_table"
" ALTER COLUMN p TYPE POINT"
", ALTER COLUMN mpoint TYPE MULTIPOINT"
", ALTER COLUMN l TYPE LINESTRING"
", ALTER COLUMN mlinestring TYPE MULTILINESTRING"
", ALTER COLUMN poly TYPE POLYGON"
", ALTER COLUMN multipoly TYPE MULTIPOLYGON;";
sql(alter_column_command);
// clang-format off
auto expected_values = std::vector<std::vector<NullableTargetValue>>{
{i(1), "POINT (0 0)", "MULTIPOINT (0 0,1 1)", "LINESTRING (0 0,0 0)", "MULTILINESTRING ((0 0,1 1),(2 2,3 3))",
"POLYGON ((0 0,1 0,1 1,0 1,0 0))", "MULTIPOLYGON (((0 0,1 0,0 1,0 0)))"},
{i(2), Null, Null, Null, Null, Null, Null},
{i(3), "POINT (1 1)", "MULTIPOINT (1 1,2 2)", "LINESTRING (1 1,2 2,3 3)", "MULTILINESTRING ((1 1,2 2),(3 3,4 4))",
"POLYGON ((5 4,7 4,6 5,5 4))",
"MULTIPOLYGON (((0 0,1 0,0 1,0 0)),((0 0,2 0,0 2,0 0)))"},
{i(4), "POINT (2 2)", "MULTIPOINT (3 4,4 3,0 0)", "LINESTRING (2 2,3 3)", "MULTILINESTRING ((2 2,3 3),(4 4,5 5))",
"POLYGON ((1 1,3 1,2 3,1 1))",
"MULTIPOLYGON (((0 0,3 0,0 3,0 0)),((0 0,1 0,0 1,0 0)),((0 0,2 0,0 2,0 "
"0)))"},
{i(5), Null, Null, Null, Null, Null, Null}};
// clang-format on
sqlAndCompareResult("SELECT * FROM test_table ORDER BY index;", expected_values);
auto reference_schema = std::vector<std::pair<std::string, std::string>>{
{"index", "INT"},
{"p", "POINT"},
{"mpoint", "MULTIPOINT"},
{"l", "LINESTRING"},
{"mlinestring", "MULTILINESTRING"},
{"poly", "POLYGON"},
{"multipoly", "MULTIPOLYGON"},
};
compareSchemaToReference("test_table", reference_schema);
}
TEST_F(AlterTableAlterColumnTest, ReencodeDictionaryLowerDepthExceedingSize) {
createTextTable({"d0"}, {}, "ENCODING DICT (32)");
auto num_elements = static_cast<int>(std::numeric_limits<unsigned char>::max()) + 1;
for (int i = 0; i < num_elements; ++i) {
std::string insert_query = "INSERT INTO test_table VALUES (" + std::to_string(i) +
",'text_" + std::to_string(i) + "');";
sql(insert_query);
}
std::string alter_column_command =
"ALTER TABLE test_table"
" ALTER COLUMN d0 TYPE TEXT ENCODING DICT(8);";
queryAndAssertPartialException(
alter_column_command,
"has exceeded it's limit of 8 bits (255 unique values) while attempting to add the "
"new string 'text_255'. To load more data, please re-create the table with this "
"column as type TEXT ENCODING DICT(16) or TEXT ENCODING DICT(32) and reload your "
"data.");
auto expected_values = std::vector<std::vector<NullableTargetValue>>{};
for (int i = 0; i < num_elements; ++i) {
expected_values.push_back({static_cast<int64_t>(i), "text_" + std::to_string(i)});
}
sqlAndCompareResult("SELECT * FROM test_table ORDER BY index;", expected_values);
auto reference_schema = std::vector<std::pair<std::string, std::string>>{
{"index", "INT"}, {"d0", "TEXT ENCODING DICT(32)"}};
compareSchemaToReference("test_table", reference_schema);
}
TEST_F(AlterTableAlterColumnTest, ReencodeDictionaryLowerDepthNotExceedingSize) {
createTextTable({"d0"}, {}, "ENCODING DICT (32)");
auto num_elements = static_cast<int>(std::numeric_limits<unsigned char>::max()) + 1;
for (int i = 0; i < num_elements; ++i) {
std::string insert_query = "INSERT INTO test_table VALUES (" + std::to_string(i) +
",'text_" + std::to_string(i) + "');";
sql(insert_query);
}
sql("DELETE FROM test_table WHERE index = 255;");
std::string alter_column_command =
"ALTER TABLE test_table"
" ALTER COLUMN d0 TYPE TEXT ENCODING DICT(8);";
sql(alter_column_command);
auto expected_values = std::vector<std::vector<NullableTargetValue>>{};
for (int i = 0; i < num_elements - 1; ++i) {
expected_values.push_back({static_cast<int64_t>(i), "text_" + std::to_string(i)});
}
sqlAndCompareResult("SELECT * FROM test_table ORDER BY index;", expected_values);
auto reference_schema = std::vector<std::pair<std::string, std::string>>{
{"index", "INT"}, {"d0", "TEXT ENCODING DICT(8)"}};
compareSchemaToReference("test_table", reference_schema);
}
TEST_F(AlterTableAlterColumnTest, ReencodeDictionaryLowerDepth) {
createTextTable({"d0", "d1"},
{
{"text 11", "text 21"},
{"text 12", "text 22"},
{"text 13", "text 23"},
},
"ENCODING DICT (32)");
std::string alter_column_command =
"ALTER TABLE test_table"
" ALTER COLUMN d0 TYPE TEXT ENCODING DICT(16)"
", ALTER COLUMN d1 TYPE TEXT ENCODING DICT(8);";
sql(alter_column_command);
auto expected_values = std::vector<std::vector<NullableTargetValue>>{{
{1L, "text 11", "text 21"},
{2L, "text 12", "text 22"},
{3L, "text 13", "text 23"},
}};
sqlAndCompareResult("SELECT * FROM test_table ORDER BY index;", expected_values);
auto reference_schema = std::vector<std::pair<std::string, std::string>>{
{"index", "INT"},
{"d0", "TEXT ENCODING DICT(16)"},
{"d1", "TEXT ENCODING DICT(8)"},
};
compareSchemaToReference("test_table", reference_schema);
}
TEST_F(AlterTableAlterColumnTest, ReencodeDictionaryHigherDepth) {
createTextTable({"d0", "d1"},
{
{"text 11", "text 21"},
{"text 12", "text 22"},
{"text 13", "text 23"},
},
"ENCODING DICT (8)");
std::string alter_column_command =
"ALTER TABLE test_table"
" ALTER COLUMN d0 TYPE TEXT ENCODING DICT(16)"
", ALTER COLUMN d1 TYPE TEXT ENCODING DICT(32);";
sql(alter_column_command);
auto expected_values = std::vector<std::vector<NullableTargetValue>>{{
{1L, "text 11", "text 21"},
{2L, "text 12", "text 22"},
{3L, "text 13", "text 23"},
}};
sqlAndCompareResult("SELECT * FROM test_table ORDER BY index;", expected_values);
auto reference_schema = std::vector<std::pair<std::string, std::string>>{
{"index", "INT"},
{"d0", "TEXT ENCODING DICT(16)"},
{"d1", "TEXT ENCODING DICT(32)"},
};
compareSchemaToReference("test_table", reference_schema);