Skip to content

SNOW-3152139: Create UDF_init_once decorator in python client#4269

Merged
sfc-gh-aling merged 10 commits into
mainfrom
niranjan-sharma-udf-init-once
Jul 2, 2026
Merged

SNOW-3152139: Create UDF_init_once decorator in python client#4269
sfc-gh-aling merged 10 commits into
mainfrom
niranjan-sharma-udf-init-once

Conversation

@sfc-gh-nirsharma

@sfc-gh-nirsharma sfc-gh-nirsharma commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

SNOW-3152139: Create UDF_init_once decorator in python client

What
Adds the udf_init_once decorator to snowflake.snowpark.functions, providing a client-side definition that matches the server-side _snowflake.udf_init_once API.
Why
The @udf_init_once decorator allows users to mark zero-argument functions for one-time execution during pre-fork initialization on Snowflake workers. Initialized state (e.g., loaded models, computed lookup tables) is shared across all workers via Copy-On-Write. This avoids redundant initialization in each worker process.

  1. 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
    • If adding any arguments to public Snowpark APIs or creating new public Snowpark APIs, I acknowledge that I have ensured my changes include AST support. Follow the link for more information: AST Support Guidelines
  2. Please describe how your code solves the related issue.

Added the udf_init_once decorator in snowflake.snowpark.functions for marking functions to be executed once during pre-fork initialization on Snowflake workers, matching the server-side _snowflake.udf_init_once API.

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@sfc-gh-nirsharma

Copy link
Copy Markdown
Collaborator Author

I have read the CLA Document and I hereby sign the CLA

@sfc-gh-nirsharma sfc-gh-nirsharma changed the title Niranjan sharma udf init once SNOW-3152139: Create UDF_init_once decorator in python client Jun 30, 2026
Comment thread src/snowflake/snowpark/functions.py

@sfc-gh-gshe sfc-gh-gshe left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@codecov-commenter

codecov-commenter commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.53%. Comparing base (809b627) to head (75fd593).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4269   +/-   ##
=======================================
  Coverage   95.52%   95.53%           
=======================================
  Files         171      171           
  Lines       44360    44368    +8     
  Branches     7577     7579    +2     
=======================================
+ Hits        42377    42385    +8     
  Misses       1221     1221           
  Partials      762      762           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/snowflake/snowpark/functions.py Outdated
Comment thread tests/integ/test_function.py Outdated
@sfc-gh-nirsharma sfc-gh-nirsharma force-pushed the niranjan-sharma-udf-init-once branch from 4683d4d to bf74a74 Compare July 1, 2026 20:12
Comment thread CHANGELOG.md Outdated
sfc-gh-nirsharma and others added 7 commits July 1, 2026 23:31
The client-side udf_init_once decorator only tags the function and does
not execute it, so setup() does not run and _multiplier stays 1. Assert
the UDF returns inputs unchanged ([1, 2, 3]) to verify the decorated
handler file registers and runs without error via register_from_file.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…e stale â�� only the Linux hashes got updated when test_udf_init_once_file.py was added
@sfc-gh-nirsharma sfc-gh-nirsharma force-pushed the niranjan-sharma-udf-init-once branch from 43cb13f to 8f2931b Compare July 1, 2026 23:31
@sfc-gh-aling sfc-gh-aling merged commit 89e9fcf into main Jul 2, 2026
27 of 31 checks passed
@sfc-gh-aling sfc-gh-aling deleted the niranjan-sharma-udf-init-once branch July 2, 2026 16:31
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants