Add SQL function array_frequency#16198
Conversation
presto-main/src/main/java/com/facebook/presto/operator/scalar/sql/ArrayArithmeticFunctions.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/operator/scalar/sql/ArrayArithmeticFunctions.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/operator/scalar/sql/ArrayArithmeticFunctions.java
Outdated
Show resolved
Hide resolved
...main/src/test/java/com/facebook/presto/operator/scalar/sql/TestArrayArithmeticFunctions.java
Outdated
Show resolved
Hide resolved
...main/src/test/java/com/facebook/presto/operator/scalar/sql/TestArrayArithmeticFunctions.java
Outdated
Show resolved
Hide resolved
7940f8d to
cbe412a
Compare
prithvip
left a comment
There was a problem hiding this comment.
LGTM, other than adding tests and a style nit.
There was a problem hiding this comment.
I think we should also add tests for the empty array case, and for nulls in the array.
There was a problem hiding this comment.
Let's also add test for empty array as @prithvip suggested. array_frequency(cast(array[] as array(bigint). Also, for bigint / varchar, either use all upper case or all lower case. SQL is case in sensitive, I think here you can use all lower case.
...main/src/test/java/com/facebook/presto/operator/scalar/sql/TestArrayArithmeticFunctions.java
Outdated
Show resolved
Hide resolved
39f4b2f to
146ad59
Compare
There was a problem hiding this comment.
Hmm, while this behavior is sort of reasonable, I wonder whether this is expected. @kaikalur what do you think should be the right outcome if the input array only has null elements?
There was a problem hiding this comment.
This seems reasonable (especially because we can't represent null as a key in the result map)
There was a problem hiding this comment.
I changed the code to ignore null elements (can deal with arrays that have both null and non-null elements), so array of nulls now returns an empty map.
|
We also need to update the |
|
For release note, it should end with backquote rather than double quote. |
There was a problem hiding this comment.
lowercase map(bigint, int)
There was a problem hiding this comment.
lowercase map(varchar, int)
Generally we use () rather than <> in type signature.
rongrong
left a comment
There was a problem hiding this comment.
Looks good! One final nit: Please change the commit title to Add SQL function array_frequency (We normally use the verb "add" when adding new features, also upper case first letter)
Test plan - Wrote unit tests to check the function works with varchar and bigints. Can deal with duplicates.
Please make sure your submission complies with our Development, Formatting, and Commit Message guidelines. Don't forget to follow our attribution guidelines for any code copied from other projects.
Fill in the release notes towards the bottom of the PR description.
See Release Notes Guidelines for details.