Skip to content

Commit ed3dd12

Browse files
committed
review comments
1 parent b34ace5 commit ed3dd12

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

cpp/src/arrow/array/array_test.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,12 @@ TEST_F(TestArray, TestMakeArrayOfNull) {
508508
auto req = [](auto type) { return field("", std::move(type), /*nullable=*/false); };
509509

510510
// union with no nullable fields cannot represent a null
511-
ASSERT_RAISES(Invalid, MakeArrayOfNull(dense_union({req(int8())}), length));
511+
ASSERT_RAISES(TypeError, MakeArrayOfNull(dense_union({req(int8())}), length));
512+
// run end encoded with non nullable child cannot represent a null
513+
// (not directly constructible, but not invalid per Columnar.rst)
514+
auto ree = run_end_encoded(int16(), utf8());
515+
const_cast<FieldVector&>(ree->fields())[1] = req(utf8());
516+
ASSERT_RAISES(TypeError, MakeArrayOfNull(ree, length));
512517

513518
// struct with no nullable fields has a top level bitmap and can mask them
514519
ASSERT_OK_AND_ASSIGN(auto s, MakeArrayOfNull(struct_({req(int8())}), length));

cpp/src/arrow/array/util.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ class NullArrayFactory {
387387
// - buffers = []
388388
// - child_data = [nullptr] * type.num_fields()
389389
// - dictionary = nullptr
390-
bool presizing_zero_buffer_;
390+
const bool presizing_zero_buffer_;
391391

392392
NullArrayFactory(const std::shared_ptr<DataType>& type, bool nullable, int64_t length)
393393
: presizing_zero_buffer_{true},
@@ -534,8 +534,8 @@ class NullArrayFactory {
534534
for (auto [field, id] : Zip(type.fields(), type.type_codes())) {
535535
if (field->nullable()) return id;
536536
}
537-
return Status::Invalid("Cannot produce an array of null ", type,
538-
" because no child field is nullable");
537+
return Status::TypeError("Cannot produce an array of null ", type,
538+
" because no child field is nullable");
539539
}
540540

541541
Status Visit(const UnionType& type) {
@@ -576,6 +576,7 @@ class NullArrayFactory {
576576
}
577577

578578
if (type.mode() == UnionMode::DENSE) {
579+
// offsets
579580
out_->buffers.push_back(*zero_buffer_);
580581
}
581582

@@ -613,8 +614,8 @@ class NullArrayFactory {
613614

614615
out_->buffers = {nullptr};
615616
if (!type.field(1)->nullable()) {
616-
return Status::Invalid("Cannot produce an array of null ", type,
617-
" because the values field is not nullable");
617+
return Status::TypeError("Cannot produce an array of null ", type,
618+
" because the values field is not nullable");
618619
}
619620

620621
std::shared_ptr<Array> run_ends, values;

cpp/src/arrow/array/validate.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -581,15 +581,15 @@ struct ValidateArrayImpl {
581581

582582
if (HasValidityBitmap(data.type->id()) && data.buffers[0]) {
583583
// Do not call GetNullCount() as it would also set the `null_count` member
584-
return null_count = data.length -
585-
CountSetBits(data.buffers[0]->data(), data.offset, data.length);
586-
}
587-
588-
if (data.type->storage_id() == Type::NA) {
589-
return null_count = data.length;
584+
null_count =
585+
data.length - CountSetBits(data.buffers[0]->data(), data.offset, data.length);
586+
} else if (data.type->storage_id() == Type::NA) {
587+
null_count = data.length;
588+
} else {
589+
null_count = 0;
590590
}
591591

592-
return null_count = 0;
592+
return null_count;
593593
}
594594

595595
Status ValidateFixedWidthBuffers() {

cpp/src/arrow/type.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,6 @@ class ARROW_EXPORT DataType : public std::enable_shared_from_this<DataType>,
183183
/// \brief Return the type category of the storage type
184184
virtual Type::type storage_id() const { return id_; }
185185

186-
/// \brief Return a reference to the storage type
187-
virtual const DataType& storage_type_ref() const { return *this; }
188-
189186
/// \brief Return the storage type
190187
virtual std::shared_ptr<DataType> storage_type() const { return GetSharedPtr(); }
191188

0 commit comments

Comments
 (0)