Skip to content

Commit

Permalink
Clean up overuse of auto in MapConcat.cpp (facebookincubator#11152)
Browse files Browse the repository at this point in the history
Summary:

Wherever the type of any variable is not clear due to the use of auto, it was excpliticly declared instead.

Differential Revision: D63723010
  • Loading branch information
Daniel Hunte authored and facebook-github-bot committed Oct 3, 2024
1 parent 8369142 commit 92a4e9d
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions velox/functions/lib/MapConcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ class MapConcatFunction : public exec::VectorFunction {
exec::EvalCtx& context,
VectorPtr& result) const override {
VELOX_CHECK_GE(args.size(), 2);
auto mapType = args[0]->type();
const TypePtr& mapType = args[0]->type();
VELOX_CHECK_EQ(mapType->kind(), TypeKind::MAP);
for (auto& arg : args) {
for (const VectorPtr& arg : args) {
VELOX_CHECK(mapType->kindEquals(arg->type()));
}
VELOX_CHECK(mapType->kindEquals(outputType));

auto numArgs = args.size();
const uint64_t numArgs = args.size();
exec::DecodedArgs decodedArgs(rows, args, context);
vector_size_t maxSize = 0;
for (auto i = 0; i < numArgs; i++) {
auto decodedArg = decodedArgs.at(i);
auto inputMap = decodedArg->base()->as<MapVector>();
auto rawSizes = inputMap->rawSizes();
for (int i = 0; i < numArgs; i++) {
const DecodedVector* decodedArg = decodedArgs.at(i);
const MapVector* inputMap = decodedArg->base()->as<MapVector>();
const vector_size_t* rawSizes = inputMap->rawSizes();
rows.applyToSelected([&](vector_size_t row) {
if (EmptyForNull && decodedArg->isNullAt(row)) {
return;
Expand All @@ -54,34 +54,34 @@ class MapConcatFunction : public exec::VectorFunction {
});
}

auto keyType = outputType->asMap().keyType();
auto valueType = outputType->asMap().valueType();
const TypePtr& keyType = outputType->asMap().keyType();
const TypePtr& valueType = outputType->asMap().valueType();

auto* pool = context.pool();
memory::MemoryPool* pool = context.pool();
auto combinedKeys = BaseVector::create(keyType, maxSize, pool);
auto combinedValues = BaseVector::create(valueType, maxSize, pool);

// Initialize offsets and sizes to 0 so that canonicalize() will
// work also for sparse 'rows'.
BufferPtr offsets = allocateOffsets(rows.end(), pool);
auto rawOffsets = offsets->asMutable<vector_size_t>();
int* rawOffsets = offsets->asMutable<vector_size_t>();

BufferPtr sizes = allocateSizes(rows.end(), pool);
auto rawSizes = sizes->asMutable<vector_size_t>();
int* rawSizes = sizes->asMutable<vector_size_t>();

vector_size_t offset = 0;
rows.applyToSelected([&](vector_size_t row) {
rawOffsets[row] = offset;
// Reuse the last offset and size if null key must create empty map
for (auto i = 0; i < numArgs; i++) {
auto decodedArg = decodedArgs.at(i);
for (int i = 0; i < numArgs; i++) {
const DecodedVector* decodedArg = decodedArgs.at(i);
if (EmptyForNull && decodedArg->isNullAt(row)) {
continue; // Treat NULL maps as empty.
}
auto inputMap = decodedArg->base()->as<MapVector>();
auto index = decodedArg->index(row);
auto inputOffset = inputMap->offsetAt(index);
auto inputSize = inputMap->sizeAt(index);
const MapVector* inputMap = decodedArg->base()->as<MapVector>();
const vector_size_t index = decodedArg->index(row);
const vector_size_t inputOffset = inputMap->offsetAt(index);
const vector_size_t inputSize = inputMap->sizeAt(index);
combinedKeys->copy(
inputMap->mapKeys().get(), offset, inputOffset, inputSize);
combinedValues->copy(
Expand Down Expand Up @@ -110,8 +110,8 @@ class MapConcatFunction : public exec::VectorFunction {
SelectivityVector uniqueKeys(offset);
vector_size_t duplicateCnt = 0;
rows.applyToSelected([&](vector_size_t row) {
auto mapOffset = rawOffsets[row];
auto mapSize = rawSizes[row];
const int mapOffset = rawOffsets[row];
const int mapSize = rawSizes[row];
if (duplicateCnt) {
rawOffsets[row] -= duplicateCnt;
}
Expand All @@ -128,16 +128,18 @@ class MapConcatFunction : public exec::VectorFunction {

if (duplicateCnt) {
uniqueKeys.updateBounds();
auto uniqueCount = uniqueKeys.countSelected();
const vector_size_t uniqueCount = uniqueKeys.countSelected();

BufferPtr uniqueIndices = allocateIndices(uniqueCount, pool);
auto rawUniqueIndices = uniqueIndices->asMutable<vector_size_t>();
vector_size_t* rawUniqueIndices =
uniqueIndices->asMutable<vector_size_t>();
vector_size_t index = 0;
uniqueKeys.applyToSelected(
[&](vector_size_t row) { rawUniqueIndices[index++] = row; });

auto keys = BaseVector::transpose(uniqueIndices, std::move(combinedKeys));
auto values =
VectorPtr keys =
BaseVector::transpose(uniqueIndices, std::move(combinedKeys));
VectorPtr values =
BaseVector::transpose(uniqueIndices, std::move(combinedValues));

combinedMap = std::make_shared<MapVector>(
Expand All @@ -147,8 +149,8 @@ class MapConcatFunction : public exec::VectorFunction {
rows.end(),
offsets,
sizes,
keys,
values);
std::move(keys),
std::move(values));
}

context.moveOrCopyResult(combinedMap, rows, result);
Expand Down

0 comments on commit 92a4e9d

Please sign in to comment.