mapleFU commented on code in PR #55449:
URL: https://github.com/apache/arrow/pull/55449#discussion_r4681155678
##########
cpp/src/arrow/util/alp/alp_metadata.cc:
##########
@@ -102,24 +102,23 @@ Status ValidateVectorInfo(const AlpInfo& alp_info, const
AlpForInfo<T>& for_info
return Status::OK();
}
-// Exception positions index the output and the encoder writes them in order,
so
-// they must be increasing and inside the vector. A repeated position would
make
-// the patch step write the same slot twice and leave another slot untouched.
-Status ValidateExceptionPositions(
+// Exception positions index the output and must be inside the vector. The wire
+// format does not require positions to be sorted or unique.
+Result<bool> ValidateExceptionPositions(
std::span<const AlpFormatConstants::PositionType> exception_positions,
int32_t num_elements) {
+ bool strictly_increasing = true;
for (size_t i = 0; i < exception_positions.size(); ++i) {
const AlpFormatConstants::PositionType position = exception_positions[i];
if (position >= num_elements) {
return Status::Invalid("ALP exception position ", position,
" is outside a vector of ", num_elements, "
elements");
}
- if (i > 0 && position <= exception_positions[i - 1]) {
- return Status::Invalid("ALP exception positions must increase, but got ",
- exception_positions[i - 1], " then ", position);
+ if (i > 0 && exception_positions[i] <= exception_positions[i - 1]) {
+ strictly_increasing = false;
}
}
- return Status::OK();
+ return strictly_increasing;
Review Comment:
```suggestion
Result<bool> ValidateExceptionPositions(
std::span<const AlpFormatConstants::PositionType> exception_positions,
int32_t num_elements) {
if (exception_positions.empty()) {
return true;
}
AlpFormatConstants::PositionType max_pos = exception_positions[0];
uint8_t strictly_increasing = 1;
for (size_t i = 1; i < exception_positions.size(); ++i) {
const auto pos = exception_positions[i];
max_pos = std::max(max_pos, pos);
strictly_increasing &= static_cast<uint8_t>(pos >
exception_positions[i - 1]);
}
if (ARROW_PREDICT_FALSE(max_pos >= num_elements)) {
for (const auto pos : exception_positions) {
if (pos >= num_elements) {
return Status::Invalid("ALP exception position ", pos,
" is outside a vector of ", num_elements, "
elements");
}
}
}
return strictly_increasing != 0;
}
```
Can we optimize like this or otherway that we can vectorizing the checking?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]