You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "bkietz (via GitHub)" <gi...@apache.org> on 2023/07/06 12:15:51 UTC

[GitHub] [arrow] bkietz commented on a diff in pull request #36018: GH-35581: [C++] Store offsets in scalars

bkietz commented on code in PR #36018:
URL: https://github.com/apache/arrow/pull/36018#discussion_r1254352313


##########
cpp/src/arrow/array/data.cc:
##########
@@ -384,26 +382,31 @@ void ArraySpan::FillFromScalar(const Scalar& value) {
       this->child_data[i].FillFromScalar(*scalar.value[i]);
     }
   } else if (is_union(type_id)) {
+    // Dense union needs scratch space to store both offsets and a type code
+    struct UnionScratchSpace {
+      alignas(int64_t) uint8_t type_code;
+      alignas(int64_t) uint8_t offsets[sizeof(int32_t) * 2];
+    };
+    static_assert(sizeof(UnionScratchSpace) <= sizeof(UnionScalar::scratch_space_));
+    auto* union_scratch_space =
+        new (checked_cast<const UnionScalar&>(value).scratch_space_) UnionScratchSpace{};
+
     // First buffer is kept null since unions have no validity vector
     this->buffers[0] = {};
 
-    this->buffers[1].data = reinterpret_cast<uint8_t*>(this->scratch_space);
+    this->buffers[1].data = &union_scratch_space->type_code;
     this->buffers[1].size = 1;
-    int8_t* type_codes = reinterpret_cast<int8_t*>(this->scratch_space);
-    type_codes[0] = checked_cast<const UnionScalar&>(value).type_code;
+    new (&union_scratch_space->type_code)
+        int8_t{checked_cast<const UnionScalar&>(value).type_code};

Review Comment:
   I'll do that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org