MCPcopy Create free account
hub / github.com/apache/orc / testDictionaryMultipleStripes

Function testDictionaryMultipleStripes

c++/test/TestDictionaryEncoding.cc:353–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

351 }
352
353 void testDictionaryMultipleStripes(double threshold, bool enableIndex) {
354 MemoryOutputStream memStream(DEFAULT_MEM_STREAM_SIZE);
355 MemoryPool* pool = getDefaultPool();
356 std::unique_ptr<Type> type(Type::buildTypeFromString("struct<col1:string>"));
357
358 WriterOptions options;
359 options.setStripeSize(1);
360 options.setMemoryBlockSize(1024);
361 options.setCompressionBlockSize(2 * 1024);
362 options.setCompression(CompressionKind_ZLIB);
363 options.setMemoryPool(pool);
364 options.setDictionaryKeySizeThreshold(threshold);
365 options.setRowIndexStride(enableIndex ? 10000 : 0);
366 std::unique_ptr<Writer> writer = createWriter(*type, &memStream, options);
367
368 char dataBuffer[800000];
369 uint64_t offset = 0, rowCount = 65535, stripeCount = 3;
370 std::unique_ptr<ColumnVectorBatch> batch = writer->createRowBatch(rowCount);
371 StructVectorBatch* structBatch = dynamic_cast<StructVectorBatch*>(batch.get());
372 StringVectorBatch* strBatch = dynamic_cast<StringVectorBatch*>(structBatch->fields[0]);
373
374 uint64_t dictionarySize = DICTIONARY_SIZE_1K;
375
376 for (uint64_t stripe = 0; stripe != stripeCount; ++stripe) {
377 for (uint64_t i = 0; i < rowCount; ++i) {
378 std::ostringstream os;
379 os << (i % dictionarySize);
380 memcpy(dataBuffer + offset, os.str().c_str(), os.str().size());
381
382 strBatch->data[i] = dataBuffer + offset;
383 strBatch->length[i] = static_cast<int64_t>(os.str().size());
384
385 offset += os.str().size();
386 }
387
388 structBatch->numElements = rowCount;
389 strBatch->numElements = rowCount;
390
391 writer->add(*batch);
392 }
393
394 writer->close();
395
396 std::unique_ptr<InputStream> inStream(
397 new MemoryInputStream(memStream.getData(), memStream.getLength()));
398 std::unique_ptr<Reader> reader = createReader(pool, std::move(inStream));
399 std::unique_ptr<RowReader> rowReader = createRowReader(reader.get());
400
401 // make sure there are multiple stripes
402 EXPECT_EQ(rowCount * stripeCount, reader->getNumberOfRows());
403 EXPECT_EQ(stripeCount, reader->getNumberOfStripes());
404
405 // test reading sequentially for data correctness
406 batch = rowReader->createRowBatch(rowCount);
407 for (uint64_t stripe = 0; stripe != stripeCount; ++stripe) {
408 EXPECT_EQ(true, rowReader->next(*batch));
409
410 structBatch = dynamic_cast<StructVectorBatch*>(batch.get());

Callers 1

TESTFunction · 0.85

Calls 15

getDefaultPoolFunction · 0.85
getNumberOfStripesMethod · 0.80
createWriterFunction · 0.70
createReaderFunction · 0.70
createRowReaderFunction · 0.70
sizeMethod · 0.65
addMethod · 0.65
closeMethod · 0.65
getLengthMethod · 0.65
getNumberOfRowsMethod · 0.65
nextMethod · 0.65
seekToRowMethod · 0.65

Tested by

no test coverage detected