Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] NumericArray<T> may not initialize values_ when construct #44541

Open
mapleFU opened this issue Oct 28, 2024 · 0 comments
Open

[C++] NumericArray<T> may not initialize values_ when construct #44541

mapleFU opened this issue Oct 28, 2024 · 0 comments

Comments

@mapleFU
Copy link
Member

mapleFU commented Oct 28, 2024

Describe the bug, including details regarding any error messages, version, and platform.

The problem raised from [1]. NumericArray<T> uses values_ as a cache of typed values[2]. This might not being set when calling the PrimitiveArray::PrimitiveArray constructor [3]. The code can be reproduced like:

TEST(TestPrettyPrintArray, TimestampArray) {
  auto array = std::make_shared<TimestampArray>(
      timestamp(TimeUnit::MICRO),
      /*length=*/1, Buffer::FromVector(std::vector<int64_t>{0}));
  auto v0 = array->GetView(0);
  std::cout << v0 << std::endl;
}

This might be fixed with:

diff --git a/cpp/src/arrow/array/array_primitive.h b/cpp/src/arrow/array/array_primitive.h
index 3e2893b7dd..410e8516da 100644
--- a/cpp/src/arrow/array/array_primitive.h
+++ b/cpp/src/arrow/array/array_primitive.h
@@ -103,6 +103,15 @@ class NumericArray : public PrimitiveArray {
                             null_count, offset));
   }
 
+  NumericArray(const std::shared_ptr<DataType>& type, int64_t length,
+                 const std::shared_ptr<Buffer>& data,
+                 const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
+                 int64_t null_count = kUnknownNullCount, int64_t offset = 0): PrimitiveArray(type, length, data, null_bitmap, null_count, offset) {
+      values_ = raw_values_
+                    ? (reinterpret_cast<const value_type*>(raw_values_) + data_->offset)
+                    : NULLPTR;
+  }
+
   const value_type* raw_values() const { return values_; }
 
   value_type Value(int64_t i) const { return values_[i]; }

But I don't know would I missed something.

[1] #44190
[2]

const value_type* values_;

[3]
using PrimitiveArray::PrimitiveArray;

Component(s)

C++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant