Skip to content

Commit

Permalink
Support concat_ws
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE committed Nov 29, 2024
1 parent 8ce2d92 commit 193853d
Show file tree
Hide file tree
Showing 8 changed files with 757 additions and 0 deletions.
19 changes: 19 additions & 0 deletions velox/docs/functions/spark/string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ String Functions
If ``n < 0``, the result is an empty string.
If ``n >= 256``, the result is equivalent to chr(``n % 256``).

.. spark:function:: concat_ws(separator, [string/array<string>], ...) -> varchar
Returns the concatenation result for ``string`` and all elements in ``array<string>``, separated
by ``separator``. The type of ``separator`` is VARCHAR. It can take variable number of remaining
arguments, and it allows mixed use of ``string`` and ``array<string>``. Skips NULL argument or
NULL array element during the concatenation. If ``separator`` is NULL, returns NULL, regardless
of the following inputs. For non-NULL ``separator``, if no remaining input or all remaining inputs
are NULL, returns an empty string. ::

SELECT concat_ws('~', 'a', 'b', 'c'); -- 'a~b~c'
SELECT concat_ws('~', ['a', 'b', 'c'], ['d']); -- 'a~b~c~d'
SELECT concat_ws('~', 'a', ['b', 'c']); -- 'a~b~c'
SELECT concat_ws('~', '', [''], ['a', '']); -- '~~a~'
SELECT concat_ws(NULL, 'a'); -- NULL
SELECT concat_ws('~'); -- ''
SELECT concat_ws('~', NULL, [NULL], 'a', 'b'); -- 'a~b'
SELECT concat_ws('~', NULL, NULL); -- ''
SELECT concat_ws('~', [NULL]); -- ''

.. spark:function:: contains(left, right) -> boolean
Returns true if 'right' is found in 'left'. Otherwise, returns false. ::
Expand Down
11 changes: 11 additions & 0 deletions velox/expression/fuzzer/ExpressionFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,17 @@ static const std::unordered_map<
/// them to fuzzer instead of hard-coding signatures here.
getSignaturesForCast(),
},
{
"concat_ws",
std::vector<facebook::velox::exec::FunctionSignaturePtr>{
// Signature: concat_ws (separator, input,...) -> output:
// varchar, varchar, varchar,.. -> varchar
facebook::velox::exec::FunctionSignatureBuilder()
.argumentType("varchar")
.variableArity("varchar")
.returnType("varchar")
.build()},
},
};

static std::unordered_set<std::string> splitNames(const std::string& names) {
Expand Down
1 change: 1 addition & 0 deletions velox/functions/sparksql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ velox_add_library(
ArraySort.cpp
Bitwise.cpp
Comparisons.cpp
ConcatWs.cpp
DecimalArithmetic.cpp
DecimalCompare.cpp
Hash.cpp
Expand Down
Loading

0 comments on commit 193853d

Please sign in to comment.