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

SNOW-1818018: add functions.size, collect_list #2677

Merged
merged 6 commits into from
Nov 27, 2024

Conversation

sfc-gh-aalam
Copy link
Contributor

@sfc-gh-aalam sfc-gh-aalam commented Nov 25, 2024

  1. Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-1818018, SNOW-1825962

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
      • If this test skips Local Testing mode, I'm requesting review from @snowflakedb/local-testing
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am adding new credentials
    • I am adding a new dependency
    • If this is a new feature/behavior, I'm adding the Local Testing parity changes.
    • I acknowledge that I have ensured my changes to be thread-safe. Follow the link for more information: Thread-safe Developer Guidelines
  3. 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 to functions.array_agg.

@sfc-gh-aalam sfc-gh-aalam changed the title SNOW-1818018: add functions.size SNOW-1818018: add functions.size, collect_list Nov 25, 2024
Comment on lines 5875 to 5880
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()})")
)
Copy link
Contributor

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?

Copy link
Contributor Author

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

@sfc-gh-azwiegincew sfc-gh-azwiegincew added the snowpark-ast Change materially affects the Snowpark AST label Nov 27, 2024
"""
c = _to_col_if_str(col, "size")
v = to_variant(c)
return (
Copy link
Contributor

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.

@@ -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:
Copy link
Contributor

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.

Copy link
Contributor Author

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()
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@sfc-gh-lspiegelberg sfc-gh-lspiegelberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sfc-gh-aalam sfc-gh-aalam merged commit 8f080c8 into main Nov 27, 2024
40 checks passed
@sfc-gh-aalam sfc-gh-aalam deleted the aalam-SNOW-1818018-api-coverage-size branch November 27, 2024 22:43
@github-actions github-actions bot locked and limited conversation to collaborators Nov 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
snowpark-ast Change materially affects the Snowpark AST
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants