tustvold commented on code in PR #4389:
URL: https://github.com/apache/arrow-rs/pull/4389#discussion_r1225796378
##########
parquet/src/column/writer/mod.rs:
##########
@@ -1152,9 +1213,78 @@ fn compare_greater_byte_array_decimals(a: &[u8], b:
&[u8]) -> bool {
(a[1..]) > (b[1..])
}
+/// Truncate a UTF8 slice to the longest prefix that is still a valid UTF8
string, while being less than `length` bytes.
+fn truncate_utf8(data: &str, length: usize) -> Option<Vec<u8>> {
+ // We return values like that at an earlier stage in the process.
+ assert!(data.len() >= length);
+ let mut char_indices = data.char_indices();
+
+ // We know `data` is a valid UTF8 encoded string, which means it has at
least one valid UTF8 byte, which will make this loop exist.
+ while let Some((idx, c)) = char_indices.next_back() {
+ let split_point = idx + c.len_utf8();
+ if split_point <= length {
+ return data.as_bytes()[0..split_point].to_vec().into();
+ }
+ }
+
+ unreachable!()
+}
+
+/// Truncate a binary slice to make sure its length is less than `length`
+fn truncate_binary(data: &[u8], length: usize) -> Option<Vec<u8>> {
+ // We return values like that at an earlier stage in the process.
+ assert!(data.len() >= length);
+ // If all bytes are already maximal, no need to truncate
+ if data.iter().all(|b| *b == u8::MAX) {
Review Comment:
But that is only because the increment step can't proceed - which is what
will then return `None`?
--
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]