Skip to content

Commit

Permalink
Merge branch 'feature/test_large_writes' into 'master'
Browse files Browse the repository at this point in the history
Github 41: Add errors for using invalid run info ids

See merge request minknow/pod5-file-format!271
  • Loading branch information
0x55555555 committed Jun 6, 2023
2 parents bbe13df + 21c82d4 commit d89f0b2
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 152 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ All notable changes, updates, and fixes to pod5 will be documented here
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.2] 2023-06-06

### Fixed
- Add API error when adding reads with invalid end reason, pore type or run info.

## [0.2.1] 2023-05-25

### Changed
Expand Down
6 changes: 4 additions & 2 deletions c++/pod5_format/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,8 +1058,10 @@ inline bool load_struct_row_into_read_data(
end_reason_internal = pod5::ReadEndReason::signal_negative;
break;
default:
pod5_set_error(
arrow::Status::Invalid("out of range end reason passed to pod5_add_end_reason"));
pod5_set_error(arrow::Status::Invalid(
"out of range end reason ",
typed_row_data->end_reason[row_id],
" passed to add read"));
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions c++/pod5_format/dictionary_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class POD5_FORMAT_EXPORT DictionaryWriter {
std::shared_ptr<arrow::Array> const & indices);
virtual pod5::Result<std::shared_ptr<arrow::Array>> get_value_array() = 0;
virtual std::size_t item_count() = 0;

bool is_valid(std::size_t value) { return value < item_count(); }
};

} // namespace pod5
5 changes: 4 additions & 1 deletion c++/pod5_format/expandable_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class ExpandableBuffer {

gsl::span<T const> get_data_span() const
{
assert(m_buffer);
if (!m_buffer) {
return {};
}

return gsl::make_span(m_buffer->data(), m_buffer->size()).template as_span<T const>();
}

Expand Down
21 changes: 21 additions & 0 deletions c++/pod5_format/file_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class FileWriterImpl {
return arrow::Status::Invalid("File writer closed, cannot write further data");
}

ARROW_RETURN_NOT_OK(check_read(read_data));

ARROW_ASSIGN_OR_RAISE(
std::vector<std::uint64_t> signal_rows, add_signal(read_data.read_id, signal));

Expand All @@ -103,12 +105,31 @@ class FileWriterImpl {
return arrow::Status::Invalid("File writer closed, cannot write further data");
}

ARROW_RETURN_NOT_OK(check_read(read_data));

// Write read data and signal row entries:
auto read_table_row =
m_read_table_writer->add_read(read_data, signal_rows, signal_duration);
return read_table_row.status();
}

arrow::Status check_read(ReadData const & read_data)
{
if (!m_read_table_dict_writers.run_info_writer->is_valid(read_data.run_info)) {
return arrow::Status::Invalid("Invalid run info passed to add_read");
}

if (!m_read_table_dict_writers.pore_writer->is_valid(read_data.pore_type)) {
return arrow::Status::Invalid("Invalid pore type passed to add_read");
}

if (!m_read_table_dict_writers.end_reason_writer->is_valid(read_data.end_reason)) {
return arrow::Status::Invalid("Invalid end reason passed to add_read");
}

return arrow::Status::OK();
}

pod5::Result<std::vector<SignalTableRowIndex>> add_signal(
boost::uuids::uuid const & read_id,
gsl::span<std::int16_t const> const & signal)
Expand Down
3 changes: 3 additions & 0 deletions c++/pod5_format/read_table_writer_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ arrow::Result<std::shared_ptr<arrow::ArrayData>> get_array_data(
std::size_t expected_length)
{
auto const value_data = builder.get_string_data();
if (!value_data) {
return Status::Invalid("Missing array value data for dictionary");
}

arrow::TypedBufferBuilder<std::int32_t> offset_builder;
auto const & offset_data = builder.get_typed_offset_data();
Expand Down
Loading

0 comments on commit d89f0b2

Please sign in to comment.