buraksenn commented on code in PR #13130:
URL: https://github.com/apache/datafusion/pull/13130#discussion_r1827463778
##########
datafusion/functions/src/datetime/from_unixtime.rs:
##########
@@ -59,28 +63,63 @@ impl ScalarUDFImpl for FromUnixtimeFunc {
&self.signature
}
+ fn return_type_from_exprs(
+ &self,
+ args: &[Expr],
+ _schema: &dyn ExprSchema,
+ arg_types: &[DataType],
+ ) -> Result<DataType> {
+ match arg_types.len() {
+ 1 => Ok(Timestamp(Second, None)),
+ 2 => match &args[1] {
+ Expr::Literal(ScalarValue::Utf8(Some(tz))) =>
Ok(Timestamp(Second, Some(Arc::from(tz.to_string())))),
+ _ => exec_err!(
+ "Second argument for `from_unixtime` must be non-null
utf8, received {:?}",
+ arg_types[1]),
+ },
+ _ => exec_err!(
+ "from_unixtime function requires 1 or 2 arguments, got {}",
+ arg_types.len()
+ ),
+ }
+ }
+
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
- Ok(Timestamp(Second, None))
+ internal_err!("return_type should not be called")
Review Comment:
In the docs it says that if `return_type_from_expr` is implemented we should
return internal error so that's why I did this.
https://github.com/buraksenn/datafusion/blob/b7f4db4b56e945944c0448f84c61b6f3b86728f8/datafusion/expr/src/udf.rs#L419-L421:
```
/// What [`DataType`] will be returned by this function, given the types
of
/// the arguments.
///
/// # Notes
///
/// If you provide an implementation for
[`Self::return_type_from_exprs`],
/// DataFusion will not call `return_type` (this function). In this case
it
/// is recommended to return [`DataFusionError::Internal`].
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]