alamb commented on issue #15363: URL: https://github.com/apache/datafusion/issues/15363#issuecomment-2758210504
In general, adding Catalog/Schema information to functions makes sense to me, but I think it would be a non trivial effort > However, suppose I want to register a custom avg for Duration. In that case, it means that I need to re-implement the whole avg function because the new implementation will override the previous one when registered. Another approach could be to implement your own `avg` function as a wrapper around `avg` that called into the provided implementation. For example ```rust /// An average that also supports duration pub struct AvgWithDuration { // standard DataFusion average impmenetation inner: Average } /// implement aggregate udf for new average, call impl AggregateUDFImpl for AvgWithDuration { ... fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> { // handle duration if arg_types[0] == DataType::Duration { Ok(DataType::Duration) } // otherwise, fall back to inner implementation self.inner.return_type(arg_types) } fn accumulator(&self, acc_args: AccumulatorArgs) -> Result<Box<dyn Accumulator>> { // handle duration, with accumulator implemented for Duration if arg_types[0] == DataType::Duration { Ok(Box::new(DurationAccumulator(...)) } // otherwise, fall back to inner implementation self.inner.return_type(arg_types) } ... } ``` -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org