Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/13680#discussion_r74798477
--- Diff:
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeArrayData.java
---
@@ -25,55 +25,57 @@
import org.apache.spark.sql.types.*;
import org.apache.spark.unsafe.Platform;
import org.apache.spark.unsafe.array.ByteArrayMethods;
+import org.apache.spark.unsafe.bitset.BitSetMethods;
import org.apache.spark.unsafe.hash.Murmur3_x86_32;
import org.apache.spark.unsafe.types.CalendarInterval;
import org.apache.spark.unsafe.types.UTF8String;
/**
* An Unsafe implementation of Array which is backed by raw memory instead
of Java objects.
*
- * Each tuple has three parts: [numElements] [offsets] [values]
+ * Each array has four parts: [numElements][null bits][values or
offset][variable length portion]
*
- * The `numElements` is 4 bytes storing the number of elements of this
array.
+ * The `numElements` is 8 bytes storing the number of elements of this
array.
*
- * In the `offsets` region, we store 4 bytes per element, represents the
relative offset (w.r.t. the
- * base address of the array) of this element in `values` region. We can
get the length of this
- * element by subtracting next offset.
- * Note that offset can by negative which means this element is null.
+ * In the `null bits` region, we store 1 bit per element, represents
whether a element has null
+ * Its total size is ceil(numElements / 8) bytes, and it is aligned to
8-byte word boundaries.
*
- * In the `values` region, we store the content of elements. As we can get
length info, so elements
- * can be variable-length.
+ * In the `values or offset` region, we store the content of elements. For
fields that hold
+ * fixed-length primitive types, such as long, double, or int, we store
the value directly
+ * in the field. For fields with non-primitive or variable-length values,
we store a relative
+ * offset (w.r.t. the base address of the array) that points to the
beginning of
+ * the variable-length field into int. It can only be calculated by
knowing the total bytes of
--- End diff --
@cloud-fan It only handle that cases that the length is not aligned to
word, but not handle that the cases that offset is not aligned to word,
otherwise Platform.getLong() could be expensive.
The new format does not perform worse then before, but since we are
touching this part, it's better to get it good now, rather than re-design the
format in future again.
---
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]