diff --git a/velox/functions/lib/MapConcat.cpp b/velox/functions/lib/MapConcat.cpp index c11b9ae19579..3d355b70b2a8 100644 --- a/velox/functions/lib/MapConcat.cpp +++ b/velox/functions/lib/MapConcat.cpp @@ -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(); - auto rawSizes = inputMap->rawSizes(); + for (int i = 0; i < numArgs; i++) { + const DecodedVector* decodedArg = decodedArgs.at(i); + const MapVector* inputMap = decodedArg->base()->as(); + const vector_size_t* rawSizes = inputMap->rawSizes(); rows.applyToSelected([&](vector_size_t row) { if (EmptyForNull && decodedArg->isNullAt(row)) { return; @@ -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(); + int* rawOffsets = offsets->asMutable(); BufferPtr sizes = allocateSizes(rows.end(), pool); - auto rawSizes = sizes->asMutable(); + int* rawSizes = sizes->asMutable(); 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(); - auto index = decodedArg->index(row); - auto inputOffset = inputMap->offsetAt(index); - auto inputSize = inputMap->sizeAt(index); + const MapVector* inputMap = decodedArg->base()->as(); + 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( @@ -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; } @@ -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* rawUniqueIndices = + uniqueIndices->asMutable(); 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( @@ -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);