You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/01/31 18:15:07 UTC

[GitHub] [arrow-datafusion] alamb opened a new issue #1718: Cleaner API to create `Expr::ScalarFunction` programatically

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


   **Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
   I am trying to programatically create `Expr`s that represent function calls, for example `to_timetsamp(x, 4)` or something
   
   To do so today you have to do something like this (from simplify_expressions.rs)  which is ๐Ÿคฎ 
   
   ```rust
           // to_timestamp("2020-09-08T12:00:00+00:00")
           let expr = Expr::ScalarFunction {
               args: vec![lit("2020-09-08T12:00:00+00:00")],
               fun: BuiltinScalarFunction::ToTimestamp,
           };
   ```
   
   
   **Describe the solution you'd like**
   I would like to write code like this
   
   ```rust
           // to_timestamp("2020-09-08T12:00:00+00:00") --> timestamp(1599566400000000000i64)
           let expr = call("to_timestamp", vec![lit("2020-09-08T12:00:00+00:00")])
             .unwrap();
   ```rust
   
   Perhap with an api like this
   
   ```rust
   /// Calls a named built in function
   ///
   /// ```
   /// use datafusion::logical_plan::*;
   ///
   /// // create the expression sin(x) < 0.2
   /// let expr = call("sin", vec![col("x")]).unwrap().lt(lit(0.2));
   ///
   /// ```
   pub fn call(name: impl AsRef<str>, args: Vec<Expr>) -> Result<Expr> {
   ...
   }
   ```
   
   Note you can lookup a  `str` to scalar function by name with something like:
   ```rust
       let fun = name.as_ref().parse::<BuiltinScalarFunction>()?;
   ```
   
   
   **Additional context**
   There are a bunch of this nonsense in `simplify_expression.rs` which could be cleaned up 


-- 
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



[GitHub] [arrow-datafusion] HaoYang670 commented on issue #1718: Cleaner API to create `Expr::ScalarFunction` programatically

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on issue #1718:
URL: https://github.com/apache/arrow-datafusion/issues/1718#issuecomment-1027956420


   I find some duplicate tests in `simplify_expression.rs`.
   Tracked in issue #1727


-- 
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



[GitHub] [arrow-datafusion] mkmik commented on issue #1718: Cleaner API to create `Expr::ScalarFunction` programatically

Posted by GitBox <gi...@apache.org>.
mkmik commented on issue #1718:
URL: https://github.com/apache/arrow-datafusion/issues/1718#issuecomment-1026600323


   @HaoYang670 thanks


-- 
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



[GitHub] [arrow-datafusion] alamb closed issue #1718: Cleaner API to create `Expr::ScalarFunction` programatically

Posted by GitBox <gi...@apache.org>.
alamb closed issue #1718:
URL: https://github.com/apache/arrow-datafusion/issues/1718


   


-- 
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



[GitHub] [arrow-datafusion] alamb commented on issue #1718: Cleaner API to create `Expr::ScalarFunction` programatically

Posted by GitBox <gi...@apache.org>.
alamb commented on issue #1718:
URL: https://github.com/apache/arrow-datafusion/issues/1718#issuecomment-1026239024


   > call_builtin_scalar_fn!(ToTimestamp, lit("2020-09-08T12:00:00+00:00"))
   
   That would have the upside that the compiler could check the name
   
   It has the downside that the user has to know the mapping from the sql level name (e.g. `concat` to `Concat`) which maybe isn't a big deal.
   
   Perhaps we could do both ๐Ÿค” 


-- 
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



[GitHub] [arrow-datafusion] HaoYang670 commented on issue #1718: Cleaner API to create `Expr::ScalarFunction` programatically

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on issue #1718:
URL: https://github.com/apache/arrow-datafusion/issues/1718#issuecomment-1026316199


   I'd like to have a try if no one has been doing it๐Ÿ˜€


-- 
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



[GitHub] [arrow-datafusion] mkmik commented on issue #1718: Cleaner API to create `Expr::ScalarFunction` programatically

Posted by GitBox <gi...@apache.org>.
mkmik commented on issue #1718:
URL: https://github.com/apache/arrow-datafusion/issues/1718#issuecomment-1026140299


   What about something like:
   
   ```
   call_builtin_scalar_fn!(ToTimestamp, lit("2020-09-08T12:00:00+00:00"))
   ```


-- 
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