Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9203#discussion_r42692096
  
    --- Diff: 
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/UnsafeRowWriter.java
 ---
    @@ -95,41 +99,75 @@ public void alignToWords(int numBytes) {
         }
       }
     
    -  public void writeCompactDecimal(int ordinal, Decimal input, int 
precision, int scale) {
    -    // make sure Decimal object has the same scale as DecimalType
    -    if (input.changePrecision(precision, scale)) {
    -      Platform.putLong(holder.buffer, getFieldOffset(ordinal), 
input.toUnscaledLong());
    -    } else {
    -      setNullAt(ordinal);
    -    }
    +  public void write(int ordinal, boolean value) {
    +    Platform.putBoolean(holder.buffer, getFieldOffset(ordinal), value);
       }
     
    -  public void write(int ordinal, Decimal input, int precision, int scale) {
    -    // grow the global buffer before writing data.
    -    holder.grow(16);
    +  public void write(int ordinal, byte value) {
    +    Platform.putByte(holder.buffer, getFieldOffset(ordinal), value);
    +  }
     
    -    // zero-out the bytes
    -    Platform.putLong(holder.buffer, holder.cursor, 0L);
    -    Platform.putLong(holder.buffer, holder.cursor + 8, 0L);
    +  public void write(int ordinal, short value) {
    +    Platform.putShort(holder.buffer, getFieldOffset(ordinal), value);
    +  }
     
    -    // Make sure Decimal object has the same scale as DecimalType.
    -    // Note that we may pass in null Decimal object to set null for it.
    -    if (input == null || !input.changePrecision(precision, scale)) {
    -      BitSetMethods.set(holder.buffer, startingOffset, ordinal);
    -      // keep the offset for future update
    -      setOffsetAndSize(ordinal, 0L);
    -    } else {
    -      final byte[] bytes = 
input.toJavaBigDecimal().unscaledValue().toByteArray();
    -      assert bytes.length <= 16;
    +  public void write(int ordinal, int value) {
    +    Platform.putInt(holder.buffer, getFieldOffset(ordinal), value);
    +  }
     
    -      // Write the bytes to the variable length portion.
    -      Platform.copyMemory(
    -        bytes, Platform.BYTE_ARRAY_OFFSET, holder.buffer, holder.cursor, 
bytes.length);
    -      setOffsetAndSize(ordinal, bytes.length);
    +  public void write(int ordinal, long value) {
    +    Platform.putLong(holder.buffer, getFieldOffset(ordinal), value);
    +  }
    +
    +  public void write(int ordinal, float value) {
    +    if (Float.isNaN(value)) {
    +      value = Float.NaN;
         }
    +    Platform.putFloat(holder.buffer, getFieldOffset(ordinal), value);
    +  }
     
    -    // move the cursor forward.
    -    holder.cursor += 16;
    +  public void write(int ordinal, double value) {
    +    if (Double.isNaN(value)) {
    +      value = Double.NaN;
    +    }
    +    Platform.putDouble(holder.buffer, getFieldOffset(ordinal), value);
    +  }
    +
    +  public void write(int ordinal, Decimal input, int precision, int scale) {
    +    if (precision <= Decimal.MAX_LONG_DIGITS()) {
    +      // make sure Decimal object has the same scale as DecimalType
    +      if (input.changePrecision(precision, scale)) {
    +        Platform.putLong(holder.buffer, getFieldOffset(ordinal), 
input.toUnscaledLong());
    +      } else {
    +        setNullAt(ordinal);
    +      }
    +    } else {
    +      // grow the global buffer before writing data.
    +      holder.grow(16);
    +
    +      // zero-out the bytes
    +      Platform.putLong(holder.buffer, holder.cursor, 0L);
    +      Platform.putLong(holder.buffer, holder.cursor + 8, 0L);
    +
    +      // Make sure Decimal object has the same scale as DecimalType.
    +      // Note that we may pass in null Decimal object to set null for it.
    +      if (input == null || !input.changePrecision(precision, scale)) {
    --- End diff --
    
    Will do in separate PR


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to