Michael-J-Ward commented on issue #10424:
URL: https://github.com/apache/datafusion/issues/10424#issuecomment-2105156463

   
   First, I'd like to emphasize that if passing `stride=1` to the UDF worked 
the same as *not* providing a stride in the SQL api, then this would be just 
porcelain / a nicety.  Reposting the example from: 
https://github.com/apache/datafusion/issues/10425
   
   ```sql
   CREATE TEMPORARY VIEW data3 AS VALUES ([1.0, 2.0, 3.0, 3.0]), ([4.0, 5.0, 
3.0]), ([6.0]);
   ❯ select * from data3;
   +----------------------+
   | column1              |
   +----------------------+
   | [1.0, 2.0, 3.0, 3.0] |
   | [4.0, 5.0, 3.0]      |
   | [6.0]                |
   +----------------------+
   ❯ select array_slice(column1, -1, 2) from data3;
   +-----------------------------------------------+
   | array_slice(data3.column1,Int64(-1),Int64(2)) |
   +-----------------------------------------------+
   | []                                            |
   | []                                            |
   | [6.0]                                         |
   +-----------------------------------------------+
   ❯ select array_slice(column1, -1, 2, 1) from data3;
   
   thread 'main' panicked at 
/Users/andy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/arrow-data-51.0.0/src/transform/primitive.rs:31:43:
   range end index 9 out of range for slice of length 8
   ```
   
   Now to this issue, I agree that I like the explicit arguments versus passing 
a `Vec`, and I would *hope* the solution doesn't require keeping two separate 
UDFs.
   
   I created a draft with what I would think is the natural rust solution in 
#10450.  I don't know if this violates some datafusion constraint, but all the 
tests pass.
   
   ```rust
   #[doc = "returns a slice of the array."]
   pub fn array_slice(array: Expr, begin: Expr, end: Expr, stride: 
Option<Expr>) -> Expr {
       if let Some(stride) = stride {
           Expr::ScalarFunction(ScalarFunction::new_udf(
               array_slice_udf(),
               vec![array, begin, end, stride],
           ))
       } else {
           Expr::ScalarFunction(ScalarFunction::new_udf(
               array_slice_udf(),
               vec![array, begin, end],
           ))
       }
   }
   ```
   
   If that is not possible, then a second proposal would be to amend 
`array_slice_inner` w/ some `null` check.
   
   ```rust
       let stride = if args_len == 4 & is_not_null(&args[3]) {
           Some(as_int64_array(&args[3])?)
       } else {
           None
       };
   ```
   
   But again, this is just a nice-to-have if passing `stride=1` worked the same 
as *not* providing it in the SQL API.


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

Reply via email to