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("ArrowError: {0}.")]
55 Arrow(ArrowError),
56
57 #[error("InternalError: {0}.")]
58 Internal(String),
59}
60
61pub type SparkResult<T> = Result<T, SparkError>;
62
63impl From<ArrowError> for SparkError {
64 fn from(value: ArrowError) -> Self {
65 SparkError::Arrow(value)
66 }
67}
68
69impl From<SparkError> for DataFusionError {
70 fn from(value: SparkError) -> Self {
71 DataFusionError::External(Box::new(value))
72 }
73}