Add find_first lambda function#18316
Conversation
23c66a6 to
a7e2a12
Compare
presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayFindFunction.java
Outdated
Show resolved
Hide resolved
kaikalur
left a comment
There was a problem hiding this comment.
Also please see if we need these specializations or if we can just use boxed types and write a single method (for example like we do in: ArrayReduceFunction)
There was a problem hiding this comment.
Hmm - you should not need two functions for this, I don't think. Just make it a variadic function and check in the constructor?
There was a problem hiding this comment.
Get an error when trying to combine the two classes to be one, there is the same error in PR #15170 too from the conversation.
presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayFindFunction.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayFindWithOffsetFunction.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/operator/scalar/ArrayFindWithOffsetFunction.java
Outdated
Show resolved
Hide resolved
presto-main/src/test/java/com/facebook/presto/operator/scalar/TestArrayFindFunction.java
Outdated
Show resolved
Hide resolved
a7e2a12 to
16807c4
Compare
Updated the diff. I see that there are some conversations in PR #15170 about boxed type vs. implementing multiple functions regarding performance which ends up in implementing multiple implementations. Should we still keep the same tradeoff here? |
|
Also don't forget to add documentation in the rst file |
7e41b6b to
c52f924
Compare
Discussed with @kaikalur offline, we are to keep it consistent with PR #15170 and implement multiple functions. |
Add document to rst file. |
Add an UDF find for array, which returns the first array element which matches the predicate. Returns null if no match found.
c52f924 to
1ebdab0
Compare
pranjalssh
left a comment
There was a problem hiding this comment.
Dont have strong opinions of 2 vs 1 file. You could write multiple @ScalarFunction annotations but not very clean
Fix #18304.
Add an UDF find for array, which returns the first array element which matches the predicate. Returns null if no match found.
find_first(array(T), function(T, boolean)) -> T
Returns the first element which returns true for
function(T, boolean). Return null if no match found.find_first(array(T), startIndex, function(T, boolean)) -> T
If startIndex>0, find match starting at the startIndex in array until the end of array. If startIndex<0, find match starting
at the absolute(startIndex) counting from last, until the start of array. Array is 1 indexed, startIndex=0 will return exception.
Test plan - (Please fill in how you tested your changes)
Add unit tests.