Skip to content
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

readability improvement for metadata class #275

Merged
merged 2 commits into from
Oct 31, 2022
Merged

Conversation

Renkai
Copy link
Contributor

@Renkai Renkai commented Oct 31, 2022

No description provided.

@Renkai Renkai requested a review from eddyxu October 31, 2022 03:17
}
auto it = std::upper_bound(pb_.batch_offsets().begin(), pb_.batch_offsets().end(), row_index);
if (it == pb_.batch_offsets().end()) {
return ::arrow::Status::IndexError("Row index out of range {} of {}", row_index, len);
}
int32_t bound_idx = std::distance(pb_.batch_offsets().begin(), it);
int32_t bound_idx = std::distance(pb_.batch_offsets().begin(), it) - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the it == batch_offset().begin() ? in such case bound_idx = -1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first value of offsets is always 0, row_index is always not less than 0, so this case should not happen unless we change how offsets works.
https://github.com/eto-ai/lance/blob/861230d0d8186312e18f206fb8262eb919828549/cpp/src/lance/format/metadata.cc#L59

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, got it. It seems line #83 assert is always true as well? lets remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

}
auto it = std::upper_bound(pb_.batch_offsets().begin(), pb_.batch_offsets().end(), row_index);
if (it == pb_.batch_offsets().end()) {
return ::arrow::Status::IndexError("Row index out of range {} of {}", row_index, len);
}
int32_t bound_idx = std::distance(pb_.batch_offsets().begin(), it);
int32_t bound_idx = std::distance(pb_.batch_offsets().begin(), it) - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, got it. It seems line #83 assert is always true as well? lets remove it?

@@ -68,16 +68,19 @@ int32_t Metadata::GetBatchLength(int32_t batch_id) const {

::arrow::Result<std::tuple<int32_t, int32_t>> Metadata::LocateBatch(int32_t row_index) const {
int64_t len = length();
if (len == 0) {
return ::arrow::Status::IndexError(fmt::format("The offsets table is empty"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need fmt::format here

@Renkai Renkai requested a review from eddyxu October 31, 2022 14:44
@Renkai Renkai merged commit f59b7a2 into main Oct 31, 2022
@Renkai Renkai deleted the renkai_fix_metadata branch October 31, 2022 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants