Skip to content

Commit

Permalink
ListViewArray: Implement Validate + (TODO: tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrv committed Apr 28, 2023
1 parent b96beeb commit 3204c80
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion cpp/src/arrow/array/validate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "arrow/util/checked_cast.h"
#include "arrow/util/decimal.h"
#include "arrow/util/int_util_overflow.h"
#include "arrow/util/list_view_util.h"
#include "arrow/util/logging.h"
#include "arrow/util/ree_util.h"
#include "arrow/util/utf8.h"
Expand Down Expand Up @@ -429,7 +430,32 @@ struct ValidateArrayImpl {
}

Status Visit(const ListViewType& type) {
return Status::NotImplemented("ListViewType validation not implemented");
if (data.child_data.size() != 1) {
return Status::Invalid("List-view array should have 1 child; this array has ",
data.child_data.size());
}
const auto& values_data = data.child_data[0];
if (!values_data) {
return Status::Invalid("Values array is null pointer");
}
const Status values_valid = RecurseInto(*values_data);
if (!values_valid.ok()) {
return Status::Invalid("Values array invalid: ", values_valid.message());
}

if (data.length > 0) {
if (data.null_count > 0 && data.null_count != data.length) {
return Status::Invalid("List-view array has nulls but no validity bitmap");
}
}

auto status = list_view_util::internal::ValidateBuffers(
data.length, data.buffers, data.offset, values_data->length, NULLPTR,
full_validation);
if (!status.ok()) {
return Status::Invalid("List-view array invalid: ", status.message());
}
return Status::OK();
}

Status Visit(const ExtensionType& type) {
Expand Down

0 comments on commit 3204c80

Please sign in to comment.