From b431cf027595c7d4a01af6baeb57c8e4b13c6a92 Mon Sep 17 00:00:00 2001 From: "chenweiguo.vc" Date: Fri, 24 Jan 2025 01:26:05 +0800 Subject: [PATCH 1/2] BaseVariableWidthViewVector setZero only if necessary --- .../vector/BaseVariableWidthViewVector.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java b/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java index 15d2182783..1ad2144c54 100644 --- a/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java +++ b/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java @@ -1367,11 +1367,13 @@ protected ArrowBuf allocateOrGetLastDataBuffer(int length) { protected final void setBytes(int index, byte[] value, int start, int length) { int writePosition = index * ELEMENT_SIZE; - // to clear the memory segment of view being written to - // this is helpful in case of overwriting the value - viewBuffer.setZero(writePosition, ELEMENT_SIZE); - if (length <= INLINE_SIZE) { + // to clear the memory segment of view being written to + // if it has been set + if (viewBuffer.getLong(writePosition) != 0 || viewBuffer.getLong(writePosition + 8) != 0) { + viewBuffer.setZero(writePosition, ELEMENT_SIZE); + } + // allocate inline buffer // set length viewBuffer.setInt(writePosition, length); @@ -1411,11 +1413,13 @@ protected final void setBytes(int index, byte[] value, int start, int length) { protected final void setBytes(int index, ArrowBuf valueBuf, int start, int length) { int writePosition = index * ELEMENT_SIZE; - // to clear the memory segment of view being written to - // this is helpful in case of overwriting the value - viewBuffer.setZero(writePosition, ELEMENT_SIZE); - if (length <= INLINE_SIZE) { + // to clear the memory segment of view being written to + // if it has been set + if (viewBuffer.getLong(writePosition) != 0 || viewBuffer.getLong(writePosition + 8) != 0) { + viewBuffer.setZero(writePosition, ELEMENT_SIZE); + } + // allocate inline buffer // set length viewBuffer.setInt(writePosition, length); From 16c9e2f4bc5921a4d6e0572954b19b5f958dbf85 Mon Sep 17 00:00:00 2001 From: "chenweiguo.vc" Date: Fri, 24 Jan 2025 12:36:45 +0800 Subject: [PATCH 2/2] comment --- .../apache/arrow/vector/BaseVariableWidthViewVector.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java b/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java index 1ad2144c54..e0e16762f2 100644 --- a/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java +++ b/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java @@ -1368,8 +1368,8 @@ protected final void setBytes(int index, byte[] value, int start, int length) { int writePosition = index * ELEMENT_SIZE; if (length <= INLINE_SIZE) { - // to clear the memory segment of view being written to - // if it has been set + // Check if the memory segment has been written, and clear it if it has been set. + // It is recommended to batch initialize the viewBuffer before setBytes. if (viewBuffer.getLong(writePosition) != 0 || viewBuffer.getLong(writePosition + 8) != 0) { viewBuffer.setZero(writePosition, ELEMENT_SIZE); } @@ -1414,8 +1414,8 @@ protected final void setBytes(int index, ArrowBuf valueBuf, int start, int lengt int writePosition = index * ELEMENT_SIZE; if (length <= INLINE_SIZE) { - // to clear the memory segment of view being written to - // if it has been set + // Check if the memory segment has been written, and clear it if it has been set. + // It is recommended to batch initialize the viewBuffer before setBytes. if (viewBuffer.getLong(writePosition) != 0 || viewBuffer.getLong(writePosition + 8) != 0) { viewBuffer.setZero(writePosition, ELEMENT_SIZE); }