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

Method GenerateMultiStreamData

be/src/util/decompress-test.cc:340–375  ·  view source on GitHub ↗

Try to simulate pbzip2 behavior. pbzip2 splits large input into smaller chunks and compresses them separately, then concatenate the compressed streams together. We generate ~16MB compressed data to make sure it's bigger than the decompressor's output buffer size(STREAM_OUT_BUF_SIZE). With the generated raw input data, we expect ~2:1 compression ratio so we need 4xSTREAM_OUT_BUF_SIZE input data in

Source from the content-addressed store, hash-verified

338 // output buffer size(STREAM_OUT_BUF_SIZE). With the generated raw input data, we
339 // expect ~2:1 compression ratio so we need 4xSTREAM_OUT_BUF_SIZE input data in total.
340 void GenerateMultiStreamData(THdfsCompression::type format, int64_t* uncompressed_len,
341 uint8_t** uncompressed_data, int64_t* compressed_len, uint8_t** compressed_data) {
342 uint8_t raw_input[RAW_INPUT_SIZE + 1];
343 for (int i = 0; i < RAW_INPUT_SIZE; ++i) {
344 raw_input[i] = 'a' + rand() % 26;
345 }
346 raw_input[RAW_INPUT_SIZE] = 0;
347
348 // Repeatedly pick random-size input data(~1MB), compress it, then concatenate
349 // those small compressed streams into one big buffer. Also save random input
350 // into a single buffer to verify decompressor output.
351 *compressed_data = mem_pool_.Allocate(COMPRESSED_BUFFER_SIZE);
352 *uncompressed_data = mem_pool_.Allocate(UNCOMPRESSED_BUFFER_SIZE);
353 *uncompressed_len = 0;
354 *compressed_len = 0;
355
356 scoped_ptr<Codec> compressor;
357 Codec::CodecInfo codec_info(format);
358 EXPECT_OK(Codec::CreateCompressor(&mem_pool_, true, codec_info, &compressor));
359
360 // Make sure we don't completely fill the buffer, leave at least RAW_INPUT_SIZE
361 // bytes free in compressed buffer for junk data testing (Test case 3).
362 while (*compressed_len < (COMPRESSED_BUFFER_SIZE - RAW_INPUT_SIZE)
363 && *uncompressed_len < (UNCOMPRESSED_BUFFER_SIZE - RAW_INPUT_SIZE)) {
364 int len = RAW_INPUT_SIZE - (rand() % 1024);
365 uint8_t* compressed_stream = NULL;
366 int64_t compressed_length = 0;
367 EXPECT_OK(compressor->ProcessBlock(false, len, raw_input, &compressed_length,
368 &compressed_stream));
369 memcpy(*compressed_data + *compressed_len, compressed_stream, compressed_length);
370 memcpy(*uncompressed_data + *uncompressed_len, raw_input, len);
371 *uncompressed_len += len;
372 *compressed_len += compressed_length;
373 }
374 compressor->Close();
375 }
376
377 // Buffer to hold generated random data. Size doesn't matter, use 1MB for easy
378 // calculation.

Callers

nothing calls this directly

Calls 3

AllocateMethod · 0.45
ProcessBlockMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected