Skip to content

Commit acbed51

Browse files
authored
GH-469: Unify ValueVector.getObject and VariableWidthFieldVector.get behavior about null value (#486)
Fixes #469.
1 parent 1d4b757 commit acbed51

File tree

8 files changed

+33
-10
lines changed

8 files changed

+33
-10
lines changed

vector/src/main/java/org/apache/arrow/vector/FixedSizeBinaryVector.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ public void get(int index, NullableFixedSizeBinaryHolder holder) {
149149
*/
150150
@Override
151151
public byte[] getObject(int index) {
152-
return get(index);
152+
if (isSet(index) == 0) {
153+
return null;
154+
}
155+
return get(valueBuffer, index, byteWidth);
153156
}
154157

155158
public int getByteWidth() {

vector/src/main/java/org/apache/arrow/vector/LargeVarBinaryVector.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.arrow.vector;
1818

19+
import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;
20+
1921
import org.apache.arrow.memory.BufferAllocator;
2022
import org.apache.arrow.memory.ReusableBuffer;
2123
import org.apache.arrow.vector.complex.impl.LargeVarBinaryReaderImpl;
@@ -95,7 +97,7 @@ public MinorType getMinorType() {
9597
*/
9698
public byte[] get(int index) {
9799
assert index >= 0;
98-
if (isSet(index) == 0) {
100+
if (NULL_CHECKING_ENABLED && isSet(index) == 0) {
99101
return null;
100102
}
101103
final long startOffset = getStartOffset(index);
@@ -127,7 +129,14 @@ public void read(int index, ReusableBuffer<?> buffer) {
127129
*/
128130
@Override
129131
public byte[] getObject(int index) {
130-
return get(index);
132+
if (isSet(index) == 0) {
133+
return null;
134+
}
135+
final long startOffset = getStartOffset(index);
136+
final long dataLength = getEndOffset(index) - startOffset;
137+
final byte[] result = new byte[(int) dataLength];
138+
valueBuffer.getBytes(startOffset, result, 0, (int) dataLength);
139+
return result;
131140
}
132141

133142
/**

vector/src/main/java/org/apache/arrow/vector/LargeVarCharVector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public Types.MinorType getMinorType() {
101101
@Override
102102
public byte[] get(int index) {
103103
assert index >= 0;
104-
if (isSet(index) == 0) {
104+
if (NULL_CHECKING_ENABLED && isSet(index) == 0) {
105105
return null;
106106
}
107107
final long startOffset = getStartOffset(index);
@@ -120,7 +120,7 @@ public byte[] get(int index) {
120120
@Override
121121
public Text getObject(int index) {
122122
assert index >= 0;
123-
if (NULL_CHECKING_ENABLED && isSet(index) == 0) {
123+
if (isSet(index) == 0) {
124124
return null;
125125
}
126126

vector/src/main/java/org/apache/arrow/vector/ValueVector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public interface ValueVector extends Closeable, Iterable<ValueVector> {
264264
* Get friendly type object from the vector.
265265
*
266266
* @param index index of object to get
267-
* @return friendly type object
267+
* @return friendly type object, null if value is unset
268268
*/
269269
Object getObject(int index);
270270

vector/src/main/java/org/apache/arrow/vector/VarBinaryVector.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,15 @@ public void read(int index, ReusableBuffer<?> buffer) {
128128
*/
129129
@Override
130130
public byte[] getObject(int index) {
131-
return get(index);
131+
if (isSet(index) == 0) {
132+
return null;
133+
}
134+
135+
final int startOffset = getStartOffset(index);
136+
final int dataLength = getEndOffset(index) - startOffset;
137+
final byte[] result = new byte[dataLength];
138+
valueBuffer.getBytes(startOffset, result, 0, dataLength);
139+
return result;
132140
}
133141

134142
/**

vector/src/main/java/org/apache/arrow/vector/VarCharVector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public byte[] get(int index) {
117117
@Override
118118
public Text getObject(int index) {
119119
assert index >= 0;
120-
if (NULL_CHECKING_ENABLED && isSet(index) == 0) {
120+
if (isSet(index) == 0) {
121121
return null;
122122
}
123123

vector/src/main/java/org/apache/arrow/vector/ViewVarBinaryVector.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ public void read(int index, ReusableBuffer<?> buffer) {
122122
*/
123123
@Override
124124
public byte[] getObject(int index) {
125-
return get(index);
125+
if (isSet(index) == 0) {
126+
return null;
127+
}
128+
return getData(index);
126129
}
127130

128131
/**

vector/src/main/java/org/apache/arrow/vector/ViewVarCharVector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public byte[] get(int index) {
115115
@Override
116116
public Text getObject(int index) {
117117
assert index >= 0;
118-
if (NULL_CHECKING_ENABLED && isSet(index) == 0) {
118+
if (isSet(index) == 0) {
119119
return null;
120120
}
121121

0 commit comments

Comments
 (0)