You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2024/03/30 20:55:44 UTC

[I] Request: Improve Monotoniciy API [arrow-datafusion]

alamb opened a new issue, #9879:
URL: https://github.com/apache/arrow-datafusion/issues/9879

   ### Is your feature request related to a problem or challenge?
   
   While reviewing https://github.com/apache/arrow-datafusion/pull/9869 from @tinfoil-knight I was confused about the [`ScalarUDFImpl::monotonicity`](https://docs.rs/datafusion/latest/datafusion/logical_expr/trait.ScalarUDFImpl.html#method.monotonicity) API
   
   ```rust
   // This function specifies monotonicity behaviors for User defined scalar functions.
   fn monotonicity(&self) -> Result<Option<Vec<Option<bool>>>, DataFusionError> {..}
   ```
   
   The challenge is the cognative complexity of understanding what `Result<Option<Vec<Option<bool>>>` means
   
   The actual code is defined in terms `FuncMonotonicity` https://github.com/apache/arrow-datafusion/blob/57c0bc65280c467ef6f5a498c6e78a616401b286/datafusion/expr/src/signature.rs#L350-L356
   
   However, since it is a typedef it doesn't show up in the Rust docs
   
   
   ### Describe the solution you'd like
   
   An easy to understand Monotonicity API
   
   
   ### Describe alternatives you've considered
   
   
   I think it would be great to have an API like this:
   
   ```rust
   // This function specifies monotonicity behaviors for User defined scalar functions.
   fn monotonicity(&self) -> Result<Monotonicity>, DataFusionError> {..}
   ```
   
   And then we could make `Monotonicity` an enum that captured the relevant data. This would both be easier to understand and likely more efficient as well
   
   Something like
   ```rust
   /// Monotonicity of a function with respect to its arguments.
   ///
   /// A function is [monotonic] if it preserves the relative order of its inputs. 
   ///
   /// [monotonic]: https://en.wikipedia.org/wiki/Monotonic_function
   pub enum Monotonicity {
     /// not monotonic or unknown monotonicity
     None,
     /// Increasing with respect to all of its arguments
     Increasing,
     /// Decreasing with respect to all of its arguments
     Decreasing,
     /// Each element of this vector corresponds to an argument and indicates whether
     /// the function's behavior is monotonic, or non-monotonic/unknown for that argument, namely:
     /// - `None` signifies unknown monotonicity or non-monotonicity.
     /// - `Some(true)` indicates that the function is monotonically increasing w.r.t. the argument in question.
     /// - Some(false) indicates that the function is monotonically decreasing w.r.t. the argument in question.
     Mixed(Vec<bool>),
   }
   ```
   
   I think this would be much eaiser to reason about
   
   
   ### Additional context
   
   _No response_


-- 
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-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Request: Improve Monotoniciy API [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb closed issue #9879: Request: Improve Monotoniciy API
URL: https://github.com/apache/datafusion/issues/9879


-- 
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-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Request: Improve Monotoniciy API [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #9879:
URL: https://github.com/apache/datafusion/issues/9879#issuecomment-2122335700

   https://github.com/apache/datafusion/pull/10504 introduces a new API for boundary propagation, so the API challenge described in this ticket is no longer relevant. Thus closing


-- 
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-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Request: Improve Monotoniciy API [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb closed issue #9879: Request: Improve Monotoniciy API
URL: https://github.com/apache/datafusion/issues/9879


-- 
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-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Request: Improve Monotoniciy API [arrow-datafusion]

Posted by "tinfoil-knight (via GitHub)" <gi...@apache.org>.
tinfoil-knight commented on issue #9879:
URL: https://github.com/apache/arrow-datafusion/issues/9879#issuecomment-2028467872

   take


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org