airflow-provider-duckless 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- airflow_provider_duckless-0.6.0/PKG-INFO +40 -0
- airflow_provider_duckless-0.6.0/README.md +18 -0
- airflow_provider_duckless-0.6.0/pyproject.toml +51 -0
- airflow_provider_duckless-0.6.0/pyproject.toml.orig +44 -0
- airflow_provider_duckless-0.6.0/src/duckless_airflow/__init__.py +18 -0
- airflow_provider_duckless-0.6.0/src/duckless_airflow/operators.py +135 -0
- airflow_provider_duckless-0.6.0/src/duckless_airflow/triggers.py +38 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: airflow-provider-duckless
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: Apache Airflow provider for DuckLess: run DuckDB jobs on Google Cloud from a DAG, deferrable
|
|
5
|
+
Keywords: airflow,duckdb,duckless,google-cloud,cloud-composer,data-engineering
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Classifier: Development Status :: 4 - Beta
|
|
8
|
+
Classifier: Framework :: Apache Airflow
|
|
9
|
+
Classifier: Framework :: Apache Airflow :: Provider
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Dist: duckless>=0.6.0
|
|
15
|
+
Requires-Dist: apache-airflow>=2.10
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Project-URL: Homepage, https://tosun-si.github.io/duckless/guides/airflow/
|
|
18
|
+
Project-URL: Documentation, https://tosun-si.github.io/duckless/guides/airflow/
|
|
19
|
+
Project-URL: Repository, https://github.com/tosun-si/duckless
|
|
20
|
+
Project-URL: Issues, https://github.com/tosun-si/duckless/issues
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# airflow-provider-duckless
|
|
24
|
+
|
|
25
|
+
Run [DuckLess](https://github.com/tosun-si/duckless) jobs (serverless DuckDB on Google Cloud) from
|
|
26
|
+
Apache Airflow and Cloud Composer.
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from duckless_airflow.operators import DuckLessRunOperator
|
|
30
|
+
|
|
31
|
+
DuckLessRunOperator(task_id="checks", source="jobs/checks.py", machine="n2-highmem-8", env={"DAY": "{{ ds }}"})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`DuckLessRunOperator` submits the job, then waits for it in the triggerer (deferrable by default),
|
|
35
|
+
so no worker slot is held while it runs. The task fails when the job fails, with the runner's error,
|
|
36
|
+
and pushes a summary of the job to XCom.
|
|
37
|
+
|
|
38
|
+
Airflow 2.10 and later, Airflow 3 included; Python 3.11 to 3.13.
|
|
39
|
+
|
|
40
|
+
Guide: https://tosun-si.github.io/duckless/guides/airflow/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# airflow-provider-duckless
|
|
2
|
+
|
|
3
|
+
Run [DuckLess](https://github.com/tosun-si/duckless) jobs (serverless DuckDB on Google Cloud) from
|
|
4
|
+
Apache Airflow and Cloud Composer.
|
|
5
|
+
|
|
6
|
+
```python
|
|
7
|
+
from duckless_airflow.operators import DuckLessRunOperator
|
|
8
|
+
|
|
9
|
+
DuckLessRunOperator(task_id="checks", source="jobs/checks.py", machine="n2-highmem-8", env={"DAY": "{{ ds }}"})
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
`DuckLessRunOperator` submits the job, then waits for it in the triggerer (deferrable by default),
|
|
13
|
+
so no worker slot is held while it runs. The task fails when the job fails, with the runner's error,
|
|
14
|
+
and pushes a summary of the job to XCom.
|
|
15
|
+
|
|
16
|
+
Airflow 2.10 and later, Airflow 3 included; Python 3.11 to 3.13.
|
|
17
|
+
|
|
18
|
+
Guide: https://tosun-si.github.io/duckless/guides/airflow/
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "airflow-provider-duckless"
|
|
3
|
+
version = "0.6.0"
|
|
4
|
+
description = "Apache Airflow provider for DuckLess: run DuckDB jobs on Google Cloud from a DAG, deferrable"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
requires-python = ">=3.11"
|
|
8
|
+
keywords = [
|
|
9
|
+
"airflow",
|
|
10
|
+
"duckdb",
|
|
11
|
+
"duckless",
|
|
12
|
+
"google-cloud",
|
|
13
|
+
"cloud-composer",
|
|
14
|
+
"data-engineering",
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Framework :: Apache Airflow",
|
|
19
|
+
"Framework :: Apache Airflow :: Provider",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"duckless>=0.6.0",
|
|
27
|
+
"apache-airflow>=2.10",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://tosun-si.github.io/duckless/guides/airflow/"
|
|
32
|
+
Documentation = "https://tosun-si.github.io/duckless/guides/airflow/"
|
|
33
|
+
Repository = "https://github.com/tosun-si/duckless"
|
|
34
|
+
Issues = "https://github.com/tosun-si/duckless/issues"
|
|
35
|
+
|
|
36
|
+
[project.entry-points.apache_airflow_provider]
|
|
37
|
+
provider_info = "duckless_airflow:get_provider_info"
|
|
38
|
+
|
|
39
|
+
[dependency-groups]
|
|
40
|
+
dev = ["pytest>=8.4"]
|
|
41
|
+
|
|
42
|
+
[tool.uv.sources.duckless]
|
|
43
|
+
path = ".."
|
|
44
|
+
editable = true
|
|
45
|
+
|
|
46
|
+
[tool.uv.build-backend]
|
|
47
|
+
module-name = "duckless_airflow"
|
|
48
|
+
|
|
49
|
+
[build-system]
|
|
50
|
+
requires = ["uv_build>=0.8,<0.13"]
|
|
51
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "airflow-provider-duckless"
|
|
3
|
+
version = "0.6.0"
|
|
4
|
+
description = "Apache Airflow provider for DuckLess: run DuckDB jobs on Google Cloud from a DAG, deferrable"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
requires-python = ">=3.11"
|
|
8
|
+
keywords = ["airflow", "duckdb", "duckless", "google-cloud", "cloud-composer", "data-engineering"]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 4 - Beta",
|
|
11
|
+
"Framework :: Apache Airflow",
|
|
12
|
+
"Framework :: Apache Airflow :: Provider",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3.11",
|
|
15
|
+
"Programming Language :: Python :: 3.12",
|
|
16
|
+
"Programming Language :: Python :: 3.13",
|
|
17
|
+
]
|
|
18
|
+
dependencies = [
|
|
19
|
+
"duckless>=0.6.0",
|
|
20
|
+
"apache-airflow>=2.10",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://tosun-si.github.io/duckless/guides/airflow/"
|
|
25
|
+
Documentation = "https://tosun-si.github.io/duckless/guides/airflow/"
|
|
26
|
+
Repository = "https://github.com/tosun-si/duckless"
|
|
27
|
+
Issues = "https://github.com/tosun-si/duckless/issues"
|
|
28
|
+
|
|
29
|
+
# Airflow finds the provider (connections, extra links, its version in the UI) through this.
|
|
30
|
+
[project.entry-points.apache_airflow_provider]
|
|
31
|
+
provider_info = "duckless_airflow:get_provider_info"
|
|
32
|
+
|
|
33
|
+
[dependency-groups]
|
|
34
|
+
dev = ["pytest>=8.4"]
|
|
35
|
+
|
|
36
|
+
[tool.uv.sources]
|
|
37
|
+
duckless = { path = "..", editable = true }
|
|
38
|
+
|
|
39
|
+
[tool.uv.build-backend]
|
|
40
|
+
module-name = "duckless_airflow"
|
|
41
|
+
|
|
42
|
+
[build-system]
|
|
43
|
+
requires = ["uv_build>=0.8,<0.13"]
|
|
44
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Apache Airflow provider for DuckLess: run DuckDB jobs on Google Cloud from a DAG.
|
|
2
|
+
|
|
3
|
+
from duckless_airflow.operators import DuckLessRunOperator
|
|
4
|
+
|
|
5
|
+
DuckLessRunOperator(task_id="quality_checks", source="jobs/checks.py", machine="n2-highmem-8")
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from importlib import metadata
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_provider_info() -> dict:
|
|
12
|
+
"""What Airflow shows about the provider (Admin > Providers)."""
|
|
13
|
+
return {
|
|
14
|
+
"package-name": "airflow-provider-duckless",
|
|
15
|
+
"name": "DuckLess",
|
|
16
|
+
"description": "Run DuckDB jobs on Google Cloud (Cloud Batch, Cloud Run Jobs) with DuckLess.",
|
|
17
|
+
"versions": [metadata.version("airflow-provider-duckless")],
|
|
18
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""DuckLessRunOperator: submits a DuckLess job and waits for it, deferred by default."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping, Sequence
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from airflow.exceptions import AirflowException
|
|
8
|
+
|
|
9
|
+
try: # Airflow 3
|
|
10
|
+
from airflow.sdk import BaseOperator
|
|
11
|
+
except ImportError: # Airflow 2
|
|
12
|
+
from airflow.models import BaseOperator
|
|
13
|
+
|
|
14
|
+
import duckless
|
|
15
|
+
from duckless_airflow.triggers import DuckLessJobTrigger
|
|
16
|
+
|
|
17
|
+
# Once a job has ended, its run duration and metrics land within seconds.
|
|
18
|
+
SETTLE_TIMEOUT_SECONDS = 120
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def resolve_source(source: str | None, dag_file: str | None) -> str | None:
|
|
22
|
+
"""A relative source is relative to the DAG file's folder (gs:// and absolute paths stay as they are)."""
|
|
23
|
+
if source is None or source.startswith("gs://") or Path(source).is_absolute() or not dag_file:
|
|
24
|
+
return source
|
|
25
|
+
return str(Path(dag_file).parent / source)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def job_summary(report: duckless.JobReport) -> dict[str, Any]:
|
|
29
|
+
"""What the task pushes to XCom: small, JSON-safe, enough for the tasks downstream."""
|
|
30
|
+
metrics = report.metrics or {}
|
|
31
|
+
return {
|
|
32
|
+
"job_id": report.status.job_id,
|
|
33
|
+
"state": report.status.state.value,
|
|
34
|
+
"executor": report.status.executor.value,
|
|
35
|
+
"machine": report.status.machine,
|
|
36
|
+
"seconds": metrics.get("seconds"),
|
|
37
|
+
"peak_rss_gb": metrics.get("peak_rss_gb"),
|
|
38
|
+
"bigquery_writes": list(metrics.get("bigquery_writes") or ()),
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class DuckLessRunOperator(BaseOperator):
|
|
43
|
+
"""Runs a DuckLess job: a `.sql` or `.py` file for the runner, or an image and a command.
|
|
44
|
+
|
|
45
|
+
Deferred by default: once the job is submitted, the task waits in the triggerer and frees its
|
|
46
|
+
worker slot. The task fails when the job fails, with the runner's error. `duckless_settings`
|
|
47
|
+
overrides the DUCKLESS_* settings of the environment (project, region, bucket,
|
|
48
|
+
service_account, image).
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
template_fields: Sequence[str] = ("source", "env", "machine", "image", "command", "name")
|
|
52
|
+
ui_color = "#2f7bff"
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
*,
|
|
57
|
+
source: str | None = None,
|
|
58
|
+
machine: str = "n2-highmem-16",
|
|
59
|
+
spot: bool = False,
|
|
60
|
+
local_ssd_count: int | None = None,
|
|
61
|
+
env: Mapping[str, str] | None = None,
|
|
62
|
+
on: str = "auto",
|
|
63
|
+
image: str | None = None,
|
|
64
|
+
command: Sequence[str] = (),
|
|
65
|
+
name: str | None = None,
|
|
66
|
+
max_run_seconds: int = 3 * 3600,
|
|
67
|
+
duckless_settings: Mapping[str, str] | None = None,
|
|
68
|
+
deferrable: bool = True,
|
|
69
|
+
poll_seconds: float = 30,
|
|
70
|
+
**kwargs: Any,
|
|
71
|
+
) -> None:
|
|
72
|
+
super().__init__(**kwargs)
|
|
73
|
+
self.source = source
|
|
74
|
+
self.machine = machine
|
|
75
|
+
self.spot = spot
|
|
76
|
+
self.local_ssd_count = local_ssd_count
|
|
77
|
+
self.env = dict(env or {})
|
|
78
|
+
self.on = on
|
|
79
|
+
self.image = image
|
|
80
|
+
self.command = list(command)
|
|
81
|
+
self.name = name
|
|
82
|
+
self.max_run_seconds = max_run_seconds
|
|
83
|
+
self.duckless_settings = dict(duckless_settings or {})
|
|
84
|
+
self.deferrable = deferrable
|
|
85
|
+
self.poll_seconds = poll_seconds
|
|
86
|
+
self.job_id: str | None = None
|
|
87
|
+
|
|
88
|
+
def _client(self) -> duckless.Client:
|
|
89
|
+
return duckless.Client.from_env(**self.duckless_settings)
|
|
90
|
+
|
|
91
|
+
def execute(self, context: Any) -> dict[str, Any] | None:
|
|
92
|
+
client = self._client()
|
|
93
|
+
# Airflow 3 raises on `self.dag` for a task outside a DAG (tests, a bare operator).
|
|
94
|
+
dag_file = self.dag.fileloc if self.has_dag() else None
|
|
95
|
+
status = client.run(
|
|
96
|
+
resolve_source(self.source, dag_file),
|
|
97
|
+
machine=self.machine,
|
|
98
|
+
spot=self.spot,
|
|
99
|
+
local_ssd_count=self.local_ssd_count,
|
|
100
|
+
env={k: str(v) for k, v in self.env.items()},
|
|
101
|
+
on=self.on,
|
|
102
|
+
image=self.image,
|
|
103
|
+
command=tuple(self.command),
|
|
104
|
+
name=self.name or self.task_id,
|
|
105
|
+
max_run_seconds=self.max_run_seconds,
|
|
106
|
+
)
|
|
107
|
+
self.job_id = status.job_id
|
|
108
|
+
self.log.info("DuckLess job %s submitted on %s (%s)", status.job_id, status.executor.value, status.machine)
|
|
109
|
+
if self.deferrable:
|
|
110
|
+
self.defer(
|
|
111
|
+
trigger=DuckLessJobTrigger(status.job_id, self.duckless_settings, self.poll_seconds),
|
|
112
|
+
method_name="execute_complete",
|
|
113
|
+
)
|
|
114
|
+
return self._finish(client, status.job_id, timeout_seconds=None)
|
|
115
|
+
|
|
116
|
+
def execute_complete(self, context: Any, event: dict[str, Any]) -> dict[str, Any]:
|
|
117
|
+
self.job_id = event["job_id"]
|
|
118
|
+
if event["state"] == "ERROR":
|
|
119
|
+
raise AirflowException(f"could not follow DuckLess job {event['job_id']}: {event.get('error')}")
|
|
120
|
+
return self._finish(self._client(), event["job_id"], timeout_seconds=SETTLE_TIMEOUT_SECONDS)
|
|
121
|
+
|
|
122
|
+
def _finish(self, client: duckless.Client, job_id: str, timeout_seconds: float | None) -> dict[str, Any]:
|
|
123
|
+
try:
|
|
124
|
+
report = client.wait(job_id, poll_seconds=self.poll_seconds, timeout_seconds=timeout_seconds, check=True)
|
|
125
|
+
except duckless.JobFailedError as failed:
|
|
126
|
+
raise AirflowException(str(failed)) from failed
|
|
127
|
+
summary = job_summary(report)
|
|
128
|
+
self.log.info("DuckLess job %s %s in %s s", job_id, summary["state"], summary["seconds"])
|
|
129
|
+
return summary
|
|
130
|
+
|
|
131
|
+
def on_kill(self) -> None:
|
|
132
|
+
"""Synchronous mode: a killed task cancels its job, so no VM keeps running for nothing."""
|
|
133
|
+
if self.job_id:
|
|
134
|
+
self.log.info("Cancelling DuckLess job %s", self.job_id)
|
|
135
|
+
self._client().cancel(self.job_id)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Waits for a DuckLess job in the triggerer, so no worker slot is held while it runs."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from collections.abc import AsyncIterator
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from airflow.triggers.base import BaseTrigger, TriggerEvent
|
|
8
|
+
|
|
9
|
+
import duckless
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DuckLessJobTrigger(BaseTrigger):
|
|
13
|
+
"""Polls the job's state until it ends; fires one event: the final state, or the error that stopped it."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, job_id: str, settings: dict[str, str] | None = None, poll_seconds: float = 30) -> None:
|
|
16
|
+
super().__init__()
|
|
17
|
+
self.job_id = job_id
|
|
18
|
+
self.settings = dict(settings or {})
|
|
19
|
+
self.poll_seconds = poll_seconds
|
|
20
|
+
|
|
21
|
+
def serialize(self) -> tuple[str, dict[str, Any]]:
|
|
22
|
+
return (
|
|
23
|
+
"duckless_airflow.triggers.DuckLessJobTrigger",
|
|
24
|
+
{"job_id": self.job_id, "settings": self.settings, "poll_seconds": self.poll_seconds},
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
async def run(self) -> AsyncIterator[TriggerEvent]:
|
|
28
|
+
try:
|
|
29
|
+
client = duckless.Client.from_env(**self.settings)
|
|
30
|
+
while True:
|
|
31
|
+
# The client is synchronous: keep it off the triggerer's event loop.
|
|
32
|
+
report = await asyncio.to_thread(client.status, self.job_id)
|
|
33
|
+
if report.status.state.is_terminal:
|
|
34
|
+
yield TriggerEvent({"job_id": self.job_id, "state": report.status.state.value})
|
|
35
|
+
return
|
|
36
|
+
await asyncio.sleep(self.poll_seconds)
|
|
37
|
+
except Exception as e:
|
|
38
|
+
yield TriggerEvent({"job_id": self.job_id, "state": "ERROR", "error": f"{type(e).__name__}: {e}"})
|