ulysses-you commented on code in PR #5952:
URL: https://github.com/apache/incubator-gluten/pull/5952#discussion_r1623707892
##########
cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc:
##########
@@ -16,46 +16,64 @@
*/
#include "VeloxColumnarToRowConverter.h"
+#include <velox/common/base/SuccinctPrinter.h>
+#include <cstdint>
#include "memory/VeloxColumnarBatch.h"
+#include "utils/exception.h"
#include "velox/row/UnsafeRowDeserializers.h"
#include "velox/row/UnsafeRowFast.h"
using namespace facebook;
namespace gluten {
-void VeloxColumnarToRowConverter::refreshStates(facebook::velox::RowVectorPtr
rowVector) {
- numRows_ = rowVector->size();
+void VeloxColumnarToRowConverter::refreshStates(
+ facebook::velox::RowVectorPtr rowVector,
+ int64_t rowId,
+ int64_t memoryThreshold) {
+ auto vectorLength = rowVector->size();
numCols_ = rowVector->childrenSize();
fast_ = std::make_unique<velox::row::UnsafeRowFast>(rowVector);
size_t totalMemorySize = 0;
if (auto fixedRowSize =
velox::row::UnsafeRowFast::fixedRowSize(velox::asRowType(rowVector->type()))) {
- totalMemorySize += fixedRowSize.value() * numRows_;
+ GLUTEN_CHECK(
+ memoryThreshold > fixedRowSize.value(),
+ "spark.gluten.sql.columnarToRowMemoryThreshold(" +
velox::succinctBytes(memoryThreshold) +
+ ") is too small, it can't hold even one row(" +
velox::succinctBytes(fixedRowSize.value()) + ")");
+ auto rowSize = fixedRowSize.value();
+ numRows_ = std::min<int64_t>(memoryThreshold / rowSize, vectorLength -
rowId);
+ totalMemorySize = rowSize * numRows_;
} else {
- for (auto i = 0; i < numRows_; ++i) {
- totalMemorySize += fast_->rowSize(i);
+ int64_t i = rowId;
+ for (; i < vectorLength; ++i) {
+ auto rowSize = fast_->rowSize(i);
+ if (UNLIKELY(totalMemorySize + rowSize > memoryThreshold)) {
+ GLUTEN_CHECK(
+ i >= 1,
+ "spark.gluten.sql.columnarToRowMemoryThreshold(" +
velox::succinctBytes(memoryThreshold) +
+ ") is too small, it can't hold even one row(" +
velox::succinctBytes(rowSize) + ")");
+ break;
+ } else {
+ totalMemorySize += rowSize;
+ }
}
+ numRows_ = i - rowId;
}
if (veloxBuffers_ == nullptr) {
- // First allocate memory
- veloxBuffers_ = velox::AlignedBuffer::allocate<uint8_t>(totalMemorySize,
veloxPool_.get());
- }
-
- if (veloxBuffers_->capacity() < totalMemorySize) {
- velox::AlignedBuffer::reallocate<uint8_t>(&veloxBuffers_, totalMemorySize);
+ veloxBuffers_ = velox::AlignedBuffer::allocate<uint8_t>(memoryThreshold,
veloxPool_.get());
Review Comment:
The first parameter of `velox::AlignedBuffer::allocate` is numElements
rather than size, it will allocate the sizeof(uint8_t) * memoryThreshold.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]