Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/20850#discussion_r175407382
--- Diff:
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/UnsafeWriter.java
---
@@ -36,8 +90,92 @@
public abstract void write(int ordinal, float value);
public abstract void write(int ordinal, double value);
public abstract void write(int ordinal, Decimal input, int precision,
int scale);
- public abstract void write(int ordinal, UTF8String input);
- public abstract void write(int ordinal, byte[] input);
- public abstract void write(int ordinal, CalendarInterval input);
- public abstract void setOffsetAndSize(int ordinal, int currentCursor,
int size);
+
+ public final void write(int ordinal, UTF8String input) {
+ final int numBytes = input.numBytes();
+ final int roundedSize =
ByteArrayMethods.roundNumberOfBytesToNearestWord(numBytes);
+
+ // grow the global buffer before writing data.
+ grow(roundedSize);
+
+ zeroOutPaddingBytes(numBytes);
+
+ // Write the bytes to the variable length portion.
+ input.writeToMemory(buffer(), cursor());
+
+ setOffsetAndSize(ordinal, numBytes);
+
+ // move the cursor forward.
+ addCursor(roundedSize);
+ }
+
+ public final void write(int ordinal, byte[] input) {
+ write(ordinal, input, 0, input.length);
+ }
+
+ public final void write(int ordinal, byte[] input, int offset, int
numBytes) {
+ final int roundedSize =
ByteArrayMethods.roundNumberOfBytesToNearestWord(input.length);
+
+ // grow the global buffer before writing data.
+ grow(roundedSize);
+
+ zeroOutPaddingBytes(numBytes);
+
+ // Write the bytes to the variable length portion.
+ Platform.copyMemory(
+ input, Platform.BYTE_ARRAY_OFFSET + offset, buffer(), cursor(),
numBytes);
+
+ setOffsetAndSize(ordinal, numBytes);
+
+ // move the cursor forward.
+ addCursor(roundedSize);
+ }
+
+ public final void write(int ordinal, CalendarInterval input) {
+ // grow the global buffer before writing data.
+ grow(16);
+
+ // Write the months and microseconds fields of Interval to the
variable length portion.
+ Platform.putLong(buffer(), cursor(), input.months);
+ Platform.putLong(buffer(), cursor() + 8, input.microseconds);
+
+ setOffsetAndSize(ordinal, 16);
+
+ // move the cursor forward.
+ addCursor(16);
+ }
+
+ protected final void _write(long offset, boolean value) {
--- End diff --
why the `_write` names? Just call them`writeBoolean` etc...
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]