|
17 | 17 |
|
18 | 18 | #[cfg(test)] |
19 | 19 | mod tests { |
20 | | - use arrow::datatypes::DataType; |
| 20 | + use arrow::datatypes::{DataType, TimeUnit}; |
21 | 21 | use datafusion::error::Result; |
22 | 22 | use datafusion::execution::session_state::SessionStateBuilder; |
23 | 23 | use datafusion::execution::FunctionRegistry; |
@@ -91,4 +91,68 @@ mod tests { |
91 | 91 |
|
92 | 92 | Ok(()) |
93 | 93 | } |
| 94 | + |
| 95 | + /// Dedicated match arm must honor fail_on_error=true at execution time (#5074). |
| 96 | + #[tokio::test] |
| 97 | + async fn test_make_date_ansi_invalid_input_errors() -> Result<()> { |
| 98 | + let ctx = SessionContext::new(); |
| 99 | + let udf = { |
| 100 | + let session_state = ctx.state(); |
| 101 | + create_comet_physical_fun("make_date", DataType::Date32, &session_state, Some(true))? |
| 102 | + }; |
| 103 | + ctx.register_udf(udf.as_ref().clone()); |
| 104 | + |
| 105 | + let df = ctx.sql("SELECT make_date(2023, 0, 15)").await?; |
| 106 | + let result = df.collect().await; |
| 107 | + assert!( |
| 108 | + result.is_err(), |
| 109 | + "make_date with fail_on_error=true must error on invalid date, got Ok" |
| 110 | + ); |
| 111 | + |
| 112 | + Ok(()) |
| 113 | + } |
| 114 | + |
| 115 | + /// Registry catch-all must fail closed when fail_on_error=true (#5074). |
| 116 | + #[tokio::test] |
| 117 | + async fn test_registry_udf_rejects_fail_on_error() -> Result<()> { |
| 118 | + // SessionContext registers DataFusion built-ins (e.g. acos) used by the catch-all. |
| 119 | + let ctx = SessionContext::new(); |
| 120 | + let session_state = ctx.state(); |
| 121 | + // "acos" is a DataFusion built-in resolved only via the registry catch-all. |
| 122 | + let err = create_comet_physical_fun("acos", DataType::Float64, &session_state, Some(true)); |
| 123 | + assert!( |
| 124 | + err.is_err(), |
| 125 | + "registry UDF must reject fail_on_error=true, got Ok" |
| 126 | + ); |
| 127 | + let msg = err.unwrap_err().to_string(); |
| 128 | + assert!(msg.contains("acos"), "unexpected error message: {msg}"); |
| 129 | + assert!( |
| 130 | + msg.contains("fail_on_error=true"), |
| 131 | + "unexpected error message: {msg}" |
| 132 | + ); |
| 133 | + |
| 134 | + let udf_false = |
| 135 | + create_comet_physical_fun("acos", DataType::Float64, &session_state, Some(false))?; |
| 136 | + assert_eq!(udf_false.name(), "acos"); |
| 137 | + |
| 138 | + let udf_none = create_comet_physical_fun("acos", DataType::Float64, &session_state, None)?; |
| 139 | + assert_eq!(udf_none.name(), "acos"); |
| 140 | + |
| 141 | + // Dedicated match arms that consume the flag still accept fail_on_error=true. |
| 142 | + let make_date = |
| 143 | + create_comet_physical_fun("make_date", DataType::Date32, &session_state, Some(true))?; |
| 144 | + assert_eq!(make_date.name(), "make_date"); |
| 145 | + |
| 146 | + // Spark 4.1+ make_time serde always passes fail_on_error=true; the dedicated arm |
| 147 | + // must accept it even though SparkMakeTime does not take the flag as a constructor arg. |
| 148 | + let make_time = create_comet_physical_fun( |
| 149 | + "make_time", |
| 150 | + DataType::Time64(TimeUnit::Nanosecond), |
| 151 | + &session_state, |
| 152 | + Some(true), |
| 153 | + )?; |
| 154 | + assert_eq!(make_time.name(), "make_time"); |
| 155 | + |
| 156 | + Ok(()) |
| 157 | + } |
94 | 158 | } |
0 commit comments