-
Notifications
You must be signed in to change notification settings - Fork 0
/
tabular.cpp
749 lines (673 loc) · 28.8 KB
/
tabular.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
#include <chrono>
#include <cstring>
#include <iostream>
#include <random>
#include <sstream>
#include <string>
#include <categorical_model.h>
#include <compression.h>
#include <decompression.h>
// #include <markov_model.h>
#include <csignal>
#include <model.h>
#include <numerical_model.h>
#include <string_model.h>
#include <unistd.h>
class SimpleCategoricalInterpreter : public db_compress::AttrInterpreter {
private:
int cap_;
public:
explicit SimpleCategoricalInterpreter(int cap) : cap_(cap) {}
bool EnumInterpretable() const override { return true; }
int EnumCap() const override { return cap_; }
size_t EnumInterpret(const db_compress::AttrValue &attr) const override {
return attr.Int();
}
};
enum {
COMPRESS, DECOMPRESS, BENCHMARK, RANDOM_ACCESS
} mode;
// ---------------------------- Global Variables -----------------------------
char input_file_name[100], output_file_name[100], config_file_name[100];
db_compress::Schema schema;
std::vector<db_compress::AttrVector> datasets;
db_compress::CompressionConfig config;
std::vector<db_compress::BiMap> enum_map;
// ----------------------------- Setting ---------------------------------
char delimiter = ',';
bool skip_learning = true;
int block_size = 20000;
// -------------------------- Helper Functions ---------------------------
int EnumTranslate(const std::string &str, int attr) {
db_compress::BiMap &map = enum_map[attr];
auto &enum2idx = map.enum2idx;
auto &enums = map.enums;
auto it = enum2idx.find(str);
if (it != enum2idx.end())
return it->second;
else {
enum2idx[str] = enums.size();
enums.push_back(str);
return enums.size() - 1;
}
}
std::ifstream::pos_type filesize(const char *filename) {
std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary);
return in.tellg();
}
void PrintHelpInfo() {
std::cout << "Compression How To:\n\n";
std::cout << "./tabular_blitzcrank [mode] [dataset] [config] [if use \"|\" as delimiter] [if skip learning] [block size]\n\n";
std::cout << " [mode]: -c for compression, -d for decompression, -b for benchmarking\n";
std::cout << " [dataset]: path to the dataset\n";
std::cout << " [config]: path to the config file\n";
std::cout << " [if use \"|\" as delimiter]: 0 for comma, 1 for \"|\"\n";
std::cout << " [if skip learning]: 0 for learning, 1 for skipping learning\n";
std::cout << " [block size]: block size for compression\n";
}
// Read input_file_name, output_file_name, config_file_name and whether to
// compress or decompress.csv. Return false if failed to recognize params.
bool ReadParameter(int argc, char **argv) {
// mode, input_file_name, output_file_name, config_file_name, tuple_idx_,
// decompress_num start tuple and decompress_num are for random
// decompression
if (strcmp(argv[1], "-c") == 0) {
mode = COMPRESS;
} else if (strcmp(argv[1], "-d") == 0) {
mode = DECOMPRESS;
} else if (strcmp(argv[1], "-b") == 0) {
mode = BENCHMARK;
} else if (strcmp(argv[1], "-ra") == 0) {
mode = RANDOM_ACCESS;
} else {
return false;
}
switch (mode) {
case COMPRESS: {
if (argc < 5)
return false;
strcpy(input_file_name, argv[2]);
strcpy(output_file_name, argv[3]);
strcpy(config_file_name, argv[4]);
int special_del = std::stoi(argv[5]);
if (special_del == 1)
delimiter = '|';
skip_learning = std::stoi(argv[6]);
block_size = std::stoi(argv[7]);
std::cout << "Delimiter: " << delimiter << "\t"
<< "Skip Learning: " << skip_learning << "\t"
<< "Block Size: " << block_size << "\t" << std::endl;
}
break;
case DECOMPRESS: {
if (argc < 5)
return false;
strcpy(input_file_name, argv[2]);
strcpy(output_file_name, argv[3]);
strcpy(config_file_name, argv[4]);
int special_del = std::stoi(argv[5]);
if (special_del == 1)
delimiter = '|';
block_size = std::stoi(argv[6]);
std::cout << "Delimiter: " << delimiter << "\t"
<< "Block Size: " << block_size << "\t" << std::endl;
}
break;
case BENCHMARK: {
if (argc < 4)
return false;
strcpy(input_file_name, argv[2]);
std::string com = std::to_string(getpid()) + "_file.com";
strcpy(output_file_name, com.c_str());
strcpy(config_file_name, argv[3]);
if (argc == 7) {
int special_del = std::stoi(argv[4]);
if (special_del == 1)
delimiter = '|';
skip_learning = std::stoi(argv[5]);
block_size = std::stoi(argv[6]);
}
std::cout << "Delimiter: " << delimiter << "\t"
<< "Skip Learning: " << skip_learning << "\t"
<< "Block Size: " << block_size << "\t" << std::endl;
break;
}
case RANDOM_ACCESS: {
if (argc < 4)
return false;
strcpy(input_file_name, argv[2]);
strcpy(config_file_name, argv[3]);
std::string com = std::to_string(getpid()) + "_file.com";
strcpy(output_file_name, com.c_str());
int special_del = std::stoi(argv[4]);
if (special_del == 1)
delimiter = '|';
skip_learning = std::stoi(argv[5]);
block_size = std::stoi(argv[6]);
std::cout << "Delimiter: " << delimiter << "\t"
<< "Skip Learning: " << skip_learning << "\t"
<< "Block Size: " << block_size << "\t" << std::endl;
}
break;
}
return true;
}
void LoadConfig(char *configFileName_) {
std::ifstream fin(configFileName_);
if (!fin.is_open()) {
std::cout << "Cannot open config file " << configFileName_ << std::endl;
exit(1);
}
std::string str;
std::vector<double> err;
std::vector<int> attr_type;
while (std::getline(fin, str)) {
if (str.back() == '\r')
str.pop_back();
std::vector<std::string> vec;
std::string item;
std::stringstream sstream(str);
while (std::getline(sstream, item, ' ')) {
vec.push_back(item);
}
int index = static_cast<int>(attr_type.size());
if (vec[0] == "ENUM") {
if (vec.size() != 3) {
std::cerr << "ENUM config error." << std::endl;
exit(1);
}
RegisterAttrInterpreter(
index, new SimpleCategoricalInterpreter(std::stoi(vec[1])));
err.push_back(std::stod(vec[2]));
attr_type.push_back(0);
} else if (vec[0] == "ENUM-MARKOV") {
if (vec.size() != 2) {
std::cerr << "ENUM-MARKOV config error." << std::endl;
exit(1);
}
RegisterAttrInterpreter(
index, new SimpleCategoricalInterpreter(std::stoi(vec[1])));
err.push_back(std::stod(vec[1]));
attr_type.push_back(5);
} else if (vec[0] == "INTEGER") {
if (vec.size() != 2) {
std::cerr << "INTEGER config error." << std::endl;
exit(1);
}
RegisterAttrInterpreter(index, new db_compress::AttrInterpreter());
err.push_back(std::stod(vec[1]));
attr_type.push_back(1);
} else if (vec[0] == "DOUBLE") {
if (vec.size() != 2) {
std::cerr << "DOUBLE config error." << std::endl;
exit(1);
}
RegisterAttrInterpreter(index, new db_compress::AttrInterpreter());
err.push_back(std::stod(vec[1]));
attr_type.push_back(2);
} else if (vec[0] == "STRING") {
if (vec.size() != 1) {
std::cerr << "STRING config error." << std::endl;
exit(1);
}
RegisterAttrInterpreter(index, new db_compress::AttrInterpreter());
err.push_back(0);
attr_type.push_back(3);
} else if (vec[0] == "TIMESERIES") {
if (vec.size() != 2) {
std::cerr << "TIMESERIES config error." << std::endl;
exit(1);
}
RegisterAttrInterpreter(index, new db_compress::AttrInterpreter());
err.push_back(std::stod(vec[1]));
attr_type.push_back(4);
} else {
std::cerr << "Config File Error!\n";
}
}
// Register attributed model and interpreter
RegisterAttrModel(0, new db_compress::TableCategoricalCreator());
RegisterAttrModel(1, new db_compress::TableNumericalIntCreator());
RegisterAttrModel(2, new db_compress::TableNumericalRealCreator());
RegisterAttrModel(3, new db_compress::StringModelCreator());
// RegisterAttrModel(5, new db_compress::TableMarkovCreator());
// RegisterAttrModel(4, new db_compress::TableTimeSeriesCreator());
if (attr_type.empty()) {
std::cerr << "Config File Error!\n";
}
schema = db_compress::Schema(attr_type);
config.allowed_err_ = err;
config.skip_model_learning_ = skip_learning;
enum_map.resize(attr_type.size());
}
inline void AppendAttr(db_compress::AttrVector *tuple, const std::string &str,
int attr_type_local, int index) {
try {
switch (attr_type_local) {
case 0:
tuple->attr_[index].value_ = (EnumTranslate(str, index));
break;
case 1:
tuple->attr_[index].value_ = (std::stoi(str));
break;
case 2:
tuple->attr_[index].value_ = (std::stod(str));
break;
case 3:
tuple->attr_[index].value_ = (str);
break;
case 4:
tuple->attr_[index].value_ = (std::stod(str));
case 5:
tuple->attr_[index].value_ = (std::stoi(str));
break;
default:
break;
}
} catch (std::exception &e) {
std::cerr << "Error: " << e.what() << "\tCol: " << index
<< "\tValue: " << str << std::endl;
exit(1);
}
}
inline void ExtractAttr(const db_compress::AttrVector &tuple,
int attr_type_local, int index, std::string &ret) {
const db_compress::AttrValue attr = tuple.attr_[index];
switch (attr_type_local) {
case 0:
ret = enum_map[index].enums[attr.Int()];
break;
case 1:
ret = std::to_string(attr.Int());
break;
case 2:
ret = std::to_string(attr.Double());
break;
case 3:
ret = attr.String();
break;
case 4:
ret = std::to_string(attr.Double());
break;
case 5:
ret = std::to_string(attr.Int());
break;
default:
break;
}
}
int LoadDataSet() {
std::ios::sync_with_stdio(false);
std::cout << "Start load data into memory..." << std::endl;
db_compress::AttrVector tuple(schema.size());
std::ifstream in_file(input_file_name);
if (!in_file.is_open()) {
std::cout << "Cannot open input file " << input_file_name << std::endl;
exit(1);
}
std::string str;
while (std::getline(in_file, str)) {
// empty line should be ignored
if (str.empty()) {
std::cerr << "File is empty.\n";
continue;
}
if (str.back() == '\r')
str.pop_back();
int count = 0;
std::string item;
std::stringstream sstream(str);
while (std::getline(sstream, item, delimiter)) {
if (delimiter == ',') {
if (item.size() > 0 && item[0] == '"') {
item = item.substr(1);
item += ',';
std::string item2;
if (std::getline(sstream, item2, '"'))
item += item2;
std::getline(sstream, item2, delimiter);
}
}
AppendAttr(&tuple, item, schema.attr_type_[count], count);
++count;
}
// The last item might be empty string
if (str[str.length() - 1] == delimiter) {
AppendAttr(&tuple, "", schema.attr_type_[count], count);
++count;
}
if (count != schema.size()) {
std::string ret =
"File Format Error! Got: " + std::to_string(count) + " Wanted: " + std::to_string(schema.size()) +
"\n";
ret += str + "\n";
throw std::runtime_error(ret);
}
datasets.push_back(tuple);
// std::cout << "Load " << datasets.size() << " tuples\n";
}
// write down enum attrs.
db_compress::Write(enum_map);
std::cout << "Data loaded.\n";
return datasets.size();
}
int main(int argc, char **argv) {
if (argc == 1) {
PrintHelpInfo();
} else {
if (!ReadParameter(argc, argv)) {
std::cerr << "Bad Parameters.\n";
return 1;
}
std::ios::sync_with_stdio(false);
LoadConfig(config_file_name);
switch (mode) {
case COMPRESS: {
db_compress::RelationCompressor compressor(output_file_name, schema,
config, block_size);
int num_total_tuples = LoadDataSet();
int iter_cnt = 0;
// random number
std::random_device random_device;
std::mt19937 mt19937(0);
std::uniform_int_distribution<uint32_t> dist(0, num_total_tuples - 1);
bool tuning = false;
// Learning Iterations
while (true) {
std::cout << "Iteration " << ++iter_cnt << " Starts\n";
int tuple_cnt = 0;
int tuple_random_cnt = 0;
int tuple_idx;
while (tuple_cnt < num_total_tuples) {
if (tuple_random_cnt < kNumEstSample) {
tuple_idx = static_cast<int>(dist(mt19937));
tuple_random_cnt++;
} else {
tuple_idx = tuple_cnt;
tuple_cnt++;
}
db_compress::AttrVector &tuple = datasets[tuple_idx];
{ compressor.LearnTuple(tuple); }
if (tuple_cnt >= kNonFullPassStopPoint &&
!compressor.RequireFullPass()) {
break;
}
}
compressor.EndOfLearning();
if (!tuning && compressor.RequireFullPass()) {
tuning = true;
}
if (!compressor.RequireMoreIterationsForLearning()) {
break;
}
}
// Compression iteration
// std::cout << "Compression Iteration " << ++iter_cnt << " Starts\n";
for (int i = 0; i < num_total_tuples; ++i) {
db_compress::AttrVector &tuple = datasets[i];
compressor.CompressTuple(tuple);
}
compressor.EndOfCompress();
std::cout << "Compressed Size: " << filesize(output_file_name) << "\n";
// std::string index_file_name = std::to_string(getpid()) + "_temp.index";
// std::string enum_file_name = std::to_string(getpid()) + "_enum.dat";
// remove(index_file_name.c_str());
// remove(enum_file_name.c_str());
}
break;
case DECOMPRESS: {
// Load enum values
db_compress::Read(enum_map);
// Decompress
db_compress::RelationDecompressor decompressor(input_file_name, schema,
block_size);
std::ofstream out_file(output_file_name);
std::string str;
decompressor.Init();
db_compress::AttrVector tuple(static_cast<int>(schema.size()));
while (decompressor.HasNext()) {
decompressor.ReadNextTuple(&tuple);
// Write record into file.
for (size_t i = 0; i < schema.size(); ++i) {
ExtractAttr(tuple, schema.attr_type_[i], static_cast<int>(i), str);
bool has_del = false;
for (size_t j = 0; j < str.size(); ++j) {
if (str[j] == ',') {
out_file << '\"';
has_del = true;
break;
}
}
out_file << str;
if (has_del)
out_file << '\"';
out_file << (i == schema.size() - 1 ? '\n' : delimiter);
}
}
out_file.close();
}
break;
case BENCHMARK: {
int origin_size = filesize(input_file_name);
{
// Compress
std::cout << "[Compression]\t";
db_compress::RelationCompressor compressor(output_file_name, schema,
config, block_size);
int num_total_tuples = LoadDataSet();
// random number
std::random_device random_device;
std::mt19937 mt19937(0);
std::uniform_int_distribution<uint32_t> dist(0, num_total_tuples - 1);
bool tuning = false;
// Learning Iterations
while (true) {
int tuple_cnt = 0;
int tuple_random_cnt = 0;
int tuple_idx;
while (tuple_cnt < num_total_tuples) {
if (tuple_random_cnt < kNumEstSample) {
tuple_idx = static_cast<int>(dist(mt19937));
tuple_random_cnt++;
} else {
tuple_idx = tuple_cnt;
tuple_cnt++;
}
db_compress::AttrVector &tuple = datasets[tuple_idx];
{ compressor.LearnTuple(tuple); }
if (tuple_cnt >= kNonFullPassStopPoint &&
!compressor.RequireFullPass()) {
break;
}
}
compressor.EndOfLearning();
if (!tuning && compressor.RequireFullPass()) {
tuning = true;
}
if (!compressor.RequireMoreIterationsForLearning()) {
break;
}
}
// Compression iteration
// std::cout << "Compression Iteration " << ++iter_cnt << " Starts\n";
auto compression_start = std::chrono::system_clock::now();
for (int i = 0; i < num_total_tuples; ++i) {
db_compress::AttrVector &tuple = datasets[i];
compressor.CompressTuple(tuple);
}
compressor.EndOfCompress();
auto compression_end = std::chrono::system_clock::now();
auto compression_duration =
std::chrono::duration_cast<std::chrono::microseconds>(
compression_end - compression_start);
std::cout << "Throughput: "
<< origin_size / 1024 / 1024 /
(static_cast<double>(compression_duration.count()) *
std::chrono::microseconds::period::num /
std::chrono::microseconds::period::den)
<< " MiB/s\t";
std::cout << "Time: "
<< static_cast<double>(compression_duration.count()) *
std::chrono::microseconds::period::num /
std::chrono::microseconds::period::den
<< " s\n";
}
{
// Decompress
std::cout << "[Decompression]\t";
db_compress::RelationDecompressor decompressor(output_file_name, schema,
block_size);
decompressor.Init();
db_compress::AttrVector tuple(static_cast<int>(schema.size()));
auto decompress_start = std::chrono::system_clock::now();
while (decompressor.HasNext())
decompressor.ReadNextTuple(&tuple);
auto decompress_end = std::chrono::system_clock::now();
auto decompress_duration =
std::chrono::duration_cast<std::chrono::microseconds>(
decompress_end - decompress_start);
std::cout << "Throughput: "
<< origin_size / 1024 / 1024 /
(static_cast<double>(decompress_duration.count()) *
std::chrono::microseconds::period::num /
std::chrono::microseconds::period::den)
<< " MiB/s\t";
std::cout << "Time: "
<< static_cast<double>(decompress_duration.count()) *
std::chrono::microseconds::period::num /
std::chrono::microseconds::period::den
<< " s\n";
}
int compressed_size = filesize(output_file_name);
std::cout << "[Compression Factor (Origin Size / CompressedSize)]: "
<< origin_size / (double) compressed_size << "\n";
std::cout << "Compressed Size: " << compressed_size << "\n";
remove(output_file_name);
// std::string index_file_name = std::to_string(getpid()) + "_temp.index";
// std::string enum_file_name = std::to_string(getpid()) + "_enum.dat";
std::string index_file_name = "_temp.index";
std::string enum_file_name = "_enum.dat";
remove(index_file_name.c_str());
remove(enum_file_name.c_str());
}
break;
case RANDOM_ACCESS: {
//
{
// compress first
db_compress::RelationCompressor compressor(output_file_name, schema,
config, block_size);
int num_total_tuples = LoadDataSet();
int iter_cnt = 0;
// random number
std::random_device random_device;
std::mt19937 mt19937(0);
std::uniform_int_distribution<uint32_t> dist(0, num_total_tuples - 1);
bool tuning = false;
// Learning Iterations
while (true) {
std::cout << "Iteration " << ++iter_cnt << " Starts\n";
int tuple_cnt = 0;
int tuple_random_cnt = 0;
int tuple_idx;
while (tuple_cnt < num_total_tuples) {
if (tuple_random_cnt < kNumEstSample) {
tuple_idx = static_cast<int>(dist(mt19937));
tuple_random_cnt++;
} else {
tuple_idx = tuple_cnt;
tuple_cnt++;
}
db_compress::AttrVector &tuple = datasets[tuple_idx];
{ compressor.LearnTuple(tuple); }
if (tuple_cnt >= kNonFullPassStopPoint &&
!compressor.RequireFullPass()) {
break;
}
}
compressor.EndOfLearning();
if (!tuning && compressor.RequireFullPass()) {
tuning = true;
}
if (!compressor.RequireMoreIterationsForLearning()) {
break;
}
}
// Compression iteration
// std::cout << "Compression Iteration " << ++iter_cnt << " Starts\n";
for (int i = 0; i < num_total_tuples; ++i) {
db_compress::AttrVector &tuple = datasets[i];
compressor.CompressTuple(tuple);
}
compressor.EndOfCompress();
std::cout << "Compressed Size: " << filesize(output_file_name) << "\n";
}
// Random Access Test
// InitModels decompressor
std::cout << "[Random Access Test]\t";
std::cout << "Note that in this test, number of tuple in a block should "
"be only ONE.\n";
// Load enum values
db_compress::Read(enum_map);
db_compress::RelationDecompressor decompressor(output_file_name, schema,
block_size);
decompressor.Init();
db_compress::AttrVector tuple(static_cast<int>(schema.size()));
#if DEBUG == 1
int size = 5;
std::vector<uint32_t> tuple_indices(size);
for (int i = 0; i < size; i++)
tuple_indices[i] = 2 * i;
#else
// Seed Generator
std::random_device random_device;
std::mt19937 mt19937(0);
std::uniform_int_distribution<uint32_t> dist(
0, decompressor.num_total_tuples_ - 1);
size_t size = 300000;
std::vector<uint32_t> tuple_indices(size);
for (size_t i = 0; i < size; i++) {
uint32_t idx = dist(mt19937);
tuple_indices[i] = idx;
}
#endif
auto start = std::chrono::system_clock::now();
for (int idx: tuple_indices) {
#if DEBUG == 0
// decompressor.ReadTargetTuple(idx, &tuple);
decompressor.LocateTuple(idx);
while (decompressor.HasNext())
decompressor.ReadNextTuple(&tuple);
#else
decompressor.LocateTuple(idx);
while (decompressor.HasNext())
decompressor.ReadNextTuple(&tuple);
#endif
#if DEBUG
for (size_t i = 0; i < schema.size(); ++i) {
std::string str;
ExtractAttr(tuple, schema.attr_type_[i], i, str);
std::cout << str << (i == schema.size() - 1 ? '\n' : ',');
}
#endif
}
auto end = std::chrono::system_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::microseconds>(end - start);
std::cout << "Time: "
<< static_cast<double>(duration.count()) *
std::chrono::microseconds::period::num /
std::chrono::microseconds::period::den / (int) size * 1e6
<< " us\n";
std::cout << "-------------------------------------------------------" << std::endl;
std::string index_file_name = std::to_string(getpid()) + "_temp.index";
std::string enum_file_name = std::to_string(getpid()) + "_enum.dat";
remove(index_file_name.c_str());
remove(enum_file_name.c_str());
remove(output_file_name);
}
break;
}
}
return 0;
}