Jefffrey commented on issue #4864:
URL:
https://github.com/apache/arrow-datafusion/issues/4864#issuecomment-1873134653
Running with modified version of example on latest main:
```rust
use datafusion::error::Result;
use datafusion::prelude::*;
use datafusion::{arrow::datatypes::DataType, logical_expr::Volatility};
use datafusion_expr::{
ColumnarValue, ReturnTypeFunction, ScalarFunctionImplementation,
ScalarUDF, Signature,
};
use std::sync::Arc;
pub fn make_int_udf() -> ScalarUDF {
let datetime_components: ScalarFunctionImplementation =
Arc::new(move |args: &[ColumnarValue]| Ok(args[0].clone()));
let return_type: ReturnTypeFunction =
Arc::new(move |_| Ok(Arc::new(DataType::Int64)));
let signature = Signature::exact(vec![DataType::Int64],
Volatility::Immutable);
ScalarUDF::new("int_udf", &signature, &return_type, &datetime_components)
}
#[tokio::main]
async fn main() -> Result<()> {
let ctx = SessionContext::new();
ctx.register_udf(make_int_udf());
// Perform query 1.
dbg!(ctx.sql("SELECT int_udf(1.0)").await?.show().await);
// Perform query 2
dbg!(ctx.sql("SELECT int_udf(1.0 + 0)").await?.show().await);
Ok(())
}
```
Output:
```
[datafusion-examples/examples/simple_udf.rs:44] ctx.sql("SELECT
int_udf(1.0)").await?.show().await = Err(
Context(
"type_coercion",
Plan(
"Coercion from [Float64] to the signature Exact([Int64])
failed.",
),
),
)
[datafusion-examples/examples/simple_udf.rs:47] ctx.sql("SELECT int_udf(1.0
+ 0)").await?.show().await = Err(
Context(
"type_coercion",
Plan(
"Coercion from [Float64] to the signature Exact([Int64])
failed.",
),
),
)
```
Can see both now have consistent behaviour of failing during type coercion.
Probably can close this issue as resolved if this is satisfactory?
cc @alamb @jonmmease
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]