ozankabak commented on code in PR #13841: URL: https://github.com/apache/datafusion/pull/13841#discussion_r1892004788
########## datafusion/expr/src/udf.rs: ########## @@ -652,8 +659,29 @@ pub trait ScalarUDFImpl: Debug + Send + Sync { /// Calculates the [`SortProperties`] of this function based on its /// children's properties. - fn output_ordering(&self, _inputs: &[ExprProperties]) -> Result<SortProperties> { - Ok(SortProperties::Unordered) + fn output_ordering(&self, inputs: &[ExprProperties]) -> Result<SortProperties> { + if !self.output_preserves_lex_ordering(inputs)? { + return Ok(SortProperties::Unordered); + } + + let Some(first_order) = inputs.first().map(|p| &p.sort_properties) else { + return Ok(SortProperties::Unordered); + }; + + if inputs + .iter() + .skip(1) + .all(|input| &input.sort_properties == first_order) + { + Ok(*first_order) + } else { + Ok(SortProperties::Unordered) + } + } + + /// Whether the function preserves lexicographical ordering based on the input ordering + fn output_preserves_lex_ordering(&self, _inputs: &[ExprProperties]) -> Result<bool> { Review Comment: Seems like you don't need the `output_` prefix, just `preserves_lex_ordering` is enough. ########## datafusion/expr/src/udf.rs: ########## @@ -809,6 +837,10 @@ impl ScalarUDFImpl for AliasedScalarUDFImpl { self.inner.output_ordering(inputs) } + fn output_preserves_lex_ordering(&self, inputs: &[ExprProperties]) -> Result<bool> { Review Comment: Seems like you don't need the `output_` prefix, just `preserves_lex_ordering` is enough. -- 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