Skip to content

Commit

Permalink
Make concat_ws_ignore_nulls private (#2718)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-aalam authored Dec 9, 2024
1 parent 91b49f4 commit 0a64ef8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/snowflake/snowpark/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3423,19 +3423,29 @@ def _concat_ws_ignore_nulls(sep: str, *cols: ColumnOrName) -> Column:
|Hello |
----------------------------------------------------
<BLANKLINE>
>>> df.select(_concat_ws_ignore_nulls('--', df.a, df.b, df.c)).show()
-----------------------------------------------------
|"CONCAT_WS_IGNORE_NULLS('--', ""A"",""B"",""C"")" |
-----------------------------------------------------
|Hello--World |
| |
|Hello |
-----------------------------------------------------
<BLANKLINE>
"""
# TODO: SNOW-1831917 create ast
columns = [_to_col_if_str(c, "_concat_ws_ignore_nulls") for c in cols]
names = ",".join([c.get_name() for c in columns])

input_column_array = array_construct_compact(*columns)
reduced_result = builtin("reduce")(
input_column_array = array_construct_compact(*columns, _emit_ast=False)
reduced_result = builtin("reduce", _emit_ast=False)(
input_column_array,
lit(""),
lit("", _emit_ast=False),
sql_expr(f"(l, r) -> l || '{sep}' || r"),
)
return substring(reduced_result, 2).alias(
f"CONCAT_WS_IGNORE_NULLS('{sep}', {names})"
return substring(reduced_result, len(sep) + 1, _emit_ast=False).alias(
f"CONCAT_WS_IGNORE_NULLS('{sep}', {names})", _emit_ast=False
)


Expand Down

0 comments on commit 0a64ef8

Please sign in to comment.