-
Notifications
You must be signed in to change notification settings - Fork 112
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
SNOW-1818018: add functions.size, collect_list #2677
Conversation
src/snowflake/snowpark/functions.py
Outdated
return ( | ||
when(is_array(v), array_size(v)) | ||
.when(is_object(v), array_size(object_keys(v))) | ||
.otherwise(lit(None)) | ||
.alias(f"SIZE({c.get_name()})") | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For expressions like this is there any plan on making them server side functions in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check with SAS and make a request if necessary. This once seems useful
""" | ||
c = _to_col_if_str(col, "size") | ||
v = to_variant(c) | ||
return ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as in #2682 wrt to JIRA, and also using _emit_ast=False
for internal logic calls.
tests/integ/test_function.py
Outdated
@@ -1742,6 +1743,10 @@ def test_array_negative(session): | |||
df.select(array_size([1])).collect() | |||
assert "'ARRAY_SIZE' expected Column or str, got: <class 'list'>" in str(ex_info) | |||
|
|||
with pytest.raises(TypeError) as ex_info: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use instead pytest.raises(TypeError, matches='...')
. You do not need the assert then, much easier to read and maintain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can update them.
with pytest.raises(TypeError) as ex_info: | ||
df.select(size([1])).collect() | ||
assert "'SIZE' expected Column or str, got: <class 'list'>" in str(ex_info) | ||
|
||
with pytest.raises(TypeError) as ex_info: | ||
df.select(array_slice([1], "col1", "col2")).collect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Where are the tests for the new function and all of its code paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they are added as doctests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.
Fixes SNOW-1818018, SNOW-1825962
Fill out the following pre-review checklist:
Please describe how your code solves the related issue.
Add
functions.size
to get size of array, object or map column.Add
functions.collect_list
which is an alias tofunctions.array_agg
.