datafusion_comet_spark_expr/
error.rs1use arrow::error::ArrowError;
19use datafusion::common::DataFusionError;
20
21#[derive(thiserror::Error, Debug)]
22pub enum SparkError {
23 #[error("[CAST_INVALID_INPUT] The value '{value}' of the type \"{from_type}\" cannot be cast to \"{to_type}\" \
26 because it is malformed. Correct the value as per the syntax, or change its target type. \
27 Use `try_cast` to tolerate malformed input and return NULL instead. If necessary \
28 set \"spark.sql.ansi.enabled\" to \"false\" to bypass this error.")]
29 CastInvalidValue {
30 value: String,
31 from_type: String,
32 to_type: String,
33 },
34
35 #[error("[NUMERIC_VALUE_OUT_OF_RANGE] {value} cannot be represented as Decimal({precision}, {scale}). If necessary set \"spark.sql.ansi.enabled\" to \"false\" to bypass this error, and return NULL instead.")]
36 NumericValueOutOfRange {
37 value: String,
38 precision: u8,
39 scale: i8,
40 },
41
42 #[error("[CAST_OVERFLOW] The value {value} of the type \"{from_type}\" cannot be cast to \"{to_type}\" \
43 due to an overflow. Use `try_cast` to tolerate overflow and return NULL instead. If necessary \
44 set \"spark.sql.ansi.enabled\" to \"false\" to bypass this error.")]
45 CastOverFlow {
46 value: String,
47 from_type: String,
48 to_type: String,
49 },
50
51 #[error("[ARITHMETIC_OVERFLOW] {from_type} overflow. If necessary set \"spark.sql.ansi.enabled\" to \"false\" to bypass this error.")]
52 ArithmeticOverflow { from_type: String },
53
54 #[error("[DIVIDE_BY_ZERO] Division by zero. Use `try_divide` to tolerate divisor being 0 and return NULL instead. If necessary set \"spark.sql.ansi.enabled\" to \"false\" to bypass this error.")]
55 DivideByZero,
56
57 #[error("ArrowError: {0}.")]
58 Arrow(ArrowError),
59
60 #[error("InternalError: {0}.")]
61 Internal(String),
62}
63
64pub type SparkResult<T> = Result<T, SparkError>;
65
66impl From<ArrowError> for SparkError {
67 fn from(value: ArrowError) -> Self {
68 SparkError::Arrow(value)
69 }
70}
71
72impl From<SparkError> for DataFusionError {
73 fn from(value: SparkError) -> Self {
74 DataFusionError::External(Box::new(value))
75 }
76}