liyafan82 commented on a change in pull request #8214:
URL: https://github.com/apache/arrow/pull/8214#discussion_r494118200
##########
File path:
java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java
##########
@@ -48,7 +48,8 @@
implements FixedWidthVector, FieldVector, VectorDefinitionSetter {
private final int typeWidth;
- protected int lastValueCapacity;
+ protected int lastTargetValueCapacity;
Review comment:
I am not sure if we should change this variable's name, as in other
classes (e.g. BaseVariableWidthVector and BaseLargeVariableWidthVector), they
are called "lastValueCapacity"
##########
File path: java/vector/src/main/java/org/apache/arrow/vector/BitVector.java
##########
@@ -126,7 +126,12 @@ public void setInitialCapacity(int valueCount) {
*/
@Override
public int getValueCapacity() {
- return capAtMaxInt(validityBuffer.capacity() * 8);
+ return actualValueCapacity;
+ }
Review comment:
The implementation is identical to that of the super class, so we have
no need of overriding it?
##########
File path: java/vector/src/main/java/org/apache/arrow/vector/BitVector.java
##########
@@ -126,7 +126,12 @@ public void setInitialCapacity(int valueCount) {
*/
@Override
public int getValueCapacity() {
- return capAtMaxInt(validityBuffer.capacity() * 8);
+ return actualValueCapacity;
+ }
+
+ @Override
+ protected void refreshValueCapacity() {
+ actualValueCapacity = capAtMaxInt(validityBuffer.capacity() * 8);
Review comment:
I am a little surprised here (I am aware that it was copied from the
original implementation): the value capacity of a BitVector should also
consider the capacity of the data buffer. So I think the original
implementation has a bug here?
##########
File path: java/vector/src/main/java/org/apache/arrow/vector/BitVector.java
##########
@@ -119,13 +119,16 @@ public void setInitialCapacity(int valueCount) {
lastValueCapacity = valueCount;
}
- /**
- * Get the current value capacity for the vector.
- *
- * @return number of elements that vector can hold.
- */
@Override
- public int getValueCapacity() {
+ protected void refreshValueCapacity() {
+ actualValueCapacity = Math.min(getValueBufferValueCapacity(),
getValidityBufferValueCapacity());
+ }
+
+ private int getValueBufferValueCapacity() {
+ return capAtMaxInt(valueBuffer.capacity() * 8);
+ }
+
+ private int getValidityBufferValueCapacity() {
Review comment:
This one is identical to the one in the super class, so it can be
removed?
##########
File path: java/vector/src/main/java/org/apache/arrow/vector/BitVector.java
##########
@@ -119,13 +119,16 @@ public void setInitialCapacity(int valueCount) {
lastValueCapacity = valueCount;
}
- /**
- * Get the current value capacity for the vector.
- *
- * @return number of elements that vector can hold.
- */
@Override
- public int getValueCapacity() {
+ protected void refreshValueCapacity() {
Review comment:
This implementation is identical to the one in the super class, so no
need to override it?
##########
File path: java/vector/src/main/java/org/apache/arrow/vector/BitVector.java
##########
@@ -119,13 +119,16 @@ public void setInitialCapacity(int valueCount) {
lastValueCapacity = valueCount;
}
- /**
- * Get the current value capacity for the vector.
- *
- * @return number of elements that vector can hold.
- */
@Override
- public int getValueCapacity() {
+ protected void refreshValueCapacity() {
Review comment:
I see. Thanks.
The fundamental reason is that `getValueBufferValueCapacity` is declared
private, so the sub-class is not overriding the one in the super class.
How about we make it protected (as the sub-class is actually overriding the
behavior of the super class), so no longer have to override
`refreshValueCapacity` here?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]