Skip to content

Add SnowflakeNotebookOperator for executing Snowflake Notebooks - #63470

Merged
shahar1 merged 5 commits into
apache:mainfrom
jacobcbeaudin:add-snowflake-notebook-operator
Sep 20, 2026
Merged

shahar1 merged 5 commits into
apache:mainfrom
jacobcbeaudin:add-snowflake-notebook-operator

Conversation

@jacobcbeaudin

@jacobcbeaudin jacobcbeaudin commented Mar 12, 2026 •

Copy link
Copy Markdown
Contributor

Add a dedicated SnowflakeNotebookOperator that executes Snowflake Notebooks
via the Snowflake SQL API. The operator submits an EXECUTE NOTEBOOK statement,
polls for completion, and pushes the query ID to XCom. Supports both synchronous
polling and deferrable (async) mode for long-running notebook executions.

Reuses the existing SnowflakeSqlApiHook and SnowflakeSqlApiTrigger — no new
hook or trigger code required.

closes: #40167


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Opus 4.6 and Claude Opus 5

Important

🛠️ Maintainer triage note for @jacobcbeaudin · by @potiuk · 2026-07-02 17:46 UTC

Some review feedback from @eladkal is waiting on you:

  • 1 unresolved review thread(s) from @eladkal need a reply or a fix.

The ball is in your court — you've been assigned to this PR. Reply or push a fix in each thread, then mark them resolved.

Automated triage — may be imperfect; a maintainer takes the next look.

@jacobcbeaudin
jacobcbeaudin requested a review from potiuk as a code owner March 12, 2026 18:28
@boring-cyborg

boring-cyborg Bot commented Mar 12, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@boring-cyborg boring-cyborg Bot added area:providers provider:snowflake Issues related to Snowflake provider labels Mar 12, 2026
@potiuk
potiuk marked this pull request as draft March 13, 2026 12:28
@potiuk

potiuk commented Mar 13, 2026 •

Copy link
Copy Markdown
Member

@jacobcbeaudin Converting to draft — this PR doesn't yet meet our Pull Request quality criteria.

  • ❌ Pre-commit / static checks: Failing: CI image checks / Static checks. Run prek run --from-ref main locally to find and fix issues. See Pre-commit / static checks docs.

Note: Your branch is 18 commits behind main. Please rebase and push again to get up-to-date CI results.

See the linked criteria for how to fix each item, then mark the PR "Ready for review". This is not a rejection — just an invitation to bring the PR up to standard. No rush.


Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you.

@jacobcbeaudin
jacobcbeaudin marked this pull request as ready for review March 13, 2026 21:24
@jacobcbeaudin

Copy link
Copy Markdown
Contributor Author

@jacobcbeaudin This PR has been converted to draft because it does not yet meet our Pull Request quality criteria.

Issues found:

* ❌ **Pre-commit / static checks**: Failing: CI image checks / Static checks. Run `prek run --from-ref main` locally to find and fix issues. See [Pre-commit / static checks docs](https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst).

Note: Your branch is 18 commits behind main. Some check failures may be caused by changes in the base branch rather than by your PR. Please rebase your branch and push again to get up-to-date CI results.

What to do next:

* The comment informs you what you need to do.

* Fix each issue, then mark the PR as "Ready for review" in the GitHub UI - but only after making sure that all the issues are fixed.

* Maintainers will then proceed with a normal review.

Converting a PR to draft is not a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. If you have questions, feel free to ask on the Airflow Slack.

@potiuk Thanks for the feedback. I've addressed the issues:

  • Rebased onto main
  • Added the missing get_provider_info.py update

I've marked the PR as ready for review. As a first-time contributor, I believe the CI workflows need maintainer approval before they can run. Would someone be able to approve the workflow run so we can verify the checks pass?

@SameerMesiah97 SameerMesiah97 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.

I think the approach needs to be re-worked. Looking at the code for this new operator, it looks like you are duplcating the logic in SnowflakeSqlApiOperator with the key difference being the construction of the SQL query through _build_execute_notebook_query. I think it would be better to subclass SnowflakeSqlApiOperator and then override the parent method where you want the logic need to be slightly different like for e.g. in query construction.

@jacobcbeaudin jacobcbeaudin left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@SameerMesiah97 Good call. Refactored SnowflakeNotebookOperator to subclass SnowflakeSqlApiOperator. It now only adds the notebook/parameters params and builds the EXECUTE NOTEBOOK SQL in _build_execute_notebook_query(). Everything else (hook setup, execute, polling, deferral, on_kill) is inherited from the parent. Went from about 237 lines down to 90.

@potiuk
potiuk marked this pull request as draft April 1, 2026 11:06
@potiuk

potiuk commented Apr 1, 2026 •

Copy link
Copy Markdown
Member

@jacobcbeaudin Converting to draft — this PR doesn't yet meet our Pull Request quality criteria.

  • ❌ Pre-commit / static checks: Failing: CI image checks / Static checks. Run prek run --from-ref main locally to find and fix issues. See Pre-commit / static checks docs.
  • ⚠️ Unresolved review comments: This PR has 2 unresolved review threads from maintainers: @eladkal (MEMBER): 2 unresolved threads. Please review and resolve all inline review comments before requesting another review. You can resolve a conversation by clicking 'Resolve conversation' on each thread after addressing the feedback. See pull request guidelines.

Note: Your branch is 182 commits behind main. Please rebase and push again to get up-to-date CI results.

See the linked criteria for how to fix each item, then mark the PR "Ready for review". This is not a rejection — just an invitation to bring the PR up to standard. No rush.


Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you.

@jacobcbeaudin
jacobcbeaudin force-pushed the add-snowflake-notebook-operator branch from f7d8168 to db1b564 Compare April 1, 2026 22:01
@jacobcbeaudin
jacobcbeaudin marked this pull request as ready for review April 1, 2026 22:37
@potiuk potiuk added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Apr 2, 2026
@jacobcbeaudin
jacobcbeaudin force-pushed the add-snowflake-notebook-operator branch from e59d74f to e19c761 Compare April 7, 2026 16:17
@kaxil
kaxil requested a review from Copilot April 10, 2026 19:55

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a dedicated SnowflakeNotebookOperator to execute Snowflake Notebooks via the Snowflake SQL API, including documentation and coverage through unit + system test examples.

Changes:

  • Introduces SnowflakeNotebookOperator built on SnowflakeSqlApiOperator to run EXECUTE NOTEBOOK ....
  • Adds unit tests validating SQL construction and execution paths (immediate success/failure, polling, deferrable, XCom, on_kill).
  • Adds system test example DAG and provider docs section for the new operator.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
providers/snowflake/src/airflow/providers/snowflake/operators/snowflake.py Adds SnowflakeNotebookOperator and SQL builder for EXECUTE NOTEBOOK.
providers/snowflake/tests/unit/snowflake/operators/test_snowflake.py Adds unit tests for SQL generation and operator behaviors (polling/deferral/XCom).
providers/snowflake/tests/system/snowflake/example_snowflake_notebook.py Adds a system test example DAG demonstrating operator usage.
providers/snowflake/docs/operators/snowflake.rst Documents SnowflakeNotebookOperator and includes example snippets.

@jacobcbeaudin
jacobcbeaudin force-pushed the add-snowflake-notebook-operator branch 3 times, most recently from 0937ae9 to 3bd6851 Compare April 17, 2026 19:23
@eladkal
eladkal requested a review from jroachgolf84 April 27, 2026 18:14

@jroachgolf84 jroachgolf84 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@jacobcbeaudin - LGTM. However, you'll want to make sure you resolve all of the open conversations (that may just mean clicking "Resolve Conversation" if the feedback does not need to be implemented).

@jroachgolf84

Copy link
Copy Markdown
Collaborator

One other thing; were you able to test this E2E in Snowflake? Does this work as expected?

@potiuk

potiuk commented May 18, 2026

Copy link
Copy Markdown
Member

@jacobcbeaudin — There are 1 unresolved review thread on this PR from @eladkal. Could you either push a fix or reply in each thread explaining why the feedback doesn't apply? Once you believe the feedback is addressed, mark the thread as resolved so the reviewer isn't re-pinged needlessly. Thanks!


Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you.

@potiuk potiuk removed the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label May 19, 2026
@potiuk

potiuk commented May 26, 2026

Copy link
Copy Markdown
Member

@jacobcbeaudin — There are 1 unresolved review thread(s) on this PR, and you have engaged with each one (post-review commits and/or in-thread replies). Could you confirm whether you believe the feedback is fully addressed and the PR is ready for maintainer review confirmation?

If yes, reply here (a short "yes / ready" is fine) and an Apache Airflow maintainer will pick the PR up from the review queue on the next sweep.

If you are still working on a thread, please reply with what is outstanding so the threads stay unresolved on purpose.


Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you.


Drafted-by: Claude Code (Opus 4.7); reviewed by @potiuk before posting

@potiuk potiuk added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Jun 3, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Aug 25, 2026
@eladkal

eladkal commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

@jacobcbeaudin can you address open items and resolve conflicts?
I will help to get this merged

@jacobcbeaudin

Copy link
Copy Markdown
Contributor Author

@eladkal yes, I will take care of this on Monday

Adds SnowflakeNotebookOperator, which builds an EXECUTE NOTEBOOK statement
and delegates submission, polling, deferral and cancellation to
SnowflakeSqlApiOperator.
@jacobcbeaudin
jacobcbeaudin force-pushed the add-snowflake-notebook-operator branch from 91b2878 to 5b5a68d Compare September 1, 2026 15:33
SnowflakeNotebookOperator reused `parameters`, which SQLExecuteQueryOperator
owns for SQL bind parameters. Loading those from a .sql/.json file is a
deliberate feature of the parent, but the wrong behaviour for notebook
arguments: reusing the name meant a parameter that looked like a filename was
replaced by that file's contents, the attribute had to be reassigned after
super().__init__(), and a JSON renderer was applied to a list[str].

The generated SQL is never read from a file, so no template extension applies.
@jacobcbeaudin

Copy link
Copy Markdown
Contributor Author

Thank you for your patience. I did a rebase onto the latest main. The conflicts are gone. The two Merge branch 'main' commits are also gone. The branch is now a clean rebase.

Test results

@jroachgolf84 asked:

One other thing; were you able to test this E2E in Snowflake? Does this work as expected?

I ran this operator against a live Snowflake account. These functions are correct:

  • Parameters go to the notebook unchanged. ["param1", "target_db=PROD"] becomes sys.argv == ['param1', 'target_db=PROD'].
  • A notebook that fails makes the task fail. The log shows the Python error from Snowflake, not a general error.
  • A notebook name that does not exist gives an immediate error: SQL compilation error: Notebook '...' does not exist. The task does not wait.
  • The operator sends one statement for each run. QUERY_HISTORY shows two rows, but Snowflake tags the second row StreamlitEngine. That row is the internal notebook query from Snowflake.
  • The operator escapes backslashes correctly.

The template question

@jroachgolf84 asked:

Hmmm, I don't think that self.notebook or self.parameters are "going to change" after templating... What would cause these to change?

Airflow causes the change. Airflow writes the rendered values back into the template fields. You can do this test without a Snowflake account. The field has the name notebook_parameters now, but the behaviour is the same:

op = SnowflakeNotebookOperator(task_id="t", notebook="{{ params.db }}.NB",
                               notebook_parameters=["{{ params.name }}", "plain"])
op.render_template_fields({"params": {"db": "MY_DB.S", "name": "O'Brien"}})
# op.notebook_parameters is now ["O'Brien", "plain"] -- Airflow wrote it in place
# op.sql (old value):  EXECUTE NOTEBOOK MY_DB.S.NB('O'Brien', 'plain')    <- not valid SQL
# execute() makes:     EXECUTE NOTEBOOK MY_DB.S.NB('O''Brien', 'plain')   <- correct

Airflow writes the rendered values into the template fields in place. Thus execute() must build the SQL again. Without the rebuild, the operator escapes the Jinja text, and the rendered value goes to Snowflake unescaped. I added the test test_real_template_rendering_escapes_rendered_value.

A different name for the parameters

The tests showed me that parameters is a bad name here. SQLExecuteQueryOperator uses the same name for SQL bind parameters.

The parent class can read bind parameters from a .sql or .json file. This is an intended function of the parent class. parameters="params.json" goes to prepare_template(), then to ast.literal_eval, and becomes a dictionary.

But that function is wrong for notebook arguments. The two names were the same. Thus Airflow found a notebook parameter with the form of a file name. Airflow then replaced that parameter with the contents of the file:

notebook_parameters=["config.json", "plain"]
# after resolve_template_files(): ['{"secret": "..."}', 'plain']

I did these three things:

  • The name is now notebook_parameters.
  • template_ext is now (). This operator builds its own SQL and never reads SQL from a file. Thus no template extension applies.
  • template_fields_renderers keeps {"sql": "sql"}, the same as TeradataOperator, ExasolOperator and DatabricksSqlOperator.

The new name also removes the self.parameters = ... line after super().__init__(). The name conflict made that line necessary.

The new name agrees with the other operators in this hierarchy: session_parameters and client_parameters.

Airflow did not release this operator yet. Thus the new name costs nothing now. After a merge, a different name makes a deprecation cycle necessary.

Tell me if you prefer a smaller diff, and I will remove the new name.

@eladkal eladkal removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Sep 4, 2026
@shahar1
shahar1 merged commit 6ede664 into apache:main Sep 20, 2026
83 checks passed
@boring-cyborg

boring-cyborg Bot commented Sep 20, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:snowflake Issues related to Snowflake provider ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate Snowflake Notebook Scheduling with Apache Airflow

7 participants