MCPcopy Create free account
hub / github.com/apache/impala / TestCompression

Function TestCompression

be/src/experiments/compression-test.cc:47–97  ·  view source on GitHub ↗

Generates num strings between min_len and max_len. Outputs the uncompressed/compressed/sorted_compressed sizes.

Source from the content-addressed store, hash-verified

45// Generates num strings between min_len and max_len.
46// Outputs the uncompressed/compressed/sorted_compressed sizes.
47void TestCompression(int num, int min_len, int max_len, THdfsCompression::type format) {
48 vector<string> strings;
49 uint8_t* buffer = (uint8_t*)malloc(max_len * num);
50 int offset = 0;
51 int len_delta = max_len - min_len;
52 len_delta = max(len_delta, 1);
53 for (int i = 0; i < num; ++i) {
54 int len = rand() % len_delta + min_len;
55 int start = offset;
56 for (int j = 0; j < len; ++j) {
57 buffer[offset++] = rand() % 26 + 'a';
58 }
59 strings.push_back(string((char*)buffer + start, len));
60 }
61
62 // Sort the input and make a new buffer
63 uint8_t* sorted_buffer = (uint8_t*)malloc(offset);
64 int sorted_offset = 0;
65 sort(strings.begin(), strings.end());
66 for (int i = 0; i < strings.size(); ++i) {
67 memcpy(sorted_buffer + sorted_offset, strings[i].data(), strings[i].size());
68 sorted_offset += strings[i].size();
69 }
70
71 scoped_ptr<Codec> compressor;
72 Codec::CodecInfo codec_info(format);
73 Status status = Codec::CreateCompressor(NULL, false, codec_info, &compressor);
74 DCHECK(status.ok());
75
76 int64_t compressed_len = compressor->MaxOutputLen(offset);
77 uint8_t* compressed_buffer = (uint8_t*)malloc(compressed_len);
78 ABORT_IF_ERROR(
79 compressor->ProcessBlock(true, offset, buffer, &compressed_len, &compressed_buffer));
80
81 int64_t sorted_compressed_len = compressor->MaxOutputLen(offset);
82 uint8_t* sorted_compressed_buffer = (uint8_t*)malloc(sorted_compressed_len);
83 ABORT_IF_ERROR(compressor->ProcessBlock(true, offset, sorted_buffer,
84 &sorted_compressed_len, &sorted_compressed_buffer));
85
86 cout << "NumStrings=" << num << " MinLen=" << min_len << " MaxLen=" << max_len
87 << " Codec=" << codec_info.format_ << endl;
88 cout << " Uncompressed len: " << offset << endl;
89 cout << " Compressed len: " << compressed_len << endl;
90 cout << " Sorted Compressed len: " << sorted_compressed_len << endl;
91
92 compressor->Close();
93 free(buffer);
94 free(compressed_buffer);
95 free(sorted_buffer);
96 free(sorted_compressed_buffer);
97}
98
99}
100

Callers 1

mainFunction · 0.70

Calls 11

maxFunction · 0.85
sortFunction · 0.85
push_backMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
okMethod · 0.45
MaxOutputLenMethod · 0.45
ProcessBlockMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected