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 @@ -49,6 +49,7 @@ public abstract class BaseFixedWidthVector extends BaseValueVector
protected ArrowBuf validityBuffer;
protected ArrowBuf valueBuffer;
protected int valueCount;
protected boolean hasNull;

public BaseFixedWidthVector(final String name, final BufferAllocator allocator,
FieldType fieldType, final int typeWidth) {
Expand All @@ -60,6 +61,7 @@ public BaseFixedWidthVector(final String name, final BufferAllocator allocator,
validityBuffer = allocator.getEmpty();
valueBuffer = allocator.getEmpty();
lastValueCapacity = INITIAL_VALUE_ALLOCATION;
hasNull = true;
}


Expand Down Expand Up @@ -558,6 +560,7 @@ public void transferTo(BaseFixedWidthVector target) {
target.validityBuffer = validityBuffer.transferOwnership(target.allocator).buffer;
target.valueBuffer = valueBuffer.transferOwnership(target.allocator).buffer;
target.valueCount = valueCount;
target.hasNull = hasNull;
clear();
}

Expand Down Expand Up @@ -600,6 +603,7 @@ private void splitAndTransferValidityBuffer(int startIndex, int length,
int offset = startIndex % 8;

if (length > 0) {
target.hasNull = hasNull;
if (offset == 0) {
/* slice */
if (target.validityBuffer != null) {
Expand Down Expand Up @@ -665,7 +669,42 @@ private void splitAndTransferValidityBuffer(int startIndex, int length,
*/
@Override
public int getNullCount() {
return BitVectorHelper.getNullCount(validityBuffer, valueCount);
if (hasNull) {
return BitVectorHelper.getNullCount(validityBuffer, valueCount);
}
return 0;
}

/**
* Set the element at the given index to null.
*
* @param index position of element
*/
public void setNull(int index) {
handleSafe(index);
setNullUnsafe(index);
}


/**
* Set the element at the given index to null without boundary check.
*
* @param index position of element
*/
public void setNullUnsafe(int index) {
// not really needed to set the bit to 0 as long as
// the buffer always starts from 0.
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
setHasNull(true);
}

/**
* Set the flag to indicate if the vector has null.
*
* @param hasNull flag to indicate if the vector has null
*/
public void setHasNull(boolean hasNull) {
this.hasNull = hasNull;
}

/**
Expand Down Expand Up @@ -756,6 +795,10 @@ public boolean isNull(int index) {
* @return 1 if element at given index is not null, 0 otherwise
*/
public int isSet(int index) {
if (!hasNull) {
return 1;
}

final int byteIndex = index >> 3;
final byte b = validityBuffer.getByte(byteIndex);
final int bitIndex = index & 7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public abstract class BaseVariableWidthVector extends BaseValueVector
protected int valueCount;
protected int lastSet;
protected final Field field;
protected boolean hasNull;

public BaseVariableWidthVector(final String name, final BufferAllocator allocator,
FieldType fieldType) {
Expand All @@ -63,6 +64,7 @@ public BaseVariableWidthVector(final String name, final BufferAllocator allocato
offsetBuffer = allocator.getEmpty();
validityBuffer = allocator.getEmpty();
valueBuffer = allocator.getEmpty();
hasNull = true;
}

/* TODO:
Expand Down Expand Up @@ -672,6 +674,7 @@ public TransferPair getTransferPair(BufferAllocator allocator) {
public void transferTo(BaseVariableWidthVector target) {
compareTypes(target, "transferTo");
target.clear();
target.hasNull = hasNull;
target.validityBuffer = validityBuffer.transferOwnership(target.allocator).buffer;
target.valueBuffer = valueBuffer.transferOwnership(target.allocator).buffer;
target.offsetBuffer = offsetBuffer.transferOwnership(target.allocator).buffer;
Expand Down Expand Up @@ -733,6 +736,7 @@ private void splitAndTransferValidityBuffer(int startIndex, int length,
int offset = startIndex % 8;

if (length > 0) {
target.hasNull = hasNull;
if (offset == 0) {
// slice
if (target.validityBuffer != null) {
Expand Down Expand Up @@ -794,7 +798,10 @@ private void splitAndTransferValidityBuffer(int startIndex, int length,
* @return the number of null elements.
*/
public int getNullCount() {
return BitVectorHelper.getNullCount(validityBuffer, valueCount);
if (hasNull) {
return BitVectorHelper.getNullCount(validityBuffer, valueCount);
}
return 0;
}

/**
Expand All @@ -818,13 +825,26 @@ public boolean isNull(int index) {
return (isSet(index) == 0);
}

/**
* Set the flag to indicate if the vector has null.
*
* @param hasNull flag to indicate if the vector has null
*/
public void setHasNull(boolean hasNull) {
this.hasNull = hasNull;
}

/**
* Same as {@link #isNull(int)}.
*
* @param index position of element
* @return 1 if element at given index is not null, 0 otherwise
*/
public int isSet(int index) {
if (!hasNull) {
return 1;
}

final int byteIndex = index >> 3;
final byte b = validityBuffer.getByte(byteIndex);
final int bitIndex = index & 7;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void set(int index, NullableBigIntHolder holder) throws IllegalArgumentEx
BitVectorHelper.setValidityBitToOne(validityBuffer, index);
setValue(index, holder.value);
} else {
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
setNullUnsafe(index);
}
}

Expand Down Expand Up @@ -251,18 +251,6 @@ public void setSafe(int index, BigIntHolder holder) {
set(index, holder);
}

/**
* Set the element at the given index to null.
*
* @param index position of element
*/
public void setNull(int index) {
handleSafe(index);
// not really needed to set the bit to 0 as long as
// the buffer always starts from 0.
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
}

/**
* Store the given value at a particular position in the vector. isSet indicates
* whether the value is NULL or not.
Expand All @@ -274,7 +262,7 @@ public void set(int index, int isSet, long value) {
if (isSet > 0) {
set(index, value);
} else {
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
setNullUnsafe(index);
}
}

Expand Down
15 changes: 2 additions & 13 deletions java/vector/src/main/java/org/apache/arrow/vector/BitVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public int getBufferSize() {
public void splitAndTransferTo(int startIndex, int length, BaseFixedWidthVector target) {
compareTypes(target, "splitAndTransferTo");
target.clear();
target.hasNull = hasNull;
target.validityBuffer = splitAndTransferBuffer(startIndex, length, target,
validityBuffer, target.validityBuffer);
target.valueBuffer = splitAndTransferBuffer(startIndex, length, target,
Expand Down Expand Up @@ -401,18 +402,6 @@ public void setSafe(int index, BitHolder holder) {
set(index, holder);
}

/**
* Set the element at the given index to null.
*
* @param index position of element
*/
public void setNull(int index) {
handleSafe(index);
// not really needed to set the bit to 0 as long as
// the buffer always starts from 0.
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
}

/**
* Store the given value at a particular position in the vector. isSet indicates
* whether the value is NULL or not.
Expand All @@ -425,7 +414,7 @@ public void set(int index, int isSet, int value) {
if (isSet > 0) {
set(index, value);
} else {
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
setNullUnsafe(index);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,6 @@ public void setSafe(int index, DateDayHolder holder) {
set(index, holder);
}

/**
* Set the element at the given index to null.
*
* @param index position of element
*/
public void setNull(int index) {
handleSafe(index);
// not really needed to set the bit to 0 as long as
// the buffer always starts from 0.
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
}

/**
* Store the given value at a particular position in the vector. isSet indicates
* whether the value is NULL or not.
Expand All @@ -276,7 +264,7 @@ public void set(int index, int isSet, int value) {
if (isSet > 0) {
set(index, value);
} else {
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
setNullUnsafe(index);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public void set(int index, NullableDateMilliHolder holder) throws IllegalArgumen
setValue(index, holder.value);
} else {
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
setHasNull(true);
}
}

Expand Down Expand Up @@ -256,18 +257,6 @@ public void setSafe(int index, DateMilliHolder holder) {
set(index, holder);
}

/**
* Set the element at the given index to null.
*
* @param index position of element
*/
public void setNull(int index) {
handleSafe(index);
// not really needed to set the bit to 0 as long as
// the buffer always starts from 0.
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
}

/**
* Store the given value at a particular position in the vector. isSet indicates
* whether the value is NULL or not.
Expand All @@ -280,7 +269,7 @@ public void set(int index, int isSet, long value) {
if (isSet > 0) {
set(index, value);
} else {
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
setNullUnsafe(index);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,18 +438,6 @@ public void setSafe(int index, DecimalHolder holder) {
set(index, holder);
}

/**
* Set the element at the given index to null.
*
* @param index position of element
*/
public void setNull(int index) {
handleSafe(index);
// not really needed to set the bit to 0 as long as
// the buffer always starts from 0.
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
}

/**
* Store the given value at a particular position in the vector. isSet indicates
* whether the value is NULL or not.
Expand All @@ -463,7 +451,7 @@ public void set(int index, int isSet, int start, ArrowBuf buffer) {
if (isSet > 0) {
set(index, start, buffer);
} else {
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
setNullUnsafe(index);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public void set(int index, NullableFixedSizeBinaryHolder holder) {
} else if (holder.isSet > 0) {
set(index, holder.buffer);
} else {
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
setNullUnsafe(index);
}
}

Expand All @@ -317,11 +317,6 @@ public void setSafe(int index, NullableFixedSizeBinaryHolder holder) {
set(index, holder);
}

public void setNull(int index) {
handleSafe(index);
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
}

/**
* Given a data buffer, get the value stored at a particular position
* in the vector.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,6 @@ public void setSafe(int index, Float4Holder holder) {
set(index, holder);
}

/**
* Set the element at the given index to null.
*
* @param index position of element
*/
public void setNull(int index) {
handleSafe(index);
// not really needed to set the bit to 0 as long as
// the buffer always starts from 0.
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
}

/**
* Store the given value at a particular position in the vector. isSet indicates
* whether the value is NULL or not.
Expand All @@ -277,7 +265,7 @@ public void set(int index, int isSet, float value) {
if (isSet > 0) {
set(index, value);
} else {
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
setNullUnsafe(index);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,6 @@ public void setSafe(int index, Float8Holder holder) {
set(index, holder);
}

/**
* Set the element at the given index to null.
*
* @param index position of element
*/
public void setNull(int index) {
handleSafe(index);
// not really needed to set the bit to 0 as long as
// the buffer always starts from 0.
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
}

/**
* Store the given value at a particular position in the vector. isSet indicates
* whether the value is NULL or not.
Expand All @@ -277,7 +265,7 @@ public void set(int index, int isSet, double value) {
if (isSet > 0) {
set(index, value);
} else {
BitVectorHelper.setValidityBit(validityBuffer, index, 0);
setNullUnsafe(index);
}
}

Expand Down
Loading