(
attributes: &Attributes,
fallback_size: Option<usize>,
precision_required: bool,
)
| 1057 | } |
| 1058 | |
| 1059 | fn parse_decimal_attributes( |
| 1060 | attributes: &Attributes, |
| 1061 | fallback_size: Option<usize>, |
| 1062 | precision_required: bool, |
| 1063 | ) -> Result<(usize, usize, Option<usize>), ArrowError> { |
| 1064 | let precision = attributes |
| 1065 | .additional |
| 1066 | .get("precision") |
| 1067 | .and_then(|v| v.as_u64()) |
| 1068 | .or(if precision_required { None } else { Some(10) }) |
| 1069 | .ok_or_else(|| ArrowError::ParseError("Decimal requires precision".to_string()))? |
| 1070 | as usize; |
| 1071 | let scale = attributes |
| 1072 | .additional |
| 1073 | .get("scale") |
| 1074 | .and_then(|v| v.as_u64()) |
| 1075 | .unwrap_or(0) as usize; |
| 1076 | let size = attributes |
| 1077 | .additional |
| 1078 | .get("size") |
| 1079 | .and_then(|v| v.as_u64()) |
| 1080 | .map(|s| s as usize) |
| 1081 | .or(fallback_size); |
| 1082 | if precision == 0 { |
| 1083 | return Err(ArrowError::ParseError( |
| 1084 | "Decimal requires precision > 0".to_string(), |
| 1085 | )); |
| 1086 | } |
| 1087 | if scale > precision { |
| 1088 | return Err(ArrowError::ParseError(format!( |
| 1089 | "Decimal has invalid scale > precision: scale={scale}, precision={precision}" |
| 1090 | ))); |
| 1091 | } |
| 1092 | if precision > DECIMAL256_MAX_PRECISION as usize { |
| 1093 | return Err(ArrowError::ParseError(format!( |
| 1094 | "Decimal precision {precision} exceeds maximum supported by Arrow ({})", |
| 1095 | DECIMAL256_MAX_PRECISION |
| 1096 | ))); |
| 1097 | } |
| 1098 | if let Some(sz) = size { |
| 1099 | let max_p = max_precision_for_fixed_bytes(sz).ok_or_else(|| { |
| 1100 | ArrowError::ParseError(format!( |
| 1101 | "Invalid fixed size for decimal: {sz}, must be between 1 and 32 bytes" |
| 1102 | )) |
| 1103 | })?; |
| 1104 | if precision > max_p { |
| 1105 | return Err(ArrowError::ParseError(format!( |
| 1106 | "Decimal precision {precision} exceeds capacity of fixed size {sz} bytes (max {max_p})" |
| 1107 | ))); |
| 1108 | } |
| 1109 | } |
| 1110 | Ok((precision, scale, size)) |
| 1111 | } |
| 1112 | |
| 1113 | #[derive(Debug, Clone, Copy, PartialEq, Eq, AsRefStr)] |
| 1114 | #[strum(serialize_all = "snake_case")] |
no test coverage detected