andygrove commented on code in PR #756:
URL: https://github.com/apache/datafusion-comet/pull/756#discussion_r1707956931


##########
common/src/main/java/org/apache/comet/vector/CometVector.java:
##########
@@ -115,24 +121,35 @@ private Decimal createDecimal(BigDecimal value, int 
precision, int scale) {
     return dec;
   }
 
+  // bytes.length must be 16
+  public long getLongFromDecimalBytes(byte[] bytes) {
+    assert (bytes.length == 16);
+    // get Long value from the last eight bytes
+    // Use ByteBuffer's fast conversion to long
+    long val = ByteBuffer.wrap(bytes).getLong(8);
+    return val;
+  }
+
   /**
    * Reads a 16-byte byte array which are encoded big-endian for decimal128 
into internal byte
    * array.
    */
   byte[] getBinaryDecimal(int i) {
+    // TODO: consider implementing a zero-copy version
     return copyBinaryDecimal(i, DECIMAL_BYTES);
   }
 
   /** Reads a 16-byte byte array which are encoded big-endian for decimal128. 
*/
   public byte[] copyBinaryDecimal(int i, byte[] dest) {
-    long valueBufferAddress = getValueVector().getDataBuffer().memoryAddress();
-    Platform.copyMemory(
-        null,
-        valueBufferAddress + (long) i * DECIMAL_BYTE_WIDTH,
-        dest,
-        Platform.BYTE_ARRAY_OFFSET,
-        DECIMAL_BYTE_WIDTH);
+    ValueVector vector = getValueVector();
+    // If the index is zero and DECIMAL_BYTES_ALL already has data, we have a 
new
+    // batch of data in the vector's backing buffer. So read it again.

Review Comment:
   Could you expand on why `i==0` means that have new data? I'm not entirely 
clear on why this is the case.



-- 
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.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to