Skip to content

Add FastSnowflakeIngestion as a saparate helper for Snowpark based Snowflake ingestion (via Foundry Virtual Tables and lightweight transforms) - #124

Merged
nicornk merged 4 commits into
emdgroup:mainfrom
misterbrunet:feat/fast-snowflake-ingestion
Nov 20, 2026
Merged

nicornk merged 4 commits into
emdgroup:mainfrom
misterbrunet:feat/fast-snowflake-ingestion

Conversation

@misterbrunet

@misterbrunet misterbrunet commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adding FastSnowflakeIngestion (FSI), a helper that syncs Snowflake data into a Foundry dataset from a lightweight transform using only a Snowpark session - no Spark, no Data Connection agent.

fsi.save_snowpark_dataframe_to_foundry_output(df):

  1. unloads df as Parquet into a temporary Snowflake stage (dropped by Snowflake at session end)
  2. downloads the files to a local temp folder, in parallel
  3. uploads them to the output dataset, in parallel
  4. commits the transaction and removes the temp folder, also on failure
from foundry_dev_tools.helpers.fast_snowflake_ingestion import FastSnowflakeIngestion

fsi = FastSnowflakeIngestion(snowpark_session=session, output=output)
fsi.save_snowpark_dataframe_to_foundry_output(df)  # Snowpark dataframe

Features:

  • session stage (default) or a temporary stage in a shared database (use_shared_db, db_name, schema_name), with an optional fallback stage (fallback_db_name, fallback_schema_name)
  • Snowflake query_tag set to the Foundry job info (job/repo/input/output RIDs, branch) plus custom_tags, so Snowflake cost can be traced to the job
  • Snowflake session ID stored on the output (save_session_id=True)
  • disable_s3_transfer_acceleration(): workaround for snowflake-connector-python#2317, forces the regional S3 endpoint when egress blocks the global one; on by default, enable_s3_monkeypatch=False to opt out
  • path helpers TransactionPath, ViewPath, FoundryPathWithBranchId

Packaging, docs, tests:

  • new optional extra pip install 'foundry-dev-tools[snowflake]' (also in [full]); Palantir-only modules are imported lazily
  • docs page docs/examples/fast-snowflake-ingestion.md (usage, limitations, permissions, S3 workaround)
  • 20 unit tests with fake snowflake modules, so no new dev dependency or pdm.lock change
  • new changelog.md entry

For those at Merck who might recognise it: this module was used internally as "FastSnowflakeIngestion" in the SAP sync migration, where we moved away from agent-based syncs. This is a reworked and adapted version of it, made generic for anyone to use.

Checklist

  • You agree with our CLA
  • Included tests (or is not applicable).
  • Updated documentation (or is not applicable).
  • Used pre-commit hooks to format and lint the code.

@misterbrunet

Copy link
Copy Markdown
Contributor Author

CI failures are the Spark tests on JDK 24+ (getSubject is not supported), unrelated to this change. The FSI tests pass. #123 pins Java 17 in ci.yml, I'll rebase once it's merged.

@misterbrunet
misterbrunet force-pushed the feat/fast-snowflake-ingestion branch from 1546166 to 5c5fd8d Compare November 20, 2026 09:22
@misterbrunet misterbrunet changed the title Add FastSnowflakeIngestion as a saparate helper for Snowpark based Snowflake ingestion Add FastSnowflakeIngestion as a saparate helper for Snowpark based Snowflake ingestion (via Foundry Virtual Tables and lightweight transforms) Nov 20, 2026
@nicornk
nicornk requested a balanced review from Copilot November 20, 2026 09:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The asynchronous unload is not awaited before downloading, risking incomplete data being committed and unload failures going unnoticed.

3 open issues
What changed in this PR

Adds FastSnowflakeIngestion to Foundry DevTools for moving Snowpark DataFrames into Foundry datasets from lightweight transforms, without Spark or a Data Connection agent.

Changes:

  • Adds staged Parquet export, parallel file transfers, transaction commits, and local cleanup.
  • Provides shared and fallback stages, job telemetry, session metadata, and an S3 endpoint workaround.
  • Adds the optional snowflake extra, usage documentation, and dependency-isolated unit tests.
File Description
tests/​unit/​helpers/​test_fast_snowflake_ingestion.py Tests staging, transfers, telemetry, cleanup, and path helpers.
tests/​unit/​helpers/​__init__.py Adds the helper-test package marker.
libs/​foundry-dev-tools/​src/​foundry_dev_tools/​helpers/​fast_snowflake_ingestion/​utils.py Resolves output paths and collects Foundry job information.
libs/​foundry-dev-tools/​src/​foundry_dev_tools/​helpers/​fast_snowflake_ingestion/​_impl.py Implements the ingestion pipeline and Snowflake configuration.
libs/​foundry-dev-tools/​src/​foundry_dev_tools/​helpers/​fast_snowflake_ingestion/​__init__.py Exports the public ingestion and path helpers.
libs/​foundry-dev-tools/​pyproject.toml Adds Snowpark dependencies through snowflake and full extras.
docs/​examples/​index.md Links the new ingestion guide.
docs/​examples/​fast-snowflake-ingestion.md Documents setup, usage, permissions, and limitations.
docs/​changelog.md Announces the new ingestion helper.

Review effort: Balanced

@misterbrunet

Copy link
Copy Markdown
Contributor Author

changes applied:

  • catch SnowparkSQLException in stage fallback, as failed CREATE STAGE raises it instead of the connector Error
  • truncate query tag to 2000 characters (Snowflake limit) and log the full tag
  • drop AsyncJob from write_df_into_location_parquet return type, async unload is not supported
  • raise default MAX_FILE_SIZE from 128MB to 200MB
  • document why the regional S3 endpoint lowers transfer cost
  • document TIMESTAMP_TZ/LTZ unload limitation for Parquet

@misterbrunet

Copy link
Copy Markdown
Contributor Author
  • Removed the snowflake extra; snowflake-snowpark-python is now an optional dependency via _optional/snowflake.py, like pyarrow. Docs and tests updated.
  • Changelog stamped as [2.1.26] and added the missing compare links for 2.1.23–2.1.26.

@nicornk nicornk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

some nits

@nicornk nicornk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please address my nit's in the example code

@nicornk
nicornk merged commit 7b2ccb7 into emdgroup:main Nov 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants