Skip to content

Commit cf4588f

Browse files
committed
fix after rebase
1 parent 669703f commit cf4588f

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

native/spark-expr/src/conversion_funcs/boolean.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use crate::SparkResult;
18+
use crate::{SparkError, SparkResult};
1919
use arrow::array::{ArrayRef, AsArray, Decimal128Array};
2020
use arrow::datatypes::DataType;
2121
use 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)]

0 commit comments

Comments
 (0)