forked from heavyai/heavydb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImportExportTest.cpp
5403 lines (4851 loc) · 205 KB
/
ImportExportTest.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 2017 MapD Technologies, 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 <Tests/TestHelpers.h>
#include <algorithm>
#include <fstream>
#include <limits>
#include <string>
#include <gtest/gtest.h>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/process.hpp>
#include <boost/program_options.hpp>
#include <boost/range/combine.hpp>
#include "Archive/PosixFileArchive.h"
#include "Catalog/Catalog.h"
#ifdef HAVE_AWS_S3
#include "AwsHelpers.h"
#include "DataMgr/OmniSciAwsSdk.h"
#endif // HAVE_AWS_S3
#include "DataMgr/ForeignStorage/RegexFileBufferParser.h"
#include "Geospatial/ColumnNames.h"
#include "Geospatial/GDAL.h"
#include "Geospatial/Types.h"
#include "ImportExport/DelimitedParserUtils.h"
#include "ImportExport/Importer.h"
#include "QueryEngine/ResultSet.h"
#include "Shared/SysDefinitions.h"
#include "Shared/enable_assign_render_groups.h"
#include "Shared/file_path_util.h"
#include "Shared/import_helpers.h"
#include "Shared/misc.h"
#include "Shared/scope.h"
#include "DBHandlerTestHelpers.h"
#include "ThriftHandler/DBHandler.h"
#include "ImportExport/ForeignDataImporter.h"
#include "ImportExport/RasterImporter.h"
#ifndef BASE_PATH
#define BASE_PATH "./tmp"
#endif
using namespace std;
using namespace TestHelpers;
extern bool g_use_date_in_days_default_encoding;
extern bool g_enable_fsi;
extern bool g_enable_s3_fsi;
extern bool g_enable_add_metadata_columns;
extern bool g_enable_legacy_delimited_import;
#ifdef ENABLE_IMPORT_PARQUET
extern bool g_enable_legacy_parquet_import;
#endif
extern bool g_enable_fsi_regex_import;
namespace {
std::string repeat_regex(size_t repeat_count, const std::string& regex) {
std::string repeated_regex;
for (size_t i = 0; i < repeat_count; i++) {
if (!repeated_regex.empty()) {
repeated_regex += "\\s*,\\s*";
}
repeated_regex += regex;
}
return repeated_regex;
}
std::string get_line_regex(size_t column_count) {
return repeat_regex(column_count, "\"?([^,\"]*)\"?");
}
std::string get_line_array_regex(size_t column_count) {
return repeat_regex(column_count, "(\\{[^\\}]+\\}|NULL|)");
}
std::string get_line_geo_regex(size_t column_count) {
return repeat_regex(column_count,
"\"?((?:POINT|LINESTRING|POLYGON|MULTIPOLYGON)[^\"]+|\\\\N)\"?");
}
} // namespace
namespace {
bool g_regenerate_export_test_reference_files = false;
bool g_run_odbc{false};
#define SKIP_ALL_ON_AGGREGATOR() \
if (isDistributedMode()) { \
LOG(ERROR) << "Tests not valid in distributed mode"; \
return; \
}
std::string options_to_string(const std::map<std::string, std::string>& options,
bool seperate = true) {
std::string options_str;
for (auto const& [key, val] : options) {
options_str += (seperate ? "," : "") + key + "='" + val + "'";
seperate = true;
}
return options_str;
}
std::string TypeToString(SQLTypes type) {
return SQLTypeInfo(type, false).get_type_name();
}
void d(const SQLTypes expected_type, const std::string& str) {
auto detected_type = import_export::Detector::detect_sqltype(str);
EXPECT_EQ(TypeToString(expected_type), TypeToString(detected_type))
<< "String: " << str;
}
TEST(Detect, DateTime) {
d(kDATE, "2016-01-02");
d(kDATE, "02/01/2016");
d(kDATE, "01-Feb-16");
d(kDATE, "01/Feb/2016");
d(kDATE, "01/Feb/16");
d(kTIMESTAMP, "2016-01-02T03:04");
d(kTIMESTAMP, "2016-01-02T030405");
d(kTIMESTAMP, "2016-01-02T03:04:05");
d(kTIMESTAMP, "1776-01-02T03:04:05");
d(kTIMESTAMP, "9999-01-02T03:04:05");
d(kTIME, "03:04");
d(kTIME, "03:04:05");
d(kTEXT, "33:04");
}
TEST(Detect, Numeric) {
d(kSMALLINT, "1");
d(kSMALLINT, "12345");
d(kINT, "123456");
d(kINT, "1234567890");
d(kBIGINT, "12345678901");
d(kFLOAT, "1.");
d(kFLOAT, "1.2345678");
// d(kDOUBLE, "1.2345678901");
// d(kDOUBLE, "1.23456789012345678901234567890");
d(kTIME, "1.22.22");
}
class ImportExportTestBase : public DBHandlerTestFixture {
protected:
void SetUp() override { DBHandlerTestFixture::SetUp(); }
void TearDown() override { DBHandlerTestFixture::TearDown(); }
bool compareAgg(const int64_t cnt, const double avg) {
std::string query_str = "SELECT COUNT(*), AVG(trip_distance) FROM trips;";
sqlAndCompareResult(query_str, {{cnt, avg}});
return true;
}
bool importTestCommon(const string& query_str, const int64_t cnt, const double avg) {
sql(query_str);
return compareAgg(cnt, avg);
}
bool importTestLocal(const string& filename,
const int64_t cnt,
const double avg,
const std::map<std::string, std::string>& options = {}) {
return importTestCommon(string("COPY trips FROM '") +
"../../Tests/Import/datafiles/" + filename +
"' WITH (header='true'" +
(filename.find(".parquet") != std::string::npos
? ",source_type='parquet_file'"
: "") +
options_to_string(options) + ");",
cnt,
avg);
}
#ifdef HAVE_AWS_S3
bool importTestS3(const string& prefix,
const string& filename,
const int64_t cnt,
const double avg,
std::map<std::string, std::string> options = {}) {
// unlikely we will expose any credentials in clear text here.
// likely credentials will be passed as the "tester"'s env.
// though s3 sdk should by default access the env, if any,
// we still read them out to test coverage of the code
// that passes credentials on per user basis.
char* env;
std::string s3_region, s3_access_key, s3_secret_key;
if (0 != (env = getenv("AWS_REGION"))) {
s3_region = env;
}
if (0 != (env = getenv("AWS_ACCESS_KEY_ID"))) {
s3_access_key = env;
}
if (0 != (env = getenv("AWS_SECRET_ACCESS_KEY"))) {
s3_secret_key = env;
}
if (s3_region.empty()) {
s3_region = "us-west-1";
}
return importTestCommon(
string("COPY trips FROM '") + "s3://mapd-parquet-testdata/" + prefix + "/" +
filename + "' WITH (header='true'" +
(s3_access_key.size() ? ",s3_access_key='" + s3_access_key + "'" : "") +
(s3_secret_key.size() ? ",s3_secret_key='" + s3_secret_key + "'" : "") +
(s3_region.size() ? ",s3_region='" + s3_region + "'" : "") +
(prefix.find(".parquet") != std::string::npos ||
filename.find(".parquet") != std::string::npos
? ",source_type='parquet_file'"
: "") +
options_to_string(options) + ");",
cnt,
avg);
}
bool importTestS3Compressed(const string& filename,
const int64_t cnt,
const double avg,
const std::map<std::string, std::string>& options = {}) {
return importTestS3("trip.compressed", filename, cnt, avg, options);
}
#endif
};
const char* create_table_trips_to_skip_header = R"(
CREATE TABLE trips (
trip_distance DECIMAL(14,2),
random_string TEXT
);
)";
class ImportTestSkipHeader : public ImportExportTestBase {
protected:
void SetUp() override {
ImportExportTestBase::SetUp();
sql("drop table if exists trips;");
sql(create_table_trips_to_skip_header);
}
void TearDown() override {
sql("drop table trips;");
ImportExportTestBase::TearDown();
}
};
TEST_F(ImportTestSkipHeader, Skip_Header) {
// save existing size and restore it after test so that changing it to a tiny size
// of 10 below for this test won't affect performance of other tests.
const auto archive_read_buf_size_state = g_archive_read_buf_size;
// 10 makes sure that the first block returned by PosixFileArchive::read_data_block
// does not contain the first line delimiter
g_archive_read_buf_size = 10;
ScopeGuard reset_archive_read_buf_size = [&archive_read_buf_size_state] {
g_archive_read_buf_size = archive_read_buf_size_state;
};
EXPECT_TRUE(importTestLocal("skip_header.txt", 1, 1.0));
}
const char* create_table_mixed_varlen = R"(
CREATE TABLE import_test_mixed_varlen(
pt GEOMETRY(POINT),
ls GEOMETRY(LINESTRING),
faii INTEGER[2],
fadc DECIMAL(5,2)[2],
fatx TEXT[] ENCODING DICT(32),
fatx2 TEXT[2] ENCODING DICT(32)
);
)";
class ImportTestMixedVarlen : public ImportExportTestBase {
protected:
void SetUp() override {
ImportExportTestBase::SetUp();
sql("drop table if exists import_test_mixed_varlen;");
sql(create_table_mixed_varlen);
}
void TearDown() override {
sql("drop table if exists import_test_mixed_varlen;");
ImportExportTestBase::TearDown();
}
};
TEST_F(ImportTestMixedVarlen, Fix_failed_import_arrays_after_geos) {
sql("copy import_test_mixed_varlen from "
"'../../Tests/Import/datafiles/mixed_varlen.txt' with "
"(header='false');");
std::string query_str = "SELECT COUNT(*) FROM import_test_mixed_varlen;";
sqlAndCompareResult(query_str, {{2L}});
}
const char* create_table_date = R"(
CREATE TABLE import_test_date(
id INT,
date_text TEXT ENCODING DICT(32),
date_date DATE,
date_date_not_null DATE NOT NULL,
date_i32 DATE ENCODING FIXED(32),
date_i16 DATE ENCODING FIXED(16)
);
)";
std::string convert_date_to_string(int64_t d) {
if (d == std::numeric_limits<int64_t>::min()) {
return std::string("NULL");
}
char buf[16];
size_t const len = shared::formatDate(buf, 16, d);
CHECK_LE(10u, len) << d;
return std::string(buf);
}
class ImportTestDate : public ImportExportTestBase {
protected:
void SetUp() override {
ImportExportTestBase::SetUp();
sql("drop table if exists import_test_date;");
sql(create_table_date);
}
void TearDown() override {
sql("drop table if exists import_test_date;");
ImportExportTestBase::TearDown();
}
void runMixedDatesTest() {
ASSERT_NO_THROW(
sql("COPY import_test_date FROM "
"'../../Tests/Import/datafiles/mixed_dates.txt';"));
TQueryResult result;
sql(result, "SELECT * FROM import_test_date ORDER BY id;");
// clang-format off
assertResultSetEqual(
{
{1L, "2018-12-21", "12/21/2018", "12/21/2018", "12/21/2018", "12/21/2018"},
{2L, "2018-12-21", "12/21/2018", "12/21/2018", "12/21/2018", "12/21/2018"},
{3L, "2018-08-15", "08/15/2018", "08/15/2018", "08/15/2018", "08/15/2018"},
{4L, "2018-08-15", "08/15/2018", "08/15/2018", "08/15/2018", "08/15/2018"},
{5L, "1950-02-14", "02/14/1950", "02/14/1950", "02/14/1950", "02/14/1950"},
{6L, "1960-12-31", "12/31/1960", "12/31/1960", "12/31/1960", "12/31/1960"},
{7L, "1940-05-05", "05/05/1940", "05/05/1940", "05/05/1940", "05/05/1940"},
{8L, "2040-05-05", "05/05/2040", "05/05/2040", "05/05/2040", "05/05/2040"},
{9L, "2000-01-01", "01/01/2000", "01/01/2000", "01/01/2000", "01/01/2000"},
{10L, "2000-12-31", "12/31/2000", "12/31/2000", "12/31/2000", "12/31/2000"},
{11L, Null, Null, "01/01/2000", Null, Null}
}, result);
// clang-format on
}
};
TEST_F(ImportTestDate, ImportMixedDates) {
SKIP_ALL_ON_AGGREGATOR(); // global variable not available on leaf nodes
runMixedDatesTest();
}
class ImportTestInt : public ImportExportTestBase {
protected:
void SetUp() override {
ImportExportTestBase::SetUp();
const char* create_table_date = R"(
CREATE TABLE inttable(
b bigint,
b32 bigint encoding fixed(32),
b16 bigint encoding fixed(16),
b8 bigint encoding fixed(8),
bnn bigint not null,
bnn32 bigint not null encoding fixed(32),
bnn16 bigint not null encoding fixed(16),
bnn8 bigint not null encoding fixed(8),
i int,
i16 int encoding fixed(16),
i8 int encoding fixed(8),
inn int not null,
inn16 int not null encoding fixed(16),
inn8 int not null encoding fixed(8),
s smallint,
s8 smallint encoding fixed(8),
snn smallint not null,
snn8 smallint not null encoding fixed(8),
t tinyint,
tnn tinyint not null
);
)";
sql("drop table if exists inttable;");
sql(create_table_date);
}
void TearDown() override {
sql("drop table if exists inttable;");
ImportExportTestBase::TearDown();
}
};
TEST_F(ImportTestInt, ImportBadInt) {
SKIP_ALL_ON_AGGREGATOR(); // global variable not available on leaf nodes
// this dataset tests that rows outside the allowed valus are rejected
// no rows should be added
ASSERT_NO_THROW(
sql("COPY inttable FROM "
"'../../Tests/Import/datafiles/int_bad_test.txt';"));
sqlAndCompareResult("SELECT * FROM inttable;", {});
};
TEST_F(ImportTestInt, ImportGoodInt) {
SKIP_ALL_ON_AGGREGATOR(); // global variable not available on leaf nodes
// this dataset tests that rows inside the allowed values are accepted
// all rows should be added
ASSERT_NO_THROW(
sql("COPY inttable FROM "
"'../../Tests/Import/datafiles/int_good_test.txt';"));
constexpr long long_min = std::numeric_limits<int64_t>::min();
// clang-format off
sqlAndCompareResult("SELECT * FROM inttable ORDER BY b;",
{
{-9223372036854775807L, 1L,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, 1L, 1L},
{1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 127L, 1L, 1L, 1L, 1L, 1L, 1L},
{1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, -2147483648L, 1L, 1L, 1L, 1L, 1L, 1L, 1L},
{1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 32767L, 1L, 1L, 1L, 1L, 1L, 1L, 1L},
{1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, -2147483648L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L},
{9223372036854775807L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L},
{9223372036854775807L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L},
{9223372036854775807L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L},
{9223372036854775807L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L},
{9223372036854775807L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L},
{9223372036854775807L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L},
{Null, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, -128L}
});
// clang-format on
}
class ImportTestLegacyDate : public ImportTestDate {
protected:
void SetUp() override {
ImportTestDate::SetUp();
sql("drop table if exists import_test_date;");
g_use_date_in_days_default_encoding = false;
sql(create_table_date);
}
void TearDown() override {
sql("drop table if exists import_test_date;");
g_use_date_in_days_default_encoding = true;
ImportTestDate::TearDown();
}
};
TEST_F(ImportTestLegacyDate, ImportMixedDates) {
SKIP_ALL_ON_AGGREGATOR(); // global variable not available on leaf nodes
runMixedDatesTest();
}
const char* create_table_date_arr = R"(
CREATE TABLE import_test_date_arr(
id INT,
date_date DATE[],
date_date_fixed DATE[2],
date_date_not_null DATE[] NOT NULL
);
)";
class ImportTestDateArray : public ImportExportTestBase {
protected:
void SetUp() override {
ImportExportTestBase::SetUp();
sql("drop table if exists import_test_date_arr;");
sql(create_table_date_arr);
}
void TearDown() override {
sql("drop table if exists import_test_date_arr;");
ImportExportTestBase::TearDown();
}
void compareDateAndTruthArray(
const std::vector<std::optional<int64_t>>& date_array,
const std::vector<std::optional<std::string>>& truth_array) const {
const auto array_size =
std::min(date_array.size(),
truth_array.size()); // compare only elements that should match
for (size_t i = 0; i < array_size; ++i) {
ASSERT_TRUE((date_array[i].has_value() && truth_array[i].has_value()) ||
(!date_array[i].has_value() && !truth_array[i].has_value()))
<< " mismatch between expected and observed arrays: one is null and the other "
"is not";
if (date_array[i] && truth_array[i]) {
const auto date_str = convert_date_to_string(*date_array[i]);
ASSERT_EQ(date_str, truth_array[i]);
}
}
}
};
TEST_F(ImportTestDateArray, ImportMixedDateArrays) {
ASSERT_NO_THROW(
sql("COPY import_test_date_arr FROM "
"'../../Tests/Import/datafiles/mixed_date_arrays.txt';"));
// clang-format off
sqlAndCompareResult("SELECT * FROM import_test_date_arr ORDER BY id;",
{
{1L, array({"2018-12-21","2018-12-21"}), array({"12/21/2018","12/21/2018"}), array({"12/21/2018","12/21/2018"})},
{2L, array({"2018-12-21","2018-08-15"}), array({"12/21/2018","08/15/2018"}), array({"12/21/2018","08/15/2018"})},
{3L, array({"2018-12-21","1960-12-31","2018-12-21"}), array({"12/21/2018","12/31/1960"}), array({"12/21/2018","12/31/1960","12/21/2018"})},
{4L, array({"2018-12-21",NULL_BIGINT}), array({"12/21/2018",NULL_BIGINT}), array({"12/21/2018","12/21/2018"})},
{5L, array({NULL_BIGINT,"2018-12-21"}), array({NULL_BIGINT,"12/21/2018"}), array({"12/21/2018","12/21/2018"})},
{6L, array({"2018-12-21",NULL_BIGINT}), array({"12/21/2018",NULL_BIGINT}), array({"12/21/2018","12/21/2018"})},
{8L, Null, Null, array({"12/21/2018","12/21/2018"})},
{9L, Null, Null, array({"12/21/2018","12/21/2018"})},
{10L, Null, Null, array({"12/21/2018","12/21/2018"})},
{11L, {}, array({NULL_BIGINT,NULL_BIGINT}), array({"12/21/2018","12/21/2018"})}
});
// clang-format on
}
class FsiImportTest {
public:
static void setupS3() {
#ifdef HAVE_AWS_S3
omnisci_aws_sdk::init_sdk();
g_allow_s3_server_privileges = true;
#endif
}
static void teardownS3() {
#ifdef HAVE_AWS_S3
omnisci_aws_sdk::shutdown_sdk();
g_allow_s3_server_privileges = false;
#endif
}
protected:
void enableAllFsiImportCodePaths() {
std::swap(g_enable_fsi, stored_g_enable_fsi_);
std::swap(g_enable_s3_fsi, stored_g_enable_s3_fsi_);
std::swap(g_enable_legacy_delimited_import, stored_g_enable_legacy_delimited_import_);
#ifdef ENABLE_IMPORT_PARQUET
std::swap(g_enable_legacy_parquet_import, stored_g_enable_legacy_parquet_import_);
#endif
std::swap(g_enable_fsi_regex_import, stored_g_enable_fsi_regex_import_);
}
void restoreAllImportCodePaths() {
std::swap(g_enable_legacy_delimited_import, stored_g_enable_legacy_delimited_import_);
#ifdef ENABLE_IMPORT_PARQUET
std::swap(g_enable_legacy_parquet_import, stored_g_enable_legacy_parquet_import_);
#endif
std::swap(g_enable_fsi_regex_import, stored_g_enable_fsi_regex_import_);
std::swap(g_enable_s3_fsi, stored_g_enable_s3_fsi_);
std::swap(g_enable_fsi, stored_g_enable_fsi_);
}
bool stored_g_enable_fsi_ = true;
bool stored_g_enable_s3_fsi_ = true;
bool stored_g_enable_legacy_delimited_import_ = false;
#ifdef ENABLE_IMPORT_PARQUET
bool stored_g_enable_legacy_parquet_import_ = false;
#endif
bool stored_g_enable_fsi_regex_import_ = true;
};
class ImportConfigurationErrorHandling : public ImportExportTestBase,
public FsiImportTest {
protected:
void SetUp() override {
enableAllFsiImportCodePaths();
ImportExportTestBase::SetUp();
ASSERT_NO_THROW(sql("DROP TABLE IF EXISTS test_table;"));
sql("CREATE TABLE test_table (t int);");
}
void TearDown() override {
ASSERT_NO_THROW(sql("DROP TABLE IF EXISTS test_table;"));
ImportExportTestBase::TearDown();
restoreAllImportCodePaths();
}
const std::string fsi_file_base_dir_ = "../../Tests/FsiDataFiles/";
};
class RegexParserImportConfigurationErrorHandling
: public ImportConfigurationErrorHandling {};
TEST_F(RegexParserImportConfigurationErrorHandling, NoLineRegex) {
queryAndAssertException("COPY test_table from '" + fsi_file_base_dir_ +
"/example_2.csv' WITH "
"(source_type='regex_parsed_file');",
"Regex parser options must contain a line regex.");
}
using CodePath = std::string;
using ErrorColumnType = std::string;
using ImportType = std::string;
using DataSourceType = std::string;
using FragmentSize = int32_t;
using MaxChunkSize = int32_t;
namespace {
void validate_import_status(const std::string& import_id,
const TImportStatus& thrift_import_status,
const std::string& copy_from_result,
const size_t rows_completed,
const size_t rows_rejected,
const bool failed_status) {
// Verify the string result set returend by COPY FROM
std::string expected_copy_from_result =
"Loaded: " + std::to_string(rows_completed) +
" recs, Rejected: " + std::to_string(rows_rejected) + " recs";
if (failed_status) {
expected_copy_from_result =
"Loader Failed due to : Load was cancelled due to max reject rows being "
"reached";
}
ASSERT_EQ(expected_copy_from_result,
copy_from_result.substr(0, expected_copy_from_result.size()));
auto import_status = import_export::Importer::get_import_status(import_id);
// ensure thrift import status matches expected values
ASSERT_EQ(import_status.rows_completed,
static_cast<size_t>(thrift_import_status.rows_completed));
ASSERT_EQ(import_status.rows_rejected,
static_cast<size_t>(thrift_import_status.rows_rejected));
if (failed_status) { // if expecting a failed status, only check this condition as
// number of rows completed could be indeterministic
ASSERT_EQ(failed_status, import_status.load_failed)
<< " incorrect load_failed flag in import status";
ASSERT_EQ(import_status.load_msg,
"Load was cancelled due to max reject rows being reached");
return;
}
ASSERT_EQ(rows_completed, import_status.rows_completed)
<< " incorrect rows completed in import status";
ASSERT_EQ(rows_rejected, import_status.rows_rejected)
<< " incorrect rows rejected in import status";
ASSERT_EQ(failed_status, import_status.load_failed)
<< " incorrect load_failed flag in import status";
}
std::string get_copy_from_result_str(const TQueryResult& copy_from_query_result) {
std::string copy_from_result_str;
auto row_set = copy_from_query_result.row_set;
CHECK(row_set.is_columnar);
CHECK_EQ(row_set.columns.size(), 1UL);
auto& str_col = row_set.columns[0].data.str_col;
CHECK_EQ(str_col.size(), 1UL);
copy_from_result_str = str_col[0];
return copy_from_result_str;
}
} // namespace
#ifdef ENABLE_IMPORT_PARQUET
class ParquetImportErrorHandling : public ImportExportTestBase, public FsiImportTest {
protected:
void SetUp() override {
enableAllFsiImportCodePaths();
ImportExportTestBase::SetUp();
ASSERT_NO_THROW(sql("DROP TABLE IF EXISTS test_table;"));
}
void TearDown() override {
ASSERT_NO_THROW(sql("DROP TABLE IF EXISTS test_table;"));
ImportExportTestBase::TearDown();
restoreAllImportCodePaths();
}
TImportStatus getImportStatus(const std::string& import_id) {
return DBHandlerTestFixture::getImportStatus(import_id);
}
void validateImportStatus(const std::string& import_id,
const std::string& copy_from_result,
const size_t rows_completed,
const size_t rows_rejected,
const bool failed_status) {
validate_import_status(import_id,
getImportStatus(import_id),
copy_from_result,
rows_completed,
rows_rejected,
failed_status);
}
const std::string fsi_file_base_dir = "../../Tests/FsiDataFiles/";
};
class ParquetImportErrorHandlingOfTypes
: public ParquetImportErrorHandling,
public ::testing::WithParamInterface<ErrorColumnType> {};
TEST_F(ParquetImportErrorHandling, GreaterThanMaxReject) {
// TODO: this test is redundant with max_reject test below can probably remove in the
// future
sql("CREATE TABLE test_table (id INT, i INT, p POINT, a INT[], t TEXT, ts TIMESTAMP "
"(0) ENCODING FIXED(32), days DATE ENCODING DAYS(16), ts2days DATE ENCODING DAYS "
"(16) );");
TQueryResult copy_from_result;
const std::string file_path = fsi_file_base_dir + "/invalid_parquet/";
sql(copy_from_result,
"COPY test_table FROM '" + file_path +
"' WITH (source_type='parquet_file', max_reject=6);");
TQueryResult query;
sql(query, "SELECT count(*) FROM test_table;");
assertResultSetEqual({{0L}}, query); // confirm no data was loaded into table
validateImportStatus(file_path, get_copy_from_result_str(copy_from_result), 0, 0, true);
}
TEST_F(ParquetImportErrorHandling, MismatchNumberOfColumns) {
sql("CREATE TABLE test_table (i INT);");
queryAndAssertException(
"COPY test_table FROM '" + fsi_file_base_dir +
"/two_col_1_2.parquet' WITH (source_type='parquet_file');",
"Mismatched number of logical columns: (expected 1 columns, has 2): in file "
"'../../Tests/FsiDataFiles/two_col_1_2.parquet'");
}
TEST_F(ParquetImportErrorHandling, MismatchColumnType) {
sql("CREATE TABLE test_table (i INT, t TEXT);");
queryAndAssertException(
"COPY test_table FROM '" + fsi_file_base_dir +
"/two_col_1_2.parquet' WITH (source_type='parquet_file');",
"Conversion from Parquet type \"INT64\" to OmniSci type \"TEXT\" is not allowed. "
"Please use an appropriate column type. Parquet column: col2, OmniSci column: t, "
"Parquet file: ../../Tests/FsiDataFiles/two_col_1_2.parquet.");
}
INSTANTIATE_TEST_SUITE_P(ColumnType,
ParquetImportErrorHandlingOfTypes,
::testing::Values("int",
"geo",
"array",
"text",
"timestamp",
"date",
"timestamp2date"),
[](const auto& param_info) { return param_info.param; });
TEST_P(ParquetImportErrorHandlingOfTypes, OneInvalidType) {
sql("CREATE TABLE test_table (id INT, i INT, p POINT, a INT[], t TEXT, ts TIMESTAMP "
"(0) ENCODING FIXED(32), days DATE ENCODING DAYS(16), ts2days DATE ENCODING DAYS "
"(16) );");
TQueryResult copy_from_result;
const std::string filename =
fsi_file_base_dir + "/invalid_parquet/one_invalid_row_" + GetParam() + ".parquet";
sql(copy_from_result,
"COPY test_table FROM '" + filename + "' WITH (source_type='parquet_file');");
validateImportStatus(filename, get_copy_from_result_str(copy_from_result), 3, 1, false);
TQueryResult query;
sql(query, "SELECT * FROM test_table ORDER BY id;");
// clang-format off
assertResultSetEqual({
{1L, 100L, "POINT (0 0)", array({1L, 2L}), "a",
"1901-12-13 20:45:53", "1880-04-15", "1901-12-13"},
{2L, 200L, "POINT (1 0)", array({3L, 4L}), "b",
"2038-01-19 03:14:07", "2059-09-18", "2038-01-19"},
{4L, 400L, "POINT (2 2)", array({8L, 9L}), "d",
"1911-12-13 20:45:53", "2020-04-15", "1911-12-13"}},
query);
// clang-format on
}
#endif
using ImportAndSelectTestParameters =
std::tuple<ImportType, DataSourceType, FragmentSize, MaxChunkSize>;
class ImportAndSelectTest
: public ImportExportTestBase,
public ::testing::WithParamInterface<ImportAndSelectTestParameters>,
public FsiImportTest {
protected:
struct Param {
std::string import_type, data_source_type;
int32_t fragment_size;
int32_t num_elements_per_chunk;
};
Param param_;
std::string import_id_;
std::string copy_from_result_;
static bool isOdbc(const std::string& import_type) {
return (import_type == "sqlite" || import_type == "postgres");
}
static void createODBCSourceTable(const std::string& table_name,
const std::string& table_schema,
const std::string& src_file,
const std::string& import_type,
const bool is_odbc_geo = false) {}
static void SetUpTestSuite() {
FsiImportTest::setupS3();
ImportExportTestBase::SetUpTestSuite();
}
static void TearDownTestSuite() {
ImportExportTestBase::TearDownTestSuite();
FsiImportTest::teardownS3();
}
void SetUp() override {
std::tie(param_.import_type,
param_.data_source_type,
param_.fragment_size,
param_.num_elements_per_chunk) = GetParam();
enableAllFsiImportCodePaths();
ImportExportTestBase::SetUp();
ASSERT_NO_THROW(sql("DROP TABLE IF EXISTS import_test_new;"));
}
void TearDown() override {
ASSERT_NO_THROW(sql("DROP TABLE IF EXISTS import_test_new;"));
ImportExportTestBase::TearDown();
restoreAllImportCodePaths();
}
#ifdef HAVE_AWS_S3
// Have necessary credentials to access private buckets
bool insufficientPrivateCredentials() const {
return !is_valid_aws_key(get_aws_keys_from_env());
}
#endif
bool testShouldBeSkipped() {
if (!g_run_odbc && isOdbc(param_.import_type)) {
return true;
}
if (param_.data_source_type != "local" &&
isOdbc(param_.import_type)) { // ODBC tests only support populating tables from
// local files
return true;
}
if (param_.data_source_type == "s3_private") {
#ifdef HAVE_AWS_S3
return insufficientPrivateCredentials();
#else
return true;
#endif
}
return false;
}
std::string applyOdbcSchemaModifications(const std::string& in_schema) {
std::string schema = in_schema;
if (param_.import_type ==
"postgres") { // postgres has no TINYINT type, map all occurences to SMALLINT
schema = boost::regex_replace(schema, boost::regex{"TINYINT"}, "SMALLINT");
}
if (param_.import_type ==
"sqlite") { // sqlite ODBC driver does not support FLOAT, map to DOUBLE
schema = boost::regex_replace(schema, boost::regex{"FLOAT"}, "DOUBLE");
}
if (param_.import_type ==
"sqlite") { // sqlite ODBC driver does not support DECIMAL, map to DOUBLE
schema =
boost::regex_replace(schema, boost::regex{"DECIMAL\\(\\d+,\\d+\\)"}, "DOUBLE");
}
return schema;
}
TImportStatus getImportStatus() {
return DBHandlerTestFixture::getImportStatus(import_id_);
}
void validateImportStatus(const size_t rows_completed,
const size_t rows_rejected,
const bool failed_status) {
validate_import_status(import_id_,
getImportStatus(),
copy_from_result_,
rows_completed,
rows_rejected,
failed_status);
}
TQueryResult createTableCopyFromAndSelect(
const std::string& in_schema,
const std::string& file_name_base,
const std::string& select_query,
const std::string& line_regex,
const std::string& odbc_select,
const int64_t max_byte_size_per_element,
const std::string& table_options = {},
const bool is_dir = false,
const bool is_odbc_geo = false,
const std::optional<int64_t> max_reject = std::nullopt) {
auto& import_type = param_.import_type;
auto& data_source_type = param_.data_source_type;
auto& fragment_size = param_.fragment_size;
auto& num_elements_per_chunk = param_.num_elements_per_chunk;
int64_t max_chunk_size = num_elements_per_chunk * max_byte_size_per_element;
auto schema = applyOdbcSchemaModifications(in_schema);
std::string query = "CREATE TABLE import_test_new (" + schema + ")";
std::string query_table_options = "fragment_size=" + std::to_string(fragment_size) +
",max_chunk_size=" + std::to_string(max_chunk_size);