Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.arrow.vector;

import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.complex.impl.FixedSizeBinaryReaderImpl;
import org.apache.arrow.vector.complex.reader.FieldReader;
Expand Down Expand Up @@ -115,8 +113,8 @@ public MinorType getMinorType() {
*/
public byte[] get(int index) {
assert index >= 0;
if (NULL_CHECKING_ENABLED && isSet(index) == 0) {
throw new IllegalStateException("Value at index is null");
if (isSet(index) == 0) {
return null;
}
final byte[] dst = new byte[byteWidth];
valueBuffer.getBytes(index * byteWidth, dst, 0, byteWidth);
Expand Down Expand Up @@ -149,14 +147,7 @@ public void get(int index, NullableFixedSizeBinaryHolder holder) {
*/
@Override
public byte[] getObject(int index) {
assert index >= 0;
if (isSet(index) == 0) {
return null;
} else {
final byte[] dst = new byte[byteWidth];
valueBuffer.getBytes(index * byteWidth, dst, 0, byteWidth);
return dst;
}
return get(index);
}

public int getByteWidth() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.arrow.vector;

import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.complex.impl.VarBinaryReaderImpl;
import org.apache.arrow.vector.complex.reader.FieldReader;
Expand Down Expand Up @@ -110,8 +108,8 @@ public MinorType getMinorType() {
*/
public byte[] get(int index) {
assert index >= 0;
if (NULL_CHECKING_ENABLED && isSet(index) == 0) {
throw new IllegalStateException("Value at index is null");
if (isSet(index) == 0) {
return null;
}
final int startOffset = getStartOffset(index);
final int dataLength =
Expand All @@ -128,13 +126,7 @@ public byte[] get(int index) {
* @return byte array for non-null element, null otherwise
*/
public byte[] getObject(int index) {
byte[] b;
try {
b = get(index);
} catch (IllegalStateException e) {
return null;
}
return b;
return get(index);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.arrow.vector;

import static org.apache.arrow.vector.NullCheckingForGet.NULL_CHECKING_ENABLED;

import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.complex.impl.VarCharReaderImpl;
import org.apache.arrow.vector.complex.reader.FieldReader;
Expand Down Expand Up @@ -106,8 +104,8 @@ public MinorType getMinorType() {
*/
public byte[] get(int index) {
assert index >= 0;
if (NULL_CHECKING_ENABLED && isSet(index) == 0) {
throw new IllegalStateException("Value at index is null");
if (isSet(index) == 0) {
return null;
}
final int startOffset = getStartOffset(index);
final int dataLength =
Expand All @@ -124,15 +122,12 @@ public byte[] get(int index) {
* @return Text object for non-null element, null otherwise
*/
public Text getObject(int index) {
Text result = new Text();
byte[] b;
try {
b = get(index);
} catch (IllegalStateException e) {
byte[] b = get(index);
if (b == null) {
return null;
} else {
return new Text(b);
}
result.set(b);
return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,10 @@ public void setSetSafeWithInvalidInput() throws Exception {
vector.setSafe(0, largeNullableHolder);
vector.setSafe(0, largeBuf);
}

@Test
public void testGetNull() {
vector.setNull(0);
assertNull(vector.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -906,13 +906,7 @@ public void testNullableVarType1() {

// Ensure null value throws.
boolean b = false;
try {
vector.get(8);
} catch (IllegalStateException e) {
b = true;
} finally {
assertTrue(b);
}
assertNull(vector.get(8));
}
}

Expand Down Expand Up @@ -942,14 +936,7 @@ public void testNullableVarType2() {
assertArrayEquals(Arrays.copyOfRange(STR3, 2, STR3.length), vector.get(6));

// Ensure null value throws.
boolean b = false;
try {
vector.get(7);
} catch (IllegalStateException e) {
b = true;
} finally {
assertTrue(b);
}
assertNull(vector.get(7));
}
}

Expand Down Expand Up @@ -2173,4 +2160,19 @@ public void testSetNullableVarBinaryHolderSafe() {
buf.close();
}
}

@Test
public void testGetNullFromVariableWidthVector() {
try (VarCharVector varCharVector = new VarCharVector("varcharvec", allocator);
VarBinaryVector varBinaryVector = new VarBinaryVector("varbinary", allocator)) {
varCharVector.allocateNew(10, 1);
varBinaryVector.allocateNew(10, 1);

varCharVector.setNull(0);
varBinaryVector.setNull(0);

assertNull(varCharVector.get(0));
assertNull(varBinaryVector.get(0));
}
}
}