@@ -517,35 +517,6 @@ fn create_decimal_type(precision: u8, scale: i8) -> DataType {
517
517
)
518
518
}
519
519
520
- /// Returns the coerced type of applying mathematics operations on decimal types.
521
- /// Two sides of the mathematics operation will be coerced to the same type. Note
522
- /// that we don't coerce the decimal operands in analysis phase, but do it in the
523
- /// execution phase because this is not idempotent.
524
- pub fn coercion_decimal_mathematics_type (
525
- mathematics_op : & Operator ,
526
- left_decimal_type : & DataType ,
527
- right_decimal_type : & DataType ,
528
- ) -> Option < DataType > {
529
- // TODO: Move this logic into kernel implementations
530
- use arrow:: datatypes:: DataType :: * ;
531
- match ( left_decimal_type, right_decimal_type) {
532
- // The promotion rule from spark
533
- // https://github.com/apache/spark/blob/c20af535803a7250fef047c2bf0fe30be242369d/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/DecimalPrecision.scala#L35
534
- ( Decimal128 ( _, _) , Decimal128 ( _, _) ) => match mathematics_op {
535
- Operator :: Plus | Operator :: Minus => decimal_op_mathematics_type (
536
- mathematics_op,
537
- left_decimal_type,
538
- right_decimal_type,
539
- ) ,
540
- Operator :: Divide | Operator :: Modulo => {
541
- get_wider_decimal_type ( left_decimal_type, right_decimal_type)
542
- }
543
- _ => None ,
544
- } ,
545
- _ => None ,
546
- }
547
- }
548
-
549
520
/// Returns the output type of applying mathematics operations on two decimal types.
550
521
/// The rule is from spark. Note that this is different to the coerced type applied
551
522
/// to two sides of the arithmetic operation.
@@ -917,49 +888,17 @@ mod tests {
917
888
DataType :: Decimal128 ( 30 , 15 )
918
889
) ;
919
890
920
- let op = Operator :: Plus ;
921
891
let left_decimal_type = DataType :: Decimal128 ( 10 , 3 ) ;
922
892
let right_decimal_type = DataType :: Decimal128 ( 20 , 4 ) ;
923
- let result = coercion_decimal_mathematics_type (
924
- & op,
925
- & left_decimal_type,
926
- & right_decimal_type,
927
- ) ;
928
- assert_eq ! ( DataType :: Decimal128 ( 21 , 4 ) , result. unwrap( ) ) ;
929
- let op = Operator :: Minus ;
930
- let result = coercion_decimal_mathematics_type (
931
- & op,
932
- & left_decimal_type,
933
- & right_decimal_type,
934
- ) ;
935
- assert_eq ! ( DataType :: Decimal128 ( 21 , 4 ) , result. unwrap( ) ) ;
936
893
let op = Operator :: Multiply ;
937
- let result = coercion_decimal_mathematics_type (
938
- & op,
939
- & left_decimal_type,
940
- & right_decimal_type,
941
- ) ;
942
- assert_eq ! ( None , result) ;
943
894
let result =
944
895
decimal_op_mathematics_type ( & op, & left_decimal_type, & right_decimal_type) ;
945
896
assert_eq ! ( DataType :: Decimal128 ( 31 , 7 ) , result. unwrap( ) ) ;
946
897
let op = Operator :: Divide ;
947
- let result = coercion_decimal_mathematics_type (
948
- & op,
949
- & left_decimal_type,
950
- & right_decimal_type,
951
- ) ;
952
- assert_eq ! ( DataType :: Decimal128 ( 20 , 4 ) , result. unwrap( ) ) ;
953
898
let result =
954
899
decimal_op_mathematics_type ( & op, & left_decimal_type, & right_decimal_type) ;
955
900
assert_eq ! ( DataType :: Decimal128 ( 35 , 24 ) , result. unwrap( ) ) ;
956
901
let op = Operator :: Modulo ;
957
- let result = coercion_decimal_mathematics_type (
958
- & op,
959
- & left_decimal_type,
960
- & right_decimal_type,
961
- ) ;
962
- assert_eq ! ( DataType :: Decimal128 ( 20 , 4 ) , result. unwrap( ) ) ;
963
902
let result =
964
903
decimal_op_mathematics_type ( & op, & left_decimal_type, & right_decimal_type) ;
965
904
assert_eq ! ( DataType :: Decimal128 ( 11 , 4 ) , result. unwrap( ) ) ;
@@ -1228,19 +1167,13 @@ mod tests {
1228
1167
mathematics_op : Operator ,
1229
1168
expected_lhs_type : DataType ,
1230
1169
expected_rhs_type : DataType ,
1231
- expected_coerced_type : Option < DataType > ,
1232
1170
expected_output_type : DataType ,
1233
1171
) {
1234
1172
// The coerced types for lhs and rhs, if any of them is not decimal
1235
1173
let ( lhs_type, rhs_type) = math_decimal_coercion ( & lhs_type, & rhs_type) . unwrap ( ) ;
1236
1174
assert_eq ! ( lhs_type, expected_lhs_type) ;
1237
1175
assert_eq ! ( rhs_type, expected_rhs_type) ;
1238
1176
1239
- // The coerced type of decimal math expression, applied during expression evaluation
1240
- let coerced_type =
1241
- coercion_decimal_mathematics_type ( & mathematics_op, & lhs_type, & rhs_type) ;
1242
- assert_eq ! ( coerced_type, expected_coerced_type) ;
1243
-
1244
1177
// The output type of decimal math expression
1245
1178
let output_type =
1246
1179
decimal_op_mathematics_type ( & mathematics_op, & lhs_type, & rhs_type) . unwrap ( ) ;
@@ -1255,7 +1188,6 @@ mod tests {
1255
1188
Operator :: Plus ,
1256
1189
DataType :: Decimal128 ( 10 , 2 ) ,
1257
1190
DataType :: Decimal128 ( 10 , 2 ) ,
1258
- Some ( DataType :: Decimal128 ( 11 , 2 ) ) ,
1259
1191
DataType :: Decimal128 ( 11 , 2 ) ,
1260
1192
) ;
1261
1193
@@ -1265,7 +1197,6 @@ mod tests {
1265
1197
Operator :: Plus ,
1266
1198
DataType :: Decimal128 ( 10 , 0 ) ,
1267
1199
DataType :: Decimal128 ( 10 , 2 ) ,
1268
- Some ( DataType :: Decimal128 ( 13 , 2 ) ) ,
1269
1200
DataType :: Decimal128 ( 13 , 2 ) ,
1270
1201
) ;
1271
1202
@@ -1275,7 +1206,6 @@ mod tests {
1275
1206
Operator :: Minus ,
1276
1207
DataType :: Decimal128 ( 10 , 0 ) ,
1277
1208
DataType :: Decimal128 ( 10 , 2 ) ,
1278
- Some ( DataType :: Decimal128 ( 13 , 2 ) ) ,
1279
1209
DataType :: Decimal128 ( 13 , 2 ) ,
1280
1210
) ;
1281
1211
@@ -1285,7 +1215,6 @@ mod tests {
1285
1215
Operator :: Multiply ,
1286
1216
DataType :: Decimal128 ( 10 , 0 ) ,
1287
1217
DataType :: Decimal128 ( 10 , 2 ) ,
1288
- None ,
1289
1218
DataType :: Decimal128 ( 21 , 2 ) ,
1290
1219
) ;
1291
1220
@@ -1295,7 +1224,6 @@ mod tests {
1295
1224
Operator :: Divide ,
1296
1225
DataType :: Decimal128 ( 10 , 0 ) ,
1297
1226
DataType :: Decimal128 ( 10 , 2 ) ,
1298
- Some ( DataType :: Decimal128 ( 12 , 2 ) ) ,
1299
1227
DataType :: Decimal128 ( 23 , 11 ) ,
1300
1228
) ;
1301
1229
@@ -1305,7 +1233,6 @@ mod tests {
1305
1233
Operator :: Modulo ,
1306
1234
DataType :: Decimal128 ( 10 , 0 ) ,
1307
1235
DataType :: Decimal128 ( 10 , 2 ) ,
1308
- Some ( DataType :: Decimal128 ( 12 , 2 ) ) ,
1309
1236
DataType :: Decimal128 ( 10 , 2 ) ,
1310
1237
) ;
1311
1238
0 commit comments