Repository navigation
Databricks: detect Delta table version changes (#74195). #74225
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
Open
goyaladitay11
wants to merge
2
commits into
apache:main
Choose a base branch
from
goyaladitay11:feat/databricks-delta-table-sensor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,546
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
providers/databricks/docs/operators/delta_table_sensor.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| .. Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| .. http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| .. Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
|
|
||
| .. _howto/operator:DatabricksDeltaTableVersionSensor: | ||
|
|
||
| DatabricksDeltaTableVersionSensor | ||
| ================================= | ||
|
|
||
| Use the :class:`~airflow.providers.databricks.sensors.databricks_delta_table.DatabricksDeltaTableVersionSensor` | ||
| to monitor a Delta table in Databricks and detect new commit versions. When a newer version is observed, | ||
| the sensor succeeds, pushes provenance metadata to XCom, and optionally emits an Airflow Asset event. | ||
|
|
||
|
|
||
| Using the Sensor | ||
| ---------------- | ||
|
|
||
| The sensor requires a target Delta table and a Databricks SQL endpoint. | ||
|
|
||
| To identify the table, specify either: | ||
|
|
||
| * ``table_name`` - String representing the 1-, 2-, or 3-part Delta table name (``table``, ``schema.table``, or ``catalog.schema.table``). | ||
| * ``unity_table`` - An instance of :class:`~airflow.providers.databricks.assets.databricks.UnityTableIdentity`. When provided without explicit ``outlets``, the sensor automatically registers the corresponding Unity Catalog asset (``databricks://<host>/<catalog>/<schema>/<table>``) as an outlet. | ||
|
|
||
| To connect to Databricks SQL, specify either ``sql_warehouse_name`` or ``http_path``. | ||
|
|
||
| Other parameters, such as connection credentials and timeout configuration, are documented in the class reference. | ||
|
|
||
|
|
||
| Waiting for a new version | ||
| ------------------------- | ||
|
|
||
| By default, omitting ``baseline_version`` and ``target_version`` enrolls the table by capturing its current version on the first check and waiting for subsequent commits. You can also specify an explicit ``baseline_version`` to succeed when the table's version is strictly greater: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from airflow.providers.databricks.sensors.databricks_delta_table import ( | ||
| DatabricksDeltaTableVersionSensor, | ||
| ) | ||
|
|
||
| wait_for_updates = DatabricksDeltaTableVersionSensor( | ||
| task_id="wait_for_table_updates", | ||
| table_name="main.default.customers", | ||
| sql_warehouse_name="my_warehouse", | ||
| baseline_version=42, | ||
| poke_interval=30, | ||
| ) | ||
|
|
||
|
|
||
| Waiting for a specific version | ||
| ------------------------------ | ||
|
|
||
| To wait for an exact target Delta version, set ``target_version``: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from airflow.providers.databricks.sensors.databricks_delta_table import ( | ||
| DatabricksDeltaTableVersionSensor, | ||
| ) | ||
|
|
||
| wait_for_v50 = DatabricksDeltaTableVersionSensor( | ||
| task_id="wait_for_v50", | ||
| table_name="main.default.customers", | ||
| sql_warehouse_name="my_warehouse", | ||
| target_version=50, | ||
| ) | ||
|
|
||
|
|
||
| Using the observed version downstream | ||
| ------------------------------------- | ||
|
|
||
| When a new version is detected, the sensor pushes metadata to XCom under the key ``delta_table_version``, including ``version``, ``timestamp``, ``operation``, and ``table_identity``. If multiple commits occurred between polling checks, the sensor observes and reports the latest commit. | ||
|
|
||
| Downstream tasks requiring reproducible reads should pin their queries to the observed version using ``VERSION AS OF``: | ||
|
|
||
| .. code-block:: sql | ||
|
|
||
| SELECT * FROM main.default.customers | ||
| VERSION AS OF {{ ti.xcom_pull(task_ids="wait_for_table_updates", key="delta_table_version")["version"] }} | ||
|
|
||
| When an outlet asset is configured or inferred from ``unity_table``, the sensor also attaches the observed version and table identity to the asset event extra metadata. | ||
|
|
||
|
|
||
| Deferrable mode | ||
| --------------- | ||
|
|
||
| To avoid consuming worker slots while polling, run the sensor in deferrable mode by setting ``deferrable=True`` (or globally via ``operators.default_deferrable``). The sensor yields execution to the triggerer until a newer version is observed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 am not very happy with this doc. Feels very AI generated and not designed to be read by humans.
It feels as if the doc explains the code. parameter by parameter.
There are too many bold statements and too many things marked as important.