Github user kiszk commented on a diff in the pull request:
https://github.com/apache/spark/pull/18014#discussion_r118660658
--- Diff:
sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/OnHeapColumnVector.java
---
@@ -386,6 +425,35 @@ public void putArray(int rowId, int offset, int
length) {
}
@Override
+ public void putArray(int rowId, Object src, int srcOffset, int
dstOffset, int numElements) {
+ DataType et = type;
+ reserve(dstOffset + numElements);
+ if (et == DataTypes.BooleanType || et == DataTypes.ByteType) {
+ Platform.copyMemory(
+ src, srcOffset, byteData, Platform.BYTE_ARRAY_OFFSET + dstOffset,
numElements);
+ } else if (et == DataTypes.BooleanType || et == DataTypes.ByteType) {
+ Platform.copyMemory(
+ src, srcOffset, shortData, Platform.SHORT_ARRAY_OFFSET + dstOffset
* 2, numElements * 2);
+ } else if (et == DataTypes.IntegerType || et == DataTypes.DateType ||
+ DecimalType.is32BitDecimalType(type)) {
+ Platform.copyMemory(
+ src, srcOffset, intData, Platform.INT_ARRAY_OFFSET + dstOffset *
4, numElements * 4);
+ } else if (type instanceof LongType || type instanceof TimestampType ||
+ DecimalType.is64BitDecimalType(type)) {
+ Platform.copyMemory(
+ src, srcOffset, longData, Platform.LONG_ARRAY_OFFSET + dstOffset *
8, numElements * 8);
+ } else if (et == DataTypes.FloatType) {
+ Platform.copyMemory(
+ src, srcOffset, floatData, Platform.FLOAT_ARRAY_OFFSET + dstOffset
* 4, numElements * 4);
+ } else if (et == DataTypes.DoubleType) {
+ Platform.copyMemory(
+ src, srcOffset, doubleData, Platform.DOUBLE_ARRAY_OFFSET +
dstOffset * 8, numElements * 8);
+ } else {
+ throw new RuntimeException("Unhandled " + type);
--- End diff --
Regarding `UnsafeArrayData`, I understood what you are talking about. As
you said, leaf element are not together as shown below.
```
dimension |[0][0 ... n-1] |[1][0 ... n-1] |[2][0 ... n-1]
|
memory |[null bits][elements]|[null bits][elements]|[null
bits][elements]|
```
On the other hand, for `ColumnVector`, IIUC, `ColumnarBatchSuite.String
APIs` uses [single dimension
array](https://github.com/apache/spark/blob/master/sql/core/src/test/scala/org/apache/spark/sql/execution/vectorized/ColumnarBatchSuite.scala#L646-L650).
For the nested array, the following access is required. In this case,
`array0` and `array1` are difference instances. Thus, leaf elements are not
together.
```
val arrayRow0 : ColumnVector.Array = columnVector.getArray(0)
val array0 : ColumnVector.Array = arrayRow0.getArray(0)
val element00 : int = array0.getInt(0)
val array1 : ColumnVector.Array = arrayRow0.getArray(1)
val element01 : int = array1.getInt(1)
```
What do you think?
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]