liukun4515 commented on code in PR #2360:
URL: https://github.com/apache/arrow-rs/pull/2360#discussion_r939977865
##########
arrow/src/datatypes/datatype.rs:
##########
@@ -479,6 +563,76 @@ pub(crate) fn validate_decimal_precision(value: i128,
precision: usize) -> Resul
}
}
+// duplicate code
+#[inline]
+fn singed_cmp_le_bytes(left: &[u8], right: &[u8]) -> Ordering {
+ assert_eq!(
+ left.len(),
+ right.len(),
+ "Can't compare bytes array with different len: {}, {}",
+ left.len(),
+ right.len()
+ );
+ assert_ne!(left.len(), 0, "Can't compare bytes array of length 0");
+ let len = left.len();
+ // the sign bit is 1, the value is negative
+ let left_negative = left[len - 1] >= 0x80_u8;
+ let right_negative = right[len - 1] >= 0x80_u8;
+ if left_negative != right_negative {
+ return match left_negative {
+ true => {
+ // left is negative value
+ // right is positive value
+ Ordering::Less
+ }
+ false => Ordering::Greater,
+ };
+ }
+ for i in 0..len {
+ let l_byte = left[len - 1 - i];
+ let r_byte = right[len - 1 - i];
+ match l_byte.cmp(&r_byte) {
+ Ordering::Less => {
+ return Ordering::Less;
+ }
+ Ordering::Greater => {
+ return Ordering::Greater;
+ }
+ Ordering::Equal => {}
+ }
+ }
+ Ordering::Equal
+}
+
+pub(crate) fn validate_decimal_precision_with_bytes(lt_value: &[u8],
precision: usize) -> Result<i128> {
Review Comment:
will change to Result<()>
--
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]