diff --git a/velox/functions/sparksql/ConcatWs.cpp b/velox/functions/sparksql/ConcatWs.cpp index b477086165d2c..f51c5a7932cdd 100644 --- a/velox/functions/sparksql/ConcatWs.cpp +++ b/velox/functions/sparksql/ConcatWs.cpp @@ -59,10 +59,9 @@ class ConcatWs : public exec::VectorFunction { if (decodedArrays[i]->isNullAt(row)) { continue; } - auto arrayVector = arrayVectors[i]; auto indices = decodedArrays[i].get()->indices(); - auto size = arrayVector->sizeAt(indices[row]); - auto offset = arrayVector->offsetAt(indices[row]); + auto size = arrayVectors[i]->sizeAt(indices[row]); + auto offset = arrayVectors[i]->offsetAt(indices[row]); for (int j = 0; j < size; ++j) { if (!elementsDecodedVectors[i].isNullAt(offset + j)) { @@ -97,7 +96,7 @@ class ConcatWs : public exec::VectorFunction { totalResultBytes += value.size(); } - int32_t separatorSize = isConstantSeparator() + auto separatorSize = isConstantSeparator() ? separator_.value().size() : decodedSeparator->valueAt(row).size(); @@ -235,15 +234,11 @@ class ConcatWs : public exec::VectorFunction { isFirst = false; } else { // Add separator before the current value. - if (!separator.empty()) { - memcpy(rawBuffer, separator.data(), separator.size()); - rawBuffer += separator.size(); - } - } - if (!value.empty()) { - memcpy(rawBuffer, value.data(), value.size()); - rawBuffer += value.size(); + memcpy(rawBuffer, separator.data(), separator.size()); + rawBuffer += separator.size(); } + memcpy(rawBuffer, value.data(), value.size()); + rawBuffer += value.size(); }; for (auto itArgs = args.begin() + 1; itArgs != args.end(); ++itArgs) { @@ -252,10 +247,9 @@ class ConcatWs : public exec::VectorFunction { ++i; continue; } - auto arrayVector = arrayVectors[i]; auto indices = decodedArrays[i].get()->indices(); - auto size = arrayVector->sizeAt(indices[row]); - auto offset = arrayVector->offsetAt(indices[row]); + auto size = arrayVectors[i]->sizeAt(indices[row]); + auto offset = arrayVectors[i]->offsetAt(indices[row]); for (int k = 0; k < size; ++k) { if (!elementsDecodedVectors[i].isNullAt(offset + k)) {