File tree Expand file tree Collapse file tree
native/spark-expr/src/conversion_funcs Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515// specific language governing permissions and limitations
1616// under the License.
1717
18- use crate :: SparkResult ;
18+ use crate :: { SparkError , SparkResult } ;
1919use arrow:: array:: { ArrayRef , AsArray , Decimal128Array } ;
2020use arrow:: datatypes:: DataType ;
2121use std:: sync:: Arc ;
@@ -40,7 +40,22 @@ pub fn cast_boolean_to_decimal(
4040 . iter ( )
4141 . map ( |v| v. map ( |b| if b { scaled_val } else { 0 } ) )
4242 . collect ( ) ;
43- Ok ( Arc :: new ( result. with_precision_and_scale ( precision, scale) ?) )
43+
44+ // Convert Arrow decimal overflow errors to SparkError
45+ let decimal_array = result
46+ . with_precision_and_scale ( precision, scale)
47+ . map_err ( |e| {
48+ if matches ! ( e, arrow:: error:: ArrowError :: InvalidArgumentError ( _) )
49+ && e. to_string ( ) . contains ( "too large to store in a Decimal128" )
50+ {
51+ // Use the scaled value as it's the only non-zero value that could overflow
52+ crate :: error:: decimal_overflow_error ( scaled_val, precision, scale) . into ( )
53+ } else {
54+ SparkError :: Arrow ( Arc :: new ( e) )
55+ }
56+ } ) ?;
57+
58+ Ok ( Arc :: new ( decimal_array) )
4459}
4560
4661#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments