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

[GitHub] [arrow] felipecrv commented on a diff in pull request #34550: GH-32338: [C++] Add IPC support for Run-End Encoded Arrays

felipecrv commented on code in PR #34550:
URL: https://github.com/apache/arrow/pull/34550#discussion_r1136389111


##########
cpp/src/arrow/array/array_run_end.cc:
##########
@@ -85,6 +86,53 @@ void RunEndEncodedArray::SetData(const std::shared_ptr<ArrayData>& data) {
   values_array_ = MakeArray(this->data()->child_data[1]);
 }
 
+namespace {
+
+template <typename RunEndType>
+Result<std::shared_ptr<Array>> MakeLogicalRunEnds(const RunEndEncodedArray& self,
+                                                  int64_t physical_offset,
+                                                  int64_t physical_length) {
+  using RunEndCType = typename RunEndType::c_type;
+  const auto* run_ends = self.data()->child_data[0]->GetValues<RunEndCType>(1);
+  NumericBuilder<RunEndType> builder;
+  RETURN_NOT_OK(builder.Resize(physical_length));
+  if (physical_length > 0) {
+    for (int64_t i = 0; i < physical_length - 1; i++) {
+      const auto run_end = run_ends[physical_offset + i] - self.offset();
+      DCHECK_LT(run_end, self.length());
+      RETURN_NOT_OK(builder.Append(static_cast<RunEndCType>(run_end)));
+    }
+    DCHECK_GE(run_ends[physical_offset + physical_length - 1] - self.offset(),
+              self.length());
+    RETURN_NOT_OK(builder.Append(static_cast<RunEndCType>(self.length())));
+  }
+  return builder.Finish();
+}
+
+}  // namespace
+
+Result<std::shared_ptr<Array>> RunEndEncodedArray::LogicalRunEnds() const {
+  int64_t physical_offset = FindPhysicalOffset();
+  int64_t physical_length = FindPhysicalLength();
+  DCHECK(data()->child_data[0]->buffers[1]->is_cpu());
+
+  switch (run_ends_array_->type_id()) {
+    case Type::INT16:
+      return MakeLogicalRunEnds<Int16Type>(*this, physical_offset, physical_length);
+    case Type::INT32:
+      return MakeLogicalRunEnds<Int32Type>(*this, physical_offset, physical_length);
+    default:
+      break;
+  }
+  return MakeLogicalRunEnds<Int64Type>(*this, physical_offset, physical_length);

Review Comment:
   In other projects, I've been annoyed by MSVC complaining the function doesn't return a value when all the returns were in the `switch`, but I can change it here if Arrows MSVC warnings aren't so aggressive.



-- 
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