Jefffrey commented on code in PR #18032:
URL: https://github.com/apache/datafusion/pull/18032#discussion_r2501545994
##########
datafusion/functions/src/math/power.rs:
##########
@@ -91,58 +194,209 @@ impl ScalarUDFImpl for PowerFunc {
}
fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
- match arg_types[0] {
- DataType::Int64 => Ok(DataType::Int64),
- _ => Ok(DataType::Float64),
+ // Ok(arg_types[0].clone())
+ let [data_type, _] = take_function_args(self.name(), arg_types)?;
+ match data_type {
+ d if d.is_floating() => Ok(DataType::Float64),
+ d if d.is_integer() => Ok(DataType::Int64),
+ d if is_decimal(data_type) => Ok(d.clone()),
+ // DataType::Decimal32(p, s) => Ok(DataType::Decimal32(*p, *s)),
+ // DataType::Decimal64(p, s) => Ok(DataType::Decimal64(*p, 0)),
+ // DataType::Decimal128(p, s) => Ok(DataType::Decimal128(*p, 0)),
+ // DataType::Decimal256(p, s) => Ok(DataType::Decimal256(*p, 0)),
+ other => exec_err!(
+ "Unsupported data type {other:?} for {} function",
+ self.name()
+ ),
}
}
fn aliases(&self) -> &[String] {
&self.aliases
}
+ fn coerce_types(&self, arg_types: &[DataType]) -> Result<Vec<DataType>> {
Review Comment:
Hopefully #18519 can provide a nicer API for specifying the allowed
arguments; we can look into refactoring in future 👍
--
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]