|
19 | 19 | /// when the feature integration-tests is built |
20 | 20 | #[cfg(feature = "integration-tests")] |
21 | 21 | mod tests { |
22 | | - use std::sync::Arc; |
23 | | - |
| 22 | + use arrow::array::{Array, AsArray}; |
24 | 23 | use arrow::datatypes::DataType; |
25 | 24 | use datafusion::common::record_batch; |
26 | 25 | use datafusion::error::{DataFusionError, Result}; |
27 | 26 | use datafusion::logical_expr::{ScalarUDF, ScalarUDFImpl}; |
28 | 27 | use datafusion::prelude::{SessionContext, col}; |
| 28 | + use datafusion_execution::config::SessionConfig; |
| 29 | + use datafusion_expr::lit; |
29 | 30 | use datafusion_ffi::tests::create_record_batch; |
30 | 31 | use datafusion_ffi::tests::utils::get_module; |
| 32 | + use std::sync::Arc; |
31 | 33 |
|
32 | 34 | /// This test validates that we can load an external module and use a scalar |
33 | 35 | /// udf defined in it via the foreign function interface. In this case we are |
@@ -100,4 +102,46 @@ mod tests { |
100 | 102 |
|
101 | 103 | Ok(()) |
102 | 104 | } |
| 105 | + |
| 106 | + #[tokio::test] |
| 107 | + async fn test_config_on_scalar_udf() -> Result<()> { |
| 108 | + let module = get_module()?; |
| 109 | + |
| 110 | + let ffi_udf = |
| 111 | + module |
| 112 | + .create_timezone_udf() |
| 113 | + .ok_or(DataFusionError::NotImplemented( |
| 114 | + "External module failed to implement create_timezone_udf".to_string(), |
| 115 | + ))?(); |
| 116 | + let foreign_udf: Arc<dyn ScalarUDFImpl> = (&ffi_udf).into(); |
| 117 | + |
| 118 | + let udf = ScalarUDF::new_from_shared_impl(foreign_udf); |
| 119 | + |
| 120 | + let ctx = SessionContext::default(); |
| 121 | + |
| 122 | + let df = ctx |
| 123 | + .read_empty()? |
| 124 | + .select(vec![udf.call(vec![lit("a")]).alias("a")])?; |
| 125 | + |
| 126 | + let result = df.collect().await?; |
| 127 | + assert!(result[0].column(0).as_string::<i32>().is_null(0)); |
| 128 | + |
| 129 | + let mut config = SessionConfig::new(); |
| 130 | + config.options_mut().execution.time_zone = Some("AEST".into()); |
| 131 | + |
| 132 | + let ctx = SessionContext::new_with_config(config); |
| 133 | + |
| 134 | + let df = ctx |
| 135 | + .read_empty()? |
| 136 | + .select(vec![udf.call(vec![lit("a")]).alias("a")])?; |
| 137 | + |
| 138 | + let result = df.collect().await?; |
| 139 | + |
| 140 | + assert!(result.len() == 1); |
| 141 | + assert!(!result[0].column(0).as_string::<i32>().is_null(0)); |
| 142 | + let result = result[0].column(0).as_string::<i32>().value(0); |
| 143 | + assert_eq!(result, "AEST"); |
| 144 | + |
| 145 | + Ok(()) |
| 146 | + } |
103 | 147 | } |
0 commit comments