Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up overuse of auto in MapConcat.cpp #11152

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading