Skip to content

Commit

Permalink
inline writeLong method in decimal256
Browse files Browse the repository at this point in the history
  • Loading branch information
emkornfield committed Oct 21, 2020
1 parent f582b8a commit cfa3513
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,12 @@ public void set(int index, BigDecimal value) {
*/
public void set(int index, long value) {
BitVectorHelper.setBit(validityBuffer, index);
DecimalUtility.writeLongToArrowBufBigDecimal(value, valueBuffer, index);
final long addressOfValue = valueBuffer.memoryAddress() + (long) index * TYPE_WIDTH;
PlatformDependent.putLong(addressOfValue, value);
final long padValue = Long.signum(value) == -1 ? -1L : 0L;
PlatformDependent.putLong(addressOfValue + Long.BYTES, padValue);
PlatformDependent.putLong(addressOfValue + 2 * Long.BYTES, padValue);
PlatformDependent.putLong(addressOfValue + 3 * Long.BYTES, padValue);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,12 @@ public static void writeBigDecimalToArrowBuf(BigDecimal value, ArrowBuf bytebuf,
* Write the given long to the ArrowBuf at the given value index.
*/
public static void writeLongToArrowBuf(long value, ArrowBuf bytebuf, int index) {
final long addressOfValue = bytebuf.memoryAddress() + (long) index * 16;
final long addressOfValue = bytebuf.memoryAddress() + (long) index * DECIMAL_BYTE_LENGTH;
PlatformDependent.putLong(addressOfValue, value);
final long padValue = Long.signum(value) == -1 ? -1L : 0L;
PlatformDependent.putLong(addressOfValue + Long.BYTES, padValue);
}

/**
* Write value to the buffer extending it to 32 bytes at the given index.
*/
public static void writeLongToArrowBufBigDecimal(long value, ArrowBuf bytebuf, int index) {
final long addressOfValue = bytebuf.memoryAddress() + (long) index * 32;
PlatformDependent.putLong(addressOfValue, value);
final long padValue = Long.signum(value) == -1 ? -1L : 0L;
PlatformDependent.putLong(addressOfValue + Long.BYTES, padValue);
PlatformDependent.putLong(addressOfValue + 2 * Long.BYTES, padValue);
PlatformDependent.putLong(addressOfValue + 3 * Long.BYTES, padValue);
}


/**
* Write the given byte array to the ArrowBuf at the given value index. Will throw an
* UnsupportedOperationException if the decimal size is greater than the Decimal vector byte
Expand Down

0 comments on commit cfa3513

Please sign in to comment.