Skip to content

Commit

Permalink
Make all IsNull/IsValid impls follow the same code template
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrv committed Apr 25, 2023
1 parent 5eac50e commit 84d4716
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
6 changes: 2 additions & 4 deletions cpp/src/arrow/array/array_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ class ARROW_EXPORT Array {
// a potential inner-branch removal.
if (type_id() == Type::SPARSE_UNION) {
return !internal::IsNullSparseUnion(*data_, i);
}
if (type_id() == Type::DENSE_UNION) {
} else if (type_id() == Type::DENSE_UNION) {
return !internal::IsNullDenseUnion(*data_, i);
}
if (type_id() == Type::RUN_END_ENCODED) {
} else if (type_id() == Type::RUN_END_ENCODED) {
return !internal::IsNullRunEndEncoded(*data_, i);
}
return data_->null_count != data_->length;
Expand Down
31 changes: 13 additions & 18 deletions cpp/src/arrow/array/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,18 @@ struct ARROW_EXPORT ArrayData {

std::shared_ptr<ArrayData> Copy() const { return std::make_shared<ArrayData>(*this); }

bool IsNull(int64_t i) const { return !IsValid(i); }
inline bool IsNull(int64_t i) const { return !IsValid(i); }

bool IsValid(int64_t i) const {
inline bool IsValid(int64_t i) const {
if (buffers[0] != NULLPTR) {
return bit_util::GetBit(buffers[0]->data(), i + offset);
}
const auto type = this->type->id();
if (type == Type::SPARSE_UNION) {
return !internal::IsNullSparseUnion(*this, i);
}
if (type == Type::DENSE_UNION) {
} else if (type == Type::DENSE_UNION) {
return !internal::IsNullDenseUnion(*this, i);
}
if (type == Type::RUN_END_ENCODED) {
} else if (type == Type::RUN_END_ENCODED) {
return !internal::IsNullRunEndEncoded(*this, i);
}
return null_count.load() != length;
Expand Down Expand Up @@ -434,19 +432,16 @@ struct ARROW_EXPORT ArraySpan {
inline bool IsValid(int64_t i) const {
if (this->buffers[0].data != NULLPTR) {
return bit_util::GetBit(this->buffers[0].data, i + this->offset);
} else {
const auto type = this->type->id();
if (type == Type::SPARSE_UNION) {
return !IsNullSparseUnion(i);
}
if (type == Type::DENSE_UNION) {
return !IsNullDenseUnion(i);
}
if (type == Type::RUN_END_ENCODED) {
return !IsNullRunEndEncoded(i);
}
return this->null_count != this->length;
}
const auto type = this->type->id();
if (type == Type::SPARSE_UNION) {
return !IsNullSparseUnion(i);
} else if (type == Type::DENSE_UNION) {
return !IsNullDenseUnion(i);
} else if (type == Type::RUN_END_ENCODED) {
return !IsNullRunEndEncoded(i);
}
return this->null_count != this->length;
}

std::shared_ptr<ArrayData> ToArrayData() const;
Expand Down

0 comments on commit 84d4716

Please sign in to comment.