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

Function testStringDictionary

c++/test/TestDictionaryEncoding.cc:82–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80 }
81
82 void testStringDictionary(bool enableIndex, double threshold, bool enableEncodedBlock = false) {
83 MemoryOutputStream memStream(DEFAULT_MEM_STREAM_SIZE);
84 MemoryPool* pool = getDefaultPool();
85 std::unique_ptr<Type> type(Type::buildTypeFromString("struct<col1:string>"));
86
87 WriterOptions options;
88 options.setStripeSize(1024);
89 options.setMemoryBlockSize(64);
90 options.setCompressionBlockSize(1024);
91 options.setCompression(CompressionKind_ZLIB);
92 options.setMemoryPool(pool);
93 options.setDictionaryKeySizeThreshold(threshold);
94 options.setRowIndexStride(enableIndex ? 10000 : 0);
95 std::unique_ptr<Writer> writer = createWriter(*type, &memStream, options);
96
97 char dataBuffer[327675];
98 uint64_t offset = 0, rowCount = 65535;
99 std::unique_ptr<ColumnVectorBatch> batch = writer->createRowBatch(rowCount);
100 StructVectorBatch* structBatch = dynamic_cast<StructVectorBatch*>(batch.get());
101 StringVectorBatch* strBatch = dynamic_cast<StringVectorBatch*>(structBatch->fields[0]);
102
103 uint64_t dictionarySize = DICTIONARY_SIZE_1K;
104 for (uint64_t i = 0; i < rowCount; ++i) {
105 std::ostringstream os;
106 os << (i % dictionarySize);
107 memcpy(dataBuffer + offset, os.str().c_str(), os.str().size());
108
109 strBatch->data[i] = dataBuffer + offset;
110 strBatch->length[i] = static_cast<int64_t>(os.str().size());
111
112 offset += os.str().size();
113 }
114 structBatch->numElements = rowCount;
115 strBatch->numElements = rowCount;
116 writer->add(*batch);
117 writer->close();
118
119 std::unique_ptr<InputStream> inStream(
120 new MemoryInputStream(memStream.getData(), memStream.getLength()));
121 std::unique_ptr<Reader> reader = createReader(pool, std::move(inStream));
122 std::unique_ptr<RowReader> rowReader = createRowReader(reader.get(), enableEncodedBlock);
123 EXPECT_EQ(rowCount, reader->getNumberOfRows());
124
125 batch = rowReader->createRowBatch(rowCount);
126 EXPECT_EQ(true, rowReader->next(*batch));
127 EXPECT_EQ(rowCount, batch->numElements);
128
129 structBatch = dynamic_cast<StructVectorBatch*>(batch.get());
130 strBatch = dynamic_cast<StringVectorBatch*>(structBatch->fields[0]);
131 if (doubleEquals(threshold, DICT_THRESHOLD) && enableEncodedBlock) {
132 checkDictionaryEncoding(strBatch);
133 strBatch->decodeDictionary();
134 }
135
136 for (uint64_t i = 0; i < rowCount; ++i) {
137 std::string str(strBatch->data[i], static_cast<size_t>(strBatch->length[i]));
138 EXPECT_EQ(i % dictionarySize, static_cast<uint64_t>(atoi(str.c_str())));
139 }

Callers 1

TESTFunction · 0.85

Calls 15

getDefaultPoolFunction · 0.85
doubleEqualsFunction · 0.85
checkDictionaryEncodingFunction · 0.85
decodeDictionaryMethod · 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

Tested by

no test coverage detected