Skip to content

Commit

Permalink
Require type in FlatVector constructor (#4073)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #4073

Reviewed By: xiaoxmeng, KarthikTunga, pedroerp

Differential Revision: D43394821

Pulled By: mbasmanova

fbshipit-source-id: 296db54f78c80c59a942cba4aca6bdf14b1b4a3e
  • Loading branch information
mbasmanova authored and facebook-github-bot committed Feb 18, 2023
1 parent 7915dea commit e4a2c99
Show file tree
Hide file tree
Showing 23 changed files with 313 additions and 343 deletions.
1 change: 1 addition & 0 deletions velox/dwio/common/FlatMapHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void initializeFlatVector(
if (!vector) {
vector = std::make_shared<FlatVector<T>>(
&pool,
CppToType<T>::create(),
hasNulls ? AlignedBuffer::allocate<bool>(size, &pool) : nullptr,
0 /*length*/,
AlignedBuffer::allocate<T>(size, &pool),
Expand Down
7 changes: 6 additions & 1 deletion velox/dwio/common/tests/utils/BatchMaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,12 @@ VectorPtr createScalarMapKeys(
}

return std::make_shared<FlatVector<T>>(
&pool, BufferPtr(nullptr), totalKeys, values, std::vector<BufferPtr>{});
&pool,
CppToType<T>::create(),
BufferPtr(nullptr),
totalKeys,
values,
std::vector<BufferPtr>{});
}

VectorPtr createBinaryMapKeys(
Expand Down
17 changes: 7 additions & 10 deletions velox/dwio/common/tests/utils/MapBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,22 @@ class MapBuilder {
using rows = std::vector<std::optional<row>>;

static VectorPtr create(memory::MemoryPool& pool, rows rows) {
const std::shared_ptr<const Type> type =
CppToType<Map<TKEY, TVALUE>>::create();
const auto type = CppToType<Map<TKEY, TVALUE>>::create();
auto items = 0;
for (auto& row : rows) {
if (row.has_value()) {
items += row->size();
}
}

BufferPtr nulls =
AlignedBuffer::allocate<char>(bits::nbytes(rows.size()), &pool);
BufferPtr nulls = allocateNulls(rows.size(), &pool);
auto* nullsPtr = nulls->asMutable<uint64_t>();
size_t nullCount = 0;

BufferPtr offsets =
AlignedBuffer::allocate<vector_size_t>(rows.size(), &pool);
BufferPtr offsets = allocateOffsets(rows.size(), &pool);
auto* offsetsPtr = offsets->asMutable<vector_size_t>();

BufferPtr lengths =
AlignedBuffer::allocate<vector_size_t>(rows.size(), &pool);
BufferPtr lengths = allocateSizes(rows.size(), &pool);
auto* lengthsPtr = lengths->asMutable<vector_size_t>();

BufferPtr keys = AlignedBuffer::allocate<TKEY>(items, &pool);
Expand All @@ -57,8 +53,7 @@ class MapBuilder {
BufferPtr values = AlignedBuffer::allocate<TVALUE>(items, &pool);
auto* valuesPtr = values->asMutable<TVALUE>();

BufferPtr valueNulls =
AlignedBuffer::allocate<char>(bits::nbytes(items), &pool);
BufferPtr valueNulls = allocateNulls(items, &pool);
auto* valueNullsPtr = valueNulls->asMutable<uint64_t>();
size_t valueNullCount = 0;

Expand Down Expand Up @@ -103,12 +98,14 @@ class MapBuilder {
lengths,
std::make_shared<FlatVector<TKEY>>(
&pool,
type->childAt(0),
BufferPtr(nullptr),
items /*length*/,
keys,
std::vector<BufferPtr>()),
std::make_shared<FlatVector<TVALUE>>(
&pool,
type->childAt(1),
valueNulls,
items /*length*/,
values,
Expand Down
8 changes: 7 additions & 1 deletion velox/dwio/dwrf/reader/ColumnReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,12 @@ VectorPtr makeFlatVector(
size_t length,
BufferPtr values) {
auto flatVector = std::make_shared<FlatVector<T>>(
pool, nulls, length, values, std::vector<BufferPtr>());
pool,
CppToType<T>::create(),
nulls,
length,
values,
std::vector<BufferPtr>());
flatVector->setNullCount(nullCount);
return flatVector;
}
Expand Down Expand Up @@ -1344,6 +1349,7 @@ void StringDictionaryColumnReader::readFlatVector(
} else {
result = std::make_shared<FlatVector<StringView>>(
&memoryPool_,
VARCHAR(),
nulls,
numValues,
data,
Expand Down
33 changes: 19 additions & 14 deletions velox/dwio/dwrf/test/ColumnWriterIndexTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ VectorPtr prepBatchImpl(
}

auto batch = std::make_shared<FlatVector<T>>(
pool, nulls, size, values, std::vector<BufferPtr>());
pool,
CppToType<T>::create(),
nulls,
size,
values,
std::vector<BufferPtr>());
batch->setNullCount(nullCount);
return batch;
}
Expand All @@ -102,7 +107,7 @@ VectorPtr prepStringBatchImpl(
MemoryPool* pool,
std::function<std::string(size_t, size_t)> genData,
std::function<bool(size_t, size_t)> genNulls) {
BufferPtr nulls = AlignedBuffer::allocate<char>(bits::nbytes(size), pool);
BufferPtr nulls = allocateNulls(size, pool);
auto* nullsPtr = nulls->asMutable<uint64_t>();
size_t nullCount = 0;

Expand Down Expand Up @@ -138,7 +143,7 @@ VectorPtr prepStringBatchImpl(
}

auto batch = std::make_shared<FlatVector<StringView>>(
pool, nulls, size, values, std::move(dataChunks));
pool, VARCHAR(), nulls, size, values, std::move(dataChunks));
batch->setNullCount(nullCount);
return batch;
}
Expand Down Expand Up @@ -564,7 +569,7 @@ class BinaryColumnWriterEncodingIndexTest

protected:
VectorPtr prepBatch(size_t size, MemoryPool* pool) override {
BufferPtr nulls = AlignedBuffer::allocate<char>(bits::nbytes(size), pool);
BufferPtr nulls = allocateNulls(size, pool);
auto* nullsPtr = nulls->asMutable<uint64_t>();
size_t nullCount = 0;

Expand All @@ -589,7 +594,7 @@ class BinaryColumnWriterEncodingIndexTest
}

auto batch = std::make_shared<FlatVector<StringView>>(
pool, nulls, size, values, std::vector<BufferPtr>{data});
pool, VARCHAR(), nulls, size, values, std::vector<BufferPtr>{data});
batch->setNullCount(nullCount);
return batch;
}
Expand Down Expand Up @@ -1152,14 +1157,14 @@ class ListColumnWriterEncodingIndexTest

protected:
VectorPtr prepBatch(size_t size, MemoryPool* pool) override {
auto nulls = AlignedBuffer::allocate<char>(bits::nbytes(size), pool);
auto nulls = allocateNulls(size, pool);
auto* nullsPtr = nulls->asMutable<uint64_t>();
size_t nullCount = 0;

auto offsets = AlignedBuffer::allocate<vector_size_t>(size, pool);
auto offsets = allocateOffsets(size, pool);
auto* offsetsPtr = offsets->asMutable<vector_size_t>();

auto lengths = AlignedBuffer::allocate<vector_size_t>(size, pool);
auto lengths = allocateSizes(size, pool);
auto* lengthsPtr = lengths->asMutable<vector_size_t>();

size_t value = 0;
Expand Down Expand Up @@ -1218,14 +1223,14 @@ class MapColumnWriterEncodingIndexTest

protected:
VectorPtr prepBatch(size_t size, MemoryPool* pool) override {
auto nulls = AlignedBuffer::allocate<char>(bits::nbytes(size), pool);
auto nulls = allocateNulls(size, pool);
auto* nullsPtr = nulls->asMutable<uint64_t>();
size_t nullCount = 0;

auto offsets = AlignedBuffer::allocate<vector_size_t>(size, pool);
auto offsets = allocateOffsets(size, pool);
auto* offsetsPtr = offsets->asMutable<vector_size_t>();

auto lengths = AlignedBuffer::allocate<vector_size_t>(size, pool);
auto lengths = allocateSizes(size, pool);
auto* lengthsPtr = lengths->asMutable<vector_size_t>();

size_t value = 0;
Expand Down Expand Up @@ -1289,12 +1294,12 @@ class FlatMapColumnWriterEncodingIndexTest

protected:
VectorPtr prepBatch(size_t size, MemoryPool* pool) override {
auto offsets = AlignedBuffer::allocate<vector_size_t>(size, pool);
auto offsets = allocateOffsets(size, pool);
auto* offsetsPtr = offsets->asMutable<vector_size_t>();
auto offsets2 = AlignedBuffer::allocate<vector_size_t>(size, pool);
auto* offsets2Ptr = offsets2->asMutable<vector_size_t>();

auto lengths = AlignedBuffer::allocate<vector_size_t>(size, pool);
auto lengths = allocateSizes(size, pool);
auto* lengthsPtr = lengths->asMutable<vector_size_t>();
auto lengths2 = AlignedBuffer::allocate<vector_size_t>(size, pool);
auto* lengths2Ptr = lengths2->asMutable<vector_size_t>();
Expand Down Expand Up @@ -1384,7 +1389,7 @@ class StructColumnWriterEncodingIndexTest
}

VectorPtr prepBatch(size_t size, MemoryPool* pool, bool isRoot) override {
auto nulls = AlignedBuffer::allocate<char>(bits::nbytes(size), pool);
auto nulls = allocateNulls(size, pool);
auto* nullsPtr = nulls->asMutable<uint64_t>();
size_t nullCount = 0;

Expand Down
Loading

0 comments on commit e4a2c99

Please sign in to comment.