-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
GH-44541: [C++] NumericArray<T> should not use ctor from parent directly #44542
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,9 @@ class NumericArray : public PrimitiveArray { | |
using value_type = typename TypeClass::c_type; | ||
using IteratorType = stl::ArrayIterator<NumericArray<TYPE>>; | ||
|
||
explicit NumericArray(const std::shared_ptr<ArrayData>& data) { SetData(data); } | ||
explicit NumericArray(const std::shared_ptr<ArrayData>& data) { | ||
NumericArray::SetData(data); | ||
} | ||
|
||
// Only enable this constructor without a type argument for types without additional | ||
// metadata | ||
|
@@ -99,8 +101,16 @@ class NumericArray : public PrimitiveArray { | |
const std::shared_ptr<Buffer>& data, | ||
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR, | ||
int64_t null_count = kUnknownNullCount, int64_t offset = 0) { | ||
SetData(ArrayData::Make(TypeTraits<T1>::type_singleton(), length, {null_bitmap, data}, | ||
null_count, offset)); | ||
NumericArray::SetData(ArrayData::Make(TypeTraits<T1>::type_singleton(), length, | ||
{null_bitmap, data}, null_count, offset)); | ||
} | ||
|
||
NumericArray(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) { | ||
NumericArray::SetData(ArrayData::Make(std::move(type), length, {null_bitmap, data}, | ||
null_count, offset)); | ||
} | ||
|
||
const value_type* raw_values() const { return values_; } | ||
|
@@ -119,7 +129,7 @@ class NumericArray : public PrimitiveArray { | |
IteratorType end() const { return IteratorType(*this, length()); } | ||
|
||
protected: | ||
using PrimitiveArray::PrimitiveArray; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch 🤔 |
||
NumericArray() : values_(NULLPTR) {} | ||
|
||
void SetData(const std::shared_ptr<ArrayData>& data) { | ||
this->PrimitiveArray::SetData(data); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -585,6 +585,31 @@ TEST_F(TestArray, TestValidateNullCount) { | |
} | ||
} | ||
|
||
TEST_F(TestArray, TestValidValues) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a test case for TimestampArray specifically? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
// GH-44541: The value_ should be valid when construct. | ||
{ | ||
std::vector<int32_t> original_data{1, 2, 3, 4, 5, 6, 7}; | ||
std::shared_ptr<Int32Array> arr = | ||
std::make_shared<Int32Array>(::arrow::int32(), 7, Buffer::Wrap(original_data)); | ||
for (size_t i = 0; i < original_data.size(); ++i) { | ||
EXPECT_TRUE(arr->IsValid(i)); | ||
EXPECT_FALSE(arr->IsNull(i)); | ||
EXPECT_EQ(original_data[i], arr->Value(i)); | ||
} | ||
} | ||
{ | ||
// Test non parameter free type. | ||
std::vector<int64_t> original_data{1, 2, 3, 4, 5, 6, 7}; | ||
std::shared_ptr<TimestampArray> arr = std::make_shared<TimestampArray>( | ||
::arrow::timestamp(TimeUnit::MICRO), 7, Buffer::Wrap(original_data)); | ||
for (size_t i = 0; i < original_data.size(); ++i) { | ||
EXPECT_TRUE(arr->IsValid(i)); | ||
EXPECT_FALSE(arr->IsNull(i)); | ||
EXPECT_EQ(original_data[i], arr->Value(i)); | ||
} | ||
} | ||
} | ||
|
||
void AssertAppendScalar(MemoryPool* pool, const std::shared_ptr<Scalar>& scalar) { | ||
std::unique_ptr<arrow::ArrayBuilder> builder; | ||
auto null_scalar = MakeNullScalar(scalar->type); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
protected
is odd here; nothing inherits from NumericArray inside arrow. Is it intended to support user subclassing of NumericArray? Or could we just mark NumericArray final? @pitrouThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might keep same style from
PrimitiveArray
, which initializesraw_values_
in ctor. Don't know should we change here