Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Register Spark array_join function #11948

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions velox/docs/functions/spark/array.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ Array Functions

SELECT array_intersect(array(1, 2, 3), array(1, 3, 5)); -- [1,3]

.. function:: array_join(x, delimiter, nullReplacement) -> varchar

Concatenates the elements of the given array using the ``delimiter`` and an optional string to replace nulls.
If no value is set for ``nullReplacement``, any null value is filtered. ::

SELECT array_join(ARRAY ["1", "2", "3"], ",") -- "1,2,3"
SELECT array_join(ARRAY ["1", NULL, "2"], ",") -- "1,2"
SELECT array_join(ARRAY ["1", NULL, "2"], ",", "0") -- "1,0,2"

.. spark:function:: array_max(array(E)) -> E

Returns maximum non-NULL element of the array. Returns NULL if array is empty or all elements are NULL.
Expand Down
16 changes: 16 additions & 0 deletions velox/functions/sparksql/registration/RegisterArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ void registerSparkArrayFunctions(const std::string& prefix) {

namespace sparksql {

inline void registerArrayJoinFunctions(const std::string& prefix) {
registerFunction<
ParameterBinder<ArrayJoinFunction, Varchar>,
Varchar,
Array<Varchar>,
Varchar>({prefix + "array_join"});

registerFunction<
ParameterBinder<ArrayJoinFunction, Varchar>,
Varchar,
Array<Varchar>,
Varchar,
Varchar>({prefix + "array_join"});
}

template <typename T>
inline void registerArrayMinMaxFunctions(const std::string& prefix) {
registerFunction<ArrayMinFunction, T, Array<T>>({prefix + "array_min"});
Expand Down Expand Up @@ -94,6 +109,7 @@ inline void registerArrayRemoveFunctions(const std::string& prefix) {
}

void registerArrayFunctions(const std::string& prefix) {
registerArrayJoinFunctions(prefix);
registerArrayMinMaxFunctions(prefix);
registerArrayRemoveFunctions(prefix);
registerSparkArrayFunctions(prefix);
Expand Down
Loading