@@ -233,7 +233,7 @@ pub fn try_cast_types(from: ColumnType, to: ColumnType) -> ColumnOperationResult
233
233
/// Casting can only be supported if the resulting data type is a superset of the input data type.
234
234
/// For example Deciaml(6,1) can be cast to Decimal(7,1), but not vice versa.
235
235
#[ expect( clippy:: missing_panics_doc) ]
236
- pub fn try_scale_cast_types ( from : ColumnType , to : ColumnType ) -> ColumnOperationResult < ( ) > {
236
+ pub fn try_decimal_scale_cast_types ( from : ColumnType , to : ColumnType ) -> ColumnOperationResult < ( ) > {
237
237
match ( from, to) {
238
238
(
239
239
ColumnType :: TinyInt
@@ -1003,6 +1003,7 @@ mod test {
1003
1003
) ) ;
1004
1004
}
1005
1005
1006
+ #[ expect( clippy:: too_many_lines) ]
1006
1007
#[ test]
1007
1008
fn we_can_properly_determine_if_types_are_scale_castable ( ) {
1008
1009
for from in [
@@ -1016,84 +1017,118 @@ mod test {
1016
1017
let from_precision = Precision :: new ( from. precision_value ( ) . unwrap ( ) ) . unwrap ( ) ;
1017
1018
let two_prec = Precision :: new ( 2 ) . unwrap ( ) ;
1018
1019
let forty_prec = Precision :: new ( 40 ) . unwrap ( ) ;
1019
- try_scale_cast_types ( from, ColumnType :: Decimal75 ( two_prec, 0 ) ) . unwrap_err ( ) ;
1020
- try_scale_cast_types ( from, ColumnType :: Decimal75 ( two_prec, -1 ) ) . unwrap_err ( ) ;
1021
- try_scale_cast_types ( from, ColumnType :: Decimal75 ( two_prec, 1 ) ) . unwrap_err ( ) ;
1022
- try_scale_cast_types ( from, ColumnType :: Decimal75 ( from_precision, 0 ) ) . unwrap ( ) ;
1023
- try_scale_cast_types ( from, ColumnType :: Decimal75 ( from_precision, -1 ) ) . unwrap_err ( ) ;
1024
- try_scale_cast_types ( from, ColumnType :: Decimal75 ( from_precision, 1 ) ) . unwrap_err ( ) ;
1025
- try_scale_cast_types ( from, ColumnType :: Decimal75 ( forty_prec, 0 ) ) . unwrap ( ) ;
1026
- try_scale_cast_types ( from, ColumnType :: Decimal75 ( forty_prec, -1 ) ) . unwrap_err ( ) ;
1027
- try_scale_cast_types ( from, ColumnType :: Decimal75 ( forty_prec, 1 ) ) . unwrap ( ) ;
1020
+ try_decimal_scale_cast_types ( from, ColumnType :: Decimal75 ( two_prec, 0 ) ) . unwrap_err ( ) ;
1021
+ try_decimal_scale_cast_types ( from, ColumnType :: Decimal75 ( two_prec, -1 ) ) . unwrap_err ( ) ;
1022
+ try_decimal_scale_cast_types ( from, ColumnType :: Decimal75 ( two_prec, 1 ) ) . unwrap_err ( ) ;
1023
+ try_decimal_scale_cast_types ( from, ColumnType :: Decimal75 ( from_precision, 0 ) ) . unwrap ( ) ;
1024
+ try_decimal_scale_cast_types ( from, ColumnType :: Decimal75 ( from_precision, -1 ) )
1025
+ . unwrap_err ( ) ;
1026
+ try_decimal_scale_cast_types ( from, ColumnType :: Decimal75 ( from_precision, 1 ) )
1027
+ . unwrap_err ( ) ;
1028
+ try_decimal_scale_cast_types ( from, ColumnType :: Decimal75 ( forty_prec, 0 ) ) . unwrap ( ) ;
1029
+ try_decimal_scale_cast_types ( from, ColumnType :: Decimal75 ( forty_prec, -1 ) ) . unwrap_err ( ) ;
1030
+ try_decimal_scale_cast_types ( from, ColumnType :: Decimal75 ( forty_prec, 1 ) ) . unwrap ( ) ;
1028
1031
}
1029
1032
1030
1033
let twenty_prec = Precision :: new ( 20 ) . unwrap ( ) ;
1031
1034
1032
1035
// from_with_negative_scale
1033
1036
let neg_scale = ColumnType :: Decimal75 ( twenty_prec, -3 ) ;
1034
1037
1035
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_prec, -4 ) ) . unwrap_err ( ) ;
1036
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_prec, -3 ) ) . unwrap ( ) ;
1037
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_prec, -2 ) ) . unwrap_err ( ) ;
1038
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_prec, 0 ) ) . unwrap_err ( ) ;
1039
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_prec, 1 ) ) . unwrap_err ( ) ;
1038
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_prec, -4 ) )
1039
+ . unwrap_err ( ) ;
1040
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_prec, -3 ) ) . unwrap ( ) ;
1041
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_prec, -2 ) )
1042
+ . unwrap_err ( ) ;
1043
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_prec, 0 ) ) . unwrap_err ( ) ;
1044
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_prec, 1 ) ) . unwrap_err ( ) ;
1040
1045
1041
1046
let nineteen_prec = Precision :: new ( 19 ) . unwrap ( ) ;
1042
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( nineteen_prec, -4 ) ) . unwrap_err ( ) ;
1043
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( nineteen_prec, -3 ) ) . unwrap_err ( ) ;
1044
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( nineteen_prec, -2 ) ) . unwrap_err ( ) ;
1045
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( nineteen_prec, 0 ) ) . unwrap_err ( ) ;
1046
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( nineteen_prec, 1 ) ) . unwrap_err ( ) ;
1047
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( nineteen_prec, -4 ) )
1048
+ . unwrap_err ( ) ;
1049
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( nineteen_prec, -3 ) )
1050
+ . unwrap_err ( ) ;
1051
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( nineteen_prec, -2 ) )
1052
+ . unwrap_err ( ) ;
1053
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( nineteen_prec, 0 ) )
1054
+ . unwrap_err ( ) ;
1055
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( nineteen_prec, 1 ) )
1056
+ . unwrap_err ( ) ;
1047
1057
1048
1058
let twenty_one_prec = Precision :: new ( 21 ) . unwrap ( ) ;
1049
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_one_prec, -4 ) ) . unwrap_err ( ) ;
1050
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_one_prec, -3 ) ) . unwrap ( ) ;
1051
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_one_prec, -2 ) ) . unwrap ( ) ;
1052
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_one_prec, 0 ) ) . unwrap_err ( ) ;
1053
- try_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_one_prec, 1 ) ) . unwrap_err ( ) ;
1059
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_one_prec, -4 ) )
1060
+ . unwrap_err ( ) ;
1061
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_one_prec, -3 ) )
1062
+ . unwrap ( ) ;
1063
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_one_prec, -2 ) )
1064
+ . unwrap ( ) ;
1065
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_one_prec, 0 ) )
1066
+ . unwrap_err ( ) ;
1067
+ try_decimal_scale_cast_types ( neg_scale, ColumnType :: Decimal75 ( twenty_one_prec, 1 ) )
1068
+ . unwrap_err ( ) ;
1054
1069
1055
1070
// from_with_zero_scale
1056
1071
let zero_scale = ColumnType :: Decimal75 ( twenty_prec, 0 ) ;
1057
1072
1058
- try_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_prec, -1 ) ) . unwrap_err ( ) ;
1059
- try_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_prec, 0 ) ) . unwrap ( ) ;
1060
- try_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_prec, 1 ) ) . unwrap_err ( ) ;
1061
-
1062
- try_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( nineteen_prec, -1 ) ) . unwrap_err ( ) ;
1063
- try_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( nineteen_prec, 0 ) ) . unwrap_err ( ) ;
1064
- try_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( nineteen_prec, 1 ) ) . unwrap_err ( ) ;
1065
- try_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( nineteen_prec, 2 ) ) . unwrap_err ( ) ;
1066
-
1067
- try_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_one_prec, -1 ) ) . unwrap_err ( ) ;
1068
- try_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_one_prec, 0 ) ) . unwrap ( ) ;
1069
- try_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_one_prec, 1 ) ) . unwrap ( ) ;
1070
- try_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_one_prec, 2 ) ) . unwrap_err ( ) ;
1073
+ try_decimal_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_prec, -1 ) )
1074
+ . unwrap_err ( ) ;
1075
+ try_decimal_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_prec, 0 ) ) . unwrap ( ) ;
1076
+ try_decimal_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_prec, 1 ) )
1077
+ . unwrap_err ( ) ;
1078
+
1079
+ try_decimal_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( nineteen_prec, -1 ) )
1080
+ . unwrap_err ( ) ;
1081
+ try_decimal_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( nineteen_prec, 0 ) )
1082
+ . unwrap_err ( ) ;
1083
+ try_decimal_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( nineteen_prec, 1 ) )
1084
+ . unwrap_err ( ) ;
1085
+ try_decimal_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( nineteen_prec, 2 ) )
1086
+ . unwrap_err ( ) ;
1087
+
1088
+ try_decimal_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_one_prec, -1 ) )
1089
+ . unwrap_err ( ) ;
1090
+ try_decimal_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_one_prec, 0 ) )
1091
+ . unwrap ( ) ;
1092
+ try_decimal_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_one_prec, 1 ) )
1093
+ . unwrap ( ) ;
1094
+ try_decimal_scale_cast_types ( zero_scale, ColumnType :: Decimal75 ( twenty_one_prec, 2 ) )
1095
+ . unwrap_err ( ) ;
1071
1096
1072
1097
// from_with_positive_scale
1073
1098
let pos_scale = ColumnType :: Decimal75 ( twenty_prec, 3 ) ;
1074
1099
1075
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_prec, -1 ) ) . unwrap_err ( ) ;
1076
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_prec, 0 ) ) . unwrap_err ( ) ;
1077
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_prec, 2 ) ) . unwrap_err ( ) ;
1078
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_prec, 3 ) ) . unwrap ( ) ;
1079
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_prec, 4 ) ) . unwrap_err ( ) ;
1080
-
1081
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( nineteen_prec, -1 ) ) . unwrap_err ( ) ;
1082
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( nineteen_prec, 0 ) ) . unwrap_err ( ) ;
1083
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( nineteen_prec, 2 ) ) . unwrap_err ( ) ;
1084
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( nineteen_prec, 3 ) ) . unwrap_err ( ) ;
1085
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( nineteen_prec, 4 ) ) . unwrap_err ( ) ;
1086
-
1087
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_one_prec, -1 ) ) . unwrap_err ( ) ;
1088
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_one_prec, 0 ) ) . unwrap_err ( ) ;
1089
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_one_prec, 2 ) ) . unwrap_err ( ) ;
1090
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_one_prec, 3 ) ) . unwrap ( ) ;
1091
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_one_prec, 4 ) ) . unwrap ( ) ;
1092
- try_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_one_prec, 5 ) ) . unwrap_err ( ) ;
1100
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_prec, -1 ) )
1101
+ . unwrap_err ( ) ;
1102
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_prec, 0 ) ) . unwrap_err ( ) ;
1103
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_prec, 2 ) ) . unwrap_err ( ) ;
1104
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_prec, 3 ) ) . unwrap ( ) ;
1105
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_prec, 4 ) ) . unwrap_err ( ) ;
1106
+
1107
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( nineteen_prec, -1 ) )
1108
+ . unwrap_err ( ) ;
1109
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( nineteen_prec, 0 ) )
1110
+ . unwrap_err ( ) ;
1111
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( nineteen_prec, 2 ) )
1112
+ . unwrap_err ( ) ;
1113
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( nineteen_prec, 3 ) )
1114
+ . unwrap_err ( ) ;
1115
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( nineteen_prec, 4 ) )
1116
+ . unwrap_err ( ) ;
1117
+
1118
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_one_prec, -1 ) )
1119
+ . unwrap_err ( ) ;
1120
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_one_prec, 0 ) )
1121
+ . unwrap_err ( ) ;
1122
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_one_prec, 2 ) )
1123
+ . unwrap_err ( ) ;
1124
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_one_prec, 3 ) ) . unwrap ( ) ;
1125
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_one_prec, 4 ) ) . unwrap ( ) ;
1126
+ try_decimal_scale_cast_types ( pos_scale, ColumnType :: Decimal75 ( twenty_one_prec, 5 ) )
1127
+ . unwrap_err ( ) ;
1093
1128
}
1094
1129
1095
1130
#[ test]
1096
1131
fn we_cannot_scale_cast_nonsense_pairings ( ) {
1097
- try_scale_cast_types ( ColumnType :: Int128 , ColumnType :: Boolean ) . unwrap_err ( ) ;
1132
+ try_decimal_scale_cast_types ( ColumnType :: Int128 , ColumnType :: Boolean ) . unwrap_err ( ) ;
1098
1133
}
1099
1134
}
0 commit comments