Add support for array_least_frequent UDF#20752
Add support for array_least_frequent UDF#20752NikhilCollooru merged 1 commit intoprestodb:masterfrom
Conversation
|
Codenotify: Notifying subscribers in CODENOTIFY files for diff ed0c6e7...2f66df7.
|
steveburnett
left a comment
There was a problem hiding this comment.
LGTM (docs), with a very small suggestion for consideration.
0f32a30 to
c9e88d0
Compare
presto-main/src/main/java/com/facebook/presto/operator/scalar/sql/ArraySqlFunctions.java
Outdated
Show resolved
Hide resolved
presto-main/src/test/java/com/facebook/presto/operator/scalar/sql/TestArraySqlFunctions.java
Outdated
Show resolved
Hide resolved
8e580e9 to
55b37f2
Compare
presto-main/src/main/java/com/facebook/presto/operator/scalar/sql/ArraySqlFunctions.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Did you try transposing and sorting?
array_sort(TRANSFORM(MAP_ENTRIES(m),(k,v)->(v,k)))
Then you don't need the lambda for the comparison
There was a problem hiding this comment.
Yeah what I'm doing is pretty much same. If we're to remove the lambda then it requires additional transform. This is how its gonna look which is not much different from what we have.
TRANSFORM(SLICE(ARRAY_SORT(TRANSFORM(MAP_ENTRIES(ARRAY_FREQUENCY(REMOVE_NULLS(input))), x -> ROW(x[2], x[1]))), 1, n), x -> x[2])
There was a problem hiding this comment.
yeah it will be good to do a sqlbenchmark to see which is best.
55b37f2 to
e2ffedd
Compare
UDF to return the least frequent eleement of an array
e2ffedd to
2f66df7
Compare
|
[like] Sreeni Viswanadha reacted to your message:
…________________________________
From: Nikhil Collooru ***@***.***>
Sent: Sunday, October 8, 2023 5:57:49 PM
To: prestodb/presto ***@***.***>
Cc: Sreeni Viswanadha ***@***.***>; Comment ***@***.***>
Subject: Re: [prestodb/presto] Add support for array_least_frequent UDF (PR #20752)
Merged #20752 into master. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented. Message ID: <prestodb/presto/pull/20752/issue_event/10584884467@ github. com>
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
ZjQcmQRYFpfptBannerEnd
Merged #20752<#20752> into master.
—
Reply to this email directly, view it on GitHub<#20752 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAPNYAOC2NTU7CGCBE4IK6TX6LSR3AVCNFSM6AAAAAA4JR3TB6VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJQGU4DIOBYGQ2DMNY>.
You are receiving this because you commented.Message ID: ***@***.***>
|


Description
UDF to return the least frequent element of an array
Motivation and Context
Currently there is no easy way to get least frequent element of an array. This change add that support natively.
Test Plan
./mvnw clean install -Dtest=TestArraySqlFunctions -Dmaven.javadoc.skip=true -T1C -fn -pl presto-main== RELEASE NOTES ==
General Changes
Add function :func:
array_least_frequentSELECT ARRAY_LEAST_FREQUENT(ARRAY[1, 2, 2, 3, 3, 3]); -- 1