aboutsummaryrefslogtreecommitdiff
path: root/unsafe
diff options
context:
space:
mode:
authorNong Li <nong@databricks.com>2016-01-26 17:34:01 -0800
committerReynold Xin <rxin@databricks.com>2016-01-26 17:34:01 -0800
commit555127387accdd7c1cf236912941822ba8af0a52 (patch)
tree1452dd0aedfcffe948bd2454d66fc032e824e62c /unsafe
parent1dac964c1b996d38c65818414fc8401961a1de8a (diff)
downloadspark-555127387accdd7c1cf236912941822ba8af0a52.tar.gz
spark-555127387accdd7c1cf236912941822ba8af0a52.tar.bz2
spark-555127387accdd7c1cf236912941822ba8af0a52.zip
[SPARK-12854][SQL] Implement complex types support in ColumnarBatch
This patch adds support for complex types for ColumnarBatch. ColumnarBatch supports structs and arrays. There is a simple mapping between the richer catalyst types to these two. Strings are treated as an array of bytes. ColumnarBatch will contain a column for each node of the schema. Non-complex schemas consists of just leaf nodes. Structs represent an internal node with one child for each field. Arrays are internal nodes with one child. Structs just contain nullability. Arrays contain offsets and lengths into the child array. This structure is able to handle arbitrary nesting. It has the key property that we maintain columnar throughout and that primitive types are only stored in the leaf nodes and contiguous across rows. For example, if the schema is ``` array<array<int>> ``` There are three columns in the schema. The internal nodes each have one children. The leaf node contains all the int data stored consecutively. As part of this, this patch adds append APIs in addition to the Put APIs (e.g. putLong(rowid, v) vs appendLong(v)). These APIs are necessary when the batch contains variable length elements. The vectors are not fixed length and will grow as necessary. This should make the usage a lot simpler for the writer. Author: Nong Li <nong@databricks.com> Closes #10820 from nongli/spark-12854.
Diffstat (limited to 'unsafe')
-rw-r--r--unsafe/src/main/java/org/apache/spark/unsafe/Platform.java11
1 files changed, 11 insertions, 0 deletions
diff --git a/unsafe/src/main/java/org/apache/spark/unsafe/Platform.java b/unsafe/src/main/java/org/apache/spark/unsafe/Platform.java
index 0d6b215fe5..b29bf6a464 100644
--- a/unsafe/src/main/java/org/apache/spark/unsafe/Platform.java
+++ b/unsafe/src/main/java/org/apache/spark/unsafe/Platform.java
@@ -105,6 +105,17 @@ public final class Platform {
_UNSAFE.freeMemory(address);
}
+ public static long reallocateMemory(long address, long oldSize, long newSize) {
+ long newMemory = _UNSAFE.allocateMemory(newSize);
+ copyMemory(null, address, null, newMemory, oldSize);
+ freeMemory(address);
+ return newMemory;
+ }
+
+ public static void setMemory(long address, byte value, long size) {
+ _UNSAFE.setMemory(address, size, value);
+ }
+
public static void copyMemory(
Object src, long srcOffset, Object dst, long dstOffset, long length) {
// Check if dstOffset is before or after srcOffset to determine if we should copy