dbt-orchestra 0.4.0__py3-none-any.whl

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.
Files changed (42) hide show
  1. dbt_orchestra-0.4.0.dist-info/METADATA +242 -0
  2. dbt_orchestra-0.4.0.dist-info/RECORD +42 -0
  3. dbt_orchestra-0.4.0.dist-info/WHEEL +5 -0
  4. dbt_orchestra-0.4.0.dist-info/entry_points.txt +2 -0
  5. dbt_orchestra-0.4.0.dist-info/licenses/LICENSE +93 -0
  6. dbt_orchestra-0.4.0.dist-info/top_level.txt +1 -0
  7. orchestra_dbt/__init__.py +0 -0
  8. orchestra_dbt/asset_external_id.py +25 -0
  9. orchestra_dbt/build_after.py +155 -0
  10. orchestra_dbt/checksum.py +26 -0
  11. orchestra_dbt/cli.py +217 -0
  12. orchestra_dbt/compatibility.py +8 -0
  13. orchestra_dbt/config.py +123 -0
  14. orchestra_dbt/constants.py +6 -0
  15. orchestra_dbt/dag.py +153 -0
  16. orchestra_dbt/logger.py +43 -0
  17. orchestra_dbt/ls.py +43 -0
  18. orchestra_dbt/models.py +67 -0
  19. orchestra_dbt/modify.py +76 -0
  20. orchestra_dbt/orchestra.py +16 -0
  21. orchestra_dbt/patcher.py +202 -0
  22. orchestra_dbt/project_discovery.py +24 -0
  23. orchestra_dbt/sao.py +181 -0
  24. orchestra_dbt/source_freshness/__init__.py +73 -0
  25. orchestra_dbt/source_freshness/fallbacks/__init__.py +11 -0
  26. orchestra_dbt/source_freshness/fallbacks/common.py +58 -0
  27. orchestra_dbt/source_freshness/fallbacks/databricks.py +40 -0
  28. orchestra_dbt/source_freshness/fallbacks/registry.py +22 -0
  29. orchestra_dbt/state.py +81 -0
  30. orchestra_dbt/state_backends/__init__.py +8 -0
  31. orchestra_dbt/state_backends/base.py +9 -0
  32. orchestra_dbt/state_backends/factory.py +62 -0
  33. orchestra_dbt/state_backends/http.py +70 -0
  34. orchestra_dbt/state_backends/local_file.py +56 -0
  35. orchestra_dbt/state_backends/logging.py +24 -0
  36. orchestra_dbt/state_backends/s3.py +71 -0
  37. orchestra_dbt/state_errors.py +6 -0
  38. orchestra_dbt/state_filters.py +9 -0
  39. orchestra_dbt/state_storage.py +5 -0
  40. orchestra_dbt/state_types.py +56 -0
  41. orchestra_dbt/target_finder.py +8 -0
  42. orchestra_dbt/utils.py +23 -0
@@ -0,0 +1,242 @@
1
+ Metadata-Version: 2.4
2
+ Name: dbt-orchestra
3
+ Version: 0.4.0
4
+ Summary: Orchestra wrapper for dbt Core - allows for stateful orchestration of dbt Core projects.
5
+ Author: Orchestra Technologies
6
+ License-Expression: Elastic-2.0
7
+ Project-URL: Repository, https://github.com/orchestra-hq/sao-paolo
8
+ Project-URL: Issues, https://github.com/orchestra-hq/sao-paolo/issues
9
+ Project-URL: Changelog, https://github.com/orchestra-hq/sao-paolo/blob/main/CHANGELOG.md
10
+ Project-URL: Security, https://github.com/orchestra-hq/sao-paolo/security/policy
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Build Tools
19
+ Requires-Python: <3.14,>=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: click
23
+ Requires-Dist: httpx
24
+ Requires-Dist: packaging
25
+ Requires-Dist: pydantic
26
+ Requires-Dist: pytz
27
+ Requires-Dist: pyyaml
28
+ Provides-Extra: dev
29
+ Requires-Dist: basedpyright; extra == "dev"
30
+ Requires-Dist: boto3; extra == "dev"
31
+ Requires-Dist: dbt-core<1.12,>=1.10; extra == "dev"
32
+ Requires-Dist: moto[s3]; extra == "dev"
33
+ Requires-Dist: pytest-httpx; extra == "dev"
34
+ Requires-Dist: pytest; extra == "dev"
35
+ Requires-Dist: ruff; extra == "dev"
36
+ Provides-Extra: adapters
37
+ Requires-Dist: dbt-postgres; extra == "adapters"
38
+ Provides-Extra: debug
39
+ Requires-Dist: awscrt; extra == "debug"
40
+ Requires-Dist: boto3; extra == "debug"
41
+ Requires-Dist: graphviz; extra == "debug"
42
+ Provides-Extra: s3
43
+ Requires-Dist: boto3; extra == "s3"
44
+ Dynamic: license-file
45
+
46
+ # dbt-orchestra
47
+
48
+ ## Compatibility
49
+
50
+ - **Python:** 3.11, 3.12, and 3.13 only (see `requires-python` in `pyproject.toml`).
51
+ - **dbt-core:** 1.10.x and 1.11.x when using stateful orchestration.
52
+
53
+ ## Installing
54
+
55
+ ```bash
56
+ python3 -m venv .venv
57
+ source .venv/bin/activate
58
+ uv sync --extra dev
59
+ # Optional: Snowflake/Databricks adapters for local runs
60
+ # uv sync --extra dev --extra adapters
61
+ ```
62
+
63
+ ## Tutorial dbt project
64
+
65
+ A minimal dbt Core project lives under `[tutorial/](tutorial/)`. This is used for testing and CI.
66
+
67
+ ## Development
68
+
69
+ 1. Create a branch
70
+ 1. Add the code and unit tests
71
+ 1. Where possible, [test locally](#running-locally)
72
+ 1. Test in Orchestra with the branch
73
+ 1. Raise a PR
74
+
75
+ Pull requests run GitHub Actions: unit tests, static checks, `dbt build` for `tutorial/dbt` against Postgres, and an Orchestra pipeline via the [Orchestra Run Pipeline Action](https://github.com/orchestra-hq/run-pipeline).
76
+
77
+ ## State Aware Orchestration
78
+
79
+ When stateful orchestration is enabled, the CLI loads and saves [dbt Core state](https://docs.getdbt.com/). Enable it with `use_stateful = true` under `[tool.orchestra_dbt]`, or set `ORCHESTRA_USE_STATEFUL=true`. That state is the same JSON shape regardless of the backend used.
80
+
81
+ **Do not put secrets in `pyproject.toml`.** Use environment variables (or your platform’s secret store) for `ORCHESTRA_API_KEY`.
82
+
83
+ ### Configuration precedence
84
+
85
+ For non-secret options, **if an environment variable is set, it overrides** values from `[tool.orchestra_dbt]`; otherwise the value from `pyproject.toml` is used, then the built-in default.
86
+
87
+ ### `[tool.orchestra_dbt]` options
88
+
89
+ | Key | Type | Default | Purpose |
90
+ | ------------------------ | ----------------- | ------- | ------------------------------------------------------------------------- |
91
+ | `state_file` | string (optional) | — | Local JSON path or `s3://bucket/key` for state (see backend table below). |
92
+ | `use_stateful` | bool | `false` | Turn on stateful orchestration for supported dbt commands. |
93
+ | `orchestra_env` | string | `app` | Orchestra deployment: `app`, `stage`, or `dev` (HTTP API host). |
94
+ | `local_run` | bool | `true` | After reuse, revert patched files (typical for local iteration). |
95
+ | `debug` | bool | `false` | Verbose debug logging. |
96
+ | `integration_account_id` | string (optional) | — | When set, filter state keys to this integration account prefix. |
97
+
98
+ Equivalent environment overrides (when set): `ORCHESTRA_USE_STATEFUL`, `ORCHESTRA_ENV`, `ORCHESTRA_LOCAL_RUN`, `ORCHESTRA_DBT_DEBUG`, `ORCHESTRA_INTEGRATION_ACCOUNT_ID`.
99
+
100
+ ### Choosing HTTP (Orchestra cloud), a local JSON file, or S3
101
+
102
+ The CLI discovers `pyproject.toml` by walking upward from the current working directory. `[tool.orchestra_dbt]` is read from that file when present.
103
+
104
+ | Priority | Setting | Effect |
105
+ | -------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
106
+ | 1 | `ORCHESTRA_API_KEY` | Load/save state via Orchestra HTTP. The Orchestra environment is `orchestra_env` in pyproject (default `app`) or `ORCHESTRA_ENV` when set; must be one of `app`, `stage`, or `dev`. When the API key is set, `ORCHESTRA_STATE_FILE` and `state_file` in `pyproject.toml` are **ignored** for choosing the state backend. |
107
+ | 2 | `ORCHESTRA_STATE_FILE` | Path to a JSON file, or `s3://bucket/key` for an object in S3. Relative file paths are resolved from the current working directory. Used only when `ORCHESTRA_API_KEY` is unset. |
108
+ | 3 | `[tool.orchestra_dbt]` / `state_file` in `pyproject.toml` | Path to a JSON file, or `s3://bucket/key`. Relative file paths are resolved from the directory that contains the **discovered** `pyproject.toml`; absolute paths are used as-is. Used only when `ORCHESTRA_API_KEY` is unset and `ORCHESTRA_STATE_FILE` is unset. |
109
+
110
+ If an effective local path or S3 URI is configured (rows 2 or 3), that **file** or **S3** backend is used and an API key is not required for state. If `ORCHESTRA_API_KEY` is set (row 1), the **HTTP backend** is used regardless of file settings.
111
+
112
+ For S3, install the optional dependency (`pip install 'dbt-orchestra[s3]'` or `uv sync --extra s3`). Credentials and region follow the usual [AWS SDK resolution](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) (environment variables, shared config, IAM role, etc.). If the object does not exist yet, load starts with an empty state and save creates the object.
113
+
114
+ Stateful orchestration only runs for `dbt build`, `dbt run`, and `dbt test`. Other dbt subcommands are passed through to dbt unchanged.
115
+
116
+ ### Warehouse adapters and implicit source freshness
117
+
118
+ Stateful reuse uses `dbt source freshness` results. When a source defines `**loaded_at_field`** or `**loaded_at_query**`, dbt’s normal freshness logic runs on every adapter Orchestra supports through dbt Core.
119
+
120
+ When **both** are omitted, Orchestra can still run **adapter-specific** SQL to infer `max_loaded_at` (see `src/orchestra_dbt/source_freshness/`). Only the adapters below register that path today; the mapping is keyed by `FreshnessRunner.adapter.type()`.
121
+
122
+ | Warehouse | dbt adapter type (typical) | Implicit freshness (no `loaded_at_*`) |
123
+ | -------------------- | -------------------------- | ----------------------------------------------------------------------------------------------------------------- |
124
+ | **Databricks** | `databricks` | **Supported** — uses `DESCRIBE HISTORY` on the source relation. |
125
+ | **Snowflake** | `snowflake` | **Use `loaded_at_field` or `loaded_at_query`** — no Orchestra fallback; standard dbt freshness. |
126
+ | **Microsoft Fabric** | `fabric` | Same as Snowflake — configure `loaded_at_`*; no Orchestra fallback. |
127
+ | **PostgreSQL** | `postgres` | Same as Snowflake — configure `loaded_at_`*; no Orchestra fallback. |
128
+ | **DuckDB** | `duckdb` | **Not supported** |
129
+ | **Other adapters** | varies | No Orchestra fallback unless listed above; use `loaded_at_`* or verify dbt’s default behavior for your warehouse. |
130
+
131
+ For adapters without a registered fallback, if both `loaded_at` settings are missing, Orchestra follows dbt’s `FreshnessRunner` behavior (which may surface as warnings or a non-actionable result depending on dbt and the warehouse).
132
+
133
+ ### Runtime behavior by command and mode
134
+
135
+ | Stateful enabled | dbt command | Behavior |
136
+ | ---------------- | --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
137
+ | `false` | any command | `orc` passes through to dbt with no state load/save. |
138
+ | `true` | `build`, `run`, `test` | `orc` loads state, computes reusable nodes, patches clean nodes, runs dbt, updates and saves state. |
139
+ | `true` | `build`, `run`, `test` + `--full-refresh` | `orc` skips reuse decisions for this invocation, runs dbt directly, then still updates/saves state after execution. |
140
+ | `true` | other command (for example `seed`, `docs generate`) | `orc` passes through to dbt unchanged. |
141
+
142
+ Example optional snippet in `pyproject.toml`:
143
+
144
+ ```toml
145
+ [tool.orchestra_dbt]
146
+ use_stateful = true
147
+ orchestra_env = "dev"
148
+ state_file = ".orchestra/dbt_state.json"
149
+ ```
150
+
151
+ Add `.orchestra/` (or your chosen path) to `.gitignore` if the file should not be committed.
152
+
153
+ ### Bootstrapping a new local state file
154
+
155
+ If the configured **local** file does not exist, the CLI fails with an error (it does not silently start from empty state). Create a minimal file first, for example:
156
+
157
+ ```bash
158
+ mkdir -p .orchestra
159
+ echo '{"state":{}}' > .orchestra/dbt_state.json
160
+ ```
161
+
162
+ ## Running locally
163
+
164
+ Orchestra HTTP (requires an API key from Orchestra). Setting `ORCHESTRA_API_KEY` selects the HTTP backend; file-related settings are ignored. Put non-secret defaults in `pyproject.toml` and only export the API key:
165
+
166
+ ```toml
167
+ [tool.orchestra_dbt]
168
+ use_stateful = true
169
+ orchestra_env = "dev"
170
+ local_run = true
171
+ ```
172
+
173
+ ```bash
174
+ export ORCHESTRA_API_KEY=<API_KEY>
175
+ orc dbt run --target snowflake
176
+ ```
177
+
178
+ You can still override with env vars (for example `ORCHESTRA_ENV=stage`) when needed.
179
+
180
+ Local JSON file (after creating the file as above): **unset** `ORCHESTRA_API_KEY` so `ORCHESTRA_STATE_FILE` or `state_file` in `pyproject.toml` is used.
181
+
182
+ ```toml
183
+ [tool.orchestra_dbt]
184
+ use_stateful = true
185
+ state_file = ".orchestra/dbt_state.json"
186
+ local_run = true
187
+ ```
188
+
189
+ ```bash
190
+ orc dbt run --target snowflake
191
+ ```
192
+
193
+ ## Debugging
194
+
195
+ To debug pipelines, there are some local files and scripts.
196
+
197
+ To install the required dependencies, run:
198
+
199
+ ```bash
200
+ uv sync --extra dev --extra debug
201
+ ```
202
+
203
+ Ask @ojc-orchestra for access to the scripts:
204
+
205
+ - `dynamo_state.py`: loads state from DynamoDB into a local JSON file `local_state.json`
206
+ - `visualise.py`: loads ops from `ops.json` and visualises them in a DAG structure. This can be loaded in a browser by opening the resulting HTML file, `ops_dag.html`.
207
+
208
+ ## Testing
209
+
210
+ ```bash
211
+ pytest
212
+ ```
213
+
214
+ Without Postgres, the tutorial `dbt build` integration test is skipped. To run it locally, start Postgres, set `PGHOST`, `PGDATABASE`, and related variables (see `[tutorial/README.md](tutorial/README.md)`), then run `pytest tests/integration/test_tutorial_dbt.py`.
215
+
216
+ For the optional DAG integration test (`tests/integration/test_local.py`), place both `local_state.json` and `local_manifest.json` in the repository root. `local_state.json` can be created with `dynamo_state.py` (see above), and `local_manifest.json` can be downloaded from a representative dbt run.
217
+
218
+ Run only unit or integration tests:
219
+
220
+ ```bash
221
+ pytest tests/unit/
222
+ pytest tests/integration/
223
+ ```
224
+
225
+ Run a specific test module or case:
226
+
227
+ ```bash
228
+ pytest tests/unit/test_state.py
229
+ pytest tests/unit/test_state.py::TestLoadState::test_load_state_success
230
+ ```
231
+
232
+ ## Linting
233
+
234
+ ```bash
235
+ ruff check . && ruff format --check . && basedpyright
236
+ ```
237
+
238
+ To automatically fix issues:
239
+
240
+ ```bash
241
+ ruff check --fix . && ruff format . && basedpyright
242
+ ```
@@ -0,0 +1,42 @@
1
+ dbt_orchestra-0.4.0.dist-info/licenses/LICENSE,sha256=SCVQGLQfwOllsRFa9-Z3m8IYu4pnR9Vh2oANUCJiKqI,3860
2
+ orchestra_dbt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ orchestra_dbt/asset_external_id.py,sha256=tKMqAm0DUNSkpce83Upu7sowYMyz4oPVK_ZGFkOT3bc,755
4
+ orchestra_dbt/build_after.py,sha256=HVXUf-n9oJTx1clJ5FjfM7cS5AIPs6u2o5i1pp0U5Dg,5608
5
+ orchestra_dbt/checksum.py,sha256=4EGO177UadYdxrUjO6yorVmlRi9eZXWEH8pkmkhrHLo,856
6
+ orchestra_dbt/cli.py,sha256=fDJoj7mjkGJKJrqa2s3vcHRNZZQbkhC5SM_bdtkImnc,7033
7
+ orchestra_dbt/compatibility.py,sha256=w1GscfZubyLhpA3VMA9uyZMar-YImNhp52kKoI2yGDU,265
8
+ orchestra_dbt/config.py,sha256=6sQNKI9OdB5APoQkUrp40ZP8hrPou6Bv4vKeYHmc5NA,3960
9
+ orchestra_dbt/constants.py,sha256=zL8ARqNkbe1vJcYyfOYPnvE7kdIUpGwbVJP09EowetE,270
10
+ orchestra_dbt/dag.py,sha256=qRhKMAoWrF5rlMcLS0zSW_PCyVxdO6oUFVI0AR9GZY4,5740
11
+ orchestra_dbt/logger.py,sha256=ApFTcd3xZnDuxyo6qHaOuBQDNwCYSnhSaQo6HIjoRUQ,1122
12
+ orchestra_dbt/ls.py,sha256=Kse0G7f9eptaAK07iudj-KtdyVWrqC5FUrhIEFp-KDg,1462
13
+ orchestra_dbt/models.py,sha256=2MjN1mvDMmdTfcFLz3aD39E3oUReI0eBWUzUQM2fuVw,1241
14
+ orchestra_dbt/modify.py,sha256=NErzVG0MZSTkWdBMYXdhZI8UxiZPkIkAEXkuKOLdM7A,2439
15
+ orchestra_dbt/orchestra.py,sha256=OgsK3bbuJUn_9bmbYgNL_gBvVc4fzcFlfhQUVQWUV78,365
16
+ orchestra_dbt/patcher.py,sha256=kazTZ5YkUMawpHyHFUcdQj5CpY65wT_KoEfmScwJ208,7113
17
+ orchestra_dbt/project_discovery.py,sha256=jNV811W4b2sNH-eCPpnlUx65h9QxPdGpKE1COxKiQVE,721
18
+ orchestra_dbt/sao.py,sha256=MnDGPsuDoG0prVtpRtrHN1WckpavPpI_vrqKCZ-GgSk,6246
19
+ orchestra_dbt/state.py,sha256=6xuCRbXcWr4Uj3mwXcaA3m-Sx9x6LXREKOICthmZSYU,2463
20
+ orchestra_dbt/state_errors.py,sha256=cl9UE4tUczIq_Q3nFQKM856MwVZrKvthS4ToY_e5O10,215
21
+ orchestra_dbt/state_filters.py,sha256=mH0gaAxRme1ZrszsCJpF70SvHqM-hLVYiKwRy5cbRVw,348
22
+ orchestra_dbt/state_storage.py,sha256=RMo_eyo5U65FgAKZLIMvuUmm6eIAmbUsLDJlMY7n6ps,240
23
+ orchestra_dbt/state_types.py,sha256=JLHG5G2JnRWZ43pHHVnmI0rkD5KpPIQan-D5Yh2Ruxw,1623
24
+ orchestra_dbt/target_finder.py,sha256=nN25Nwpno95MOq3XiUjaJ3g5SwXU0loW4U2efg4HjfY,256
25
+ orchestra_dbt/utils.py,sha256=9dK8KOl1KvAC0vaENKIx842u6no0BvIpf1a6VCADLhk,430
26
+ orchestra_dbt/source_freshness/__init__.py,sha256=WGKyn72Bl7k_PLU2_8EjNBXuEjc0cqfvU8iiCFav8HA,2935
27
+ orchestra_dbt/source_freshness/fallbacks/__init__.py,sha256=HD3cuOesDsMsxDOEpiDY0EcA3lkWc4YCBf6wZmL8maI,221
28
+ orchestra_dbt/source_freshness/fallbacks/common.py,sha256=J1K9XjyyKmAvO0TaQIJN4OzbXhKNkW2BzCO3jXXpAD8,1857
29
+ orchestra_dbt/source_freshness/fallbacks/databricks.py,sha256=d4Ftde-8DYWcLCeCo7-yJbMPqAOxOoS5DAptIDmeFnc,1555
30
+ orchestra_dbt/source_freshness/fallbacks/registry.py,sha256=kiDi2PgwxGnijjozbrR-dlF4eR_lgujNFEGBTHZ_1BU,642
31
+ orchestra_dbt/state_backends/__init__.py,sha256=fI1_L2ofVY83Nve99Jpm-FBrxW920FwaNqC-tVTghfM,206
32
+ orchestra_dbt/state_backends/base.py,sha256=9jYa-dDk-tQes56rU99EbKE-llb7D77mT2yNJgJTRE0,192
33
+ orchestra_dbt/state_backends/factory.py,sha256=8m_sqYSA8HmihohEN1qTTppxOBfJDwROuB_zAGlP6-U,2086
34
+ orchestra_dbt/state_backends/http.py,sha256=mVAbX9wxLH67TTv2vQ6PgqmN7rfLpE97_7KMQZg76Z0,2555
35
+ orchestra_dbt/state_backends/local_file.py,sha256=LnBSDUHep7iLnD88AW0egAJEZcpXEtnXECzymzAjWP0,1896
36
+ orchestra_dbt/state_backends/logging.py,sha256=GbvNuR8TLGnwcx5V5JIFDL-2GTyfFJUAaXOo1hcj7sU,648
37
+ orchestra_dbt/state_backends/s3.py,sha256=JmpF9p26po87oEcYPQ3gq7iZwLLBZVA8K-MZC9fP9LY,2458
38
+ dbt_orchestra-0.4.0.dist-info/METADATA,sha256=9zJD9RmAgEFWyiZ1LukzMaOQzPYVyF2YVz2whFC3G-A,13703
39
+ dbt_orchestra-0.4.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
40
+ dbt_orchestra-0.4.0.dist-info/entry_points.txt,sha256=7FHwkDg1ZrNnME9Pg7qrkmzULSQh8G_52skVcN_xi00,47
41
+ dbt_orchestra-0.4.0.dist-info/top_level.txt,sha256=baPn2XxMqYvQjWGc8zpItNrfHyRvF_jgt_GwnAM_ZQs,14
42
+ dbt_orchestra-0.4.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ orc = orchestra_dbt.cli:main
@@ -0,0 +1,93 @@
1
+ Elastic License 2.0
2
+
3
+ URL: https://www.elastic.co/licensing/elastic-license
4
+
5
+ ## Acceptance
6
+
7
+ By using the software, you agree to all of the terms and conditions below.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
12
+ non-sublicensable, non-transferable license to use, copy, distribute, make
13
+ available, and prepare derivative works of the software, in each case subject to
14
+ the limitations and conditions below.
15
+
16
+ ## Limitations
17
+
18
+ You may not provide the software to third parties as a hosted or managed
19
+ service, where the service provides users with access to any substantial set of
20
+ the features or functionality of the software.
21
+
22
+ You may not move, change, disable, or circumvent the license key functionality
23
+ in the software, and you may not remove or obscure any functionality in the
24
+ software that is protected by the license key.
25
+
26
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
27
+ of the licensor in the software. Any use of the licensor’s trademarks is subject
28
+ to applicable law.
29
+
30
+ ## Patents
31
+
32
+ The licensor grants you a license, under any patent claims the licensor can
33
+ license, or becomes able to license, to make, have made, use, sell, offer for
34
+ sale, import and have imported the software, in each case subject to the
35
+ limitations and conditions in this license. This license does not cover any
36
+ patent claims that you cause to be infringed by modifications or additions to
37
+ the software. If you or your company make any written claim that the software
38
+ infringes or contributes to infringement of any patent, your patent license for
39
+ the software granted under these terms ends immediately. If your company makes
40
+ such a claim, your patent license ends immediately for work on behalf of your
41
+ company.
42
+
43
+ ## Notices
44
+
45
+ You must ensure that anyone who gets a copy of any part of the software from you
46
+ also gets a copy of these terms.
47
+
48
+ If you modify the software, you must include in any modified copies of the
49
+ software prominent notices stating that you have modified the software.
50
+
51
+ ## No Other Rights
52
+
53
+ These terms do not imply any licenses other than those expressly granted in
54
+ these terms.
55
+
56
+ ## Termination
57
+
58
+ If you use the software in violation of these terms, such use is not licensed,
59
+ and your licenses will automatically terminate. If the licensor provides you
60
+ with a notice of your violation, and you cease all violation of this license no
61
+ later than 30 days after you receive that notice, your licenses will be
62
+ reinstated retroactively. However, if you violate these terms after such
63
+ reinstatement, any additional violation of these terms will cause your licenses
64
+ to terminate automatically and permanently.
65
+
66
+ ## No Liability
67
+
68
+ *As far as the law allows, the software comes as is, without any warranty or
69
+ condition, and the licensor will not be liable to you for any damages arising
70
+ out of these terms or the use or nature of the software, under any kind of
71
+ legal claim.*
72
+
73
+ ## Definitions
74
+
75
+ The **licensor** is the entity offering these terms, and the **software** is the
76
+ software the licensor makes available under these terms, including any portion
77
+ of it.
78
+
79
+ **you** refers to the individual or entity agreeing to these terms.
80
+
81
+ **your company** is any legal entity, sole proprietorship, or other kind of
82
+ organization that you work for, plus all organizations that have control over,
83
+ are under the control of, or are under common control with that
84
+ organization. **control** means ownership of substantially all the assets of an
85
+ entity, or the power to direct its management and policies by vote, contract, or
86
+ otherwise. Control can be direct or indirect.
87
+
88
+ **your licenses** are all the licenses granted to you for the software under
89
+ these terms.
90
+
91
+ **use** means anything you do with the software requiring one of your licenses.
92
+
93
+ **trademark** means trademarks, service marks, and similar rights.
@@ -0,0 +1 @@
1
+ orchestra_dbt
File without changes
@@ -0,0 +1,25 @@
1
+ from .logger import log_warn
2
+
3
+
4
+ def generate_asset_external_id(
5
+ node_id: str,
6
+ relation_name: str | None,
7
+ integration_account_id: str | None,
8
+ local_run: bool = True,
9
+ ) -> str:
10
+ """
11
+ Generate a stable external ID used for Orchestra state keys.
12
+
13
+ When `local_run` is true (from `[tool.orchestra_dbt]` / `ORCHESTRA_LOCAL_RUN`),
14
+ IDs match a plain dbt run and use `node_id` only.
15
+ """
16
+ if not integration_account_id or local_run:
17
+ return node_id
18
+
19
+ if not relation_name:
20
+ log_warn(
21
+ f"No relation name found for node '{node_id}'. Using node ID fallback for the asset external ID."
22
+ )
23
+ return f"{integration_account_id}.{node_id}"
24
+
25
+ return f"{integration_account_id}.{relation_name}"
@@ -0,0 +1,155 @@
1
+ from collections import defaultdict, deque
2
+ from typing import cast
3
+
4
+ from .models import FreshnessConfig, MaterialisationNode, Node, NodeType, ParsedDag
5
+
6
+
7
+ def parse_build_after_duration_minutes(build_after: dict[str, str | int]) -> int:
8
+ period = build_after["period"] # minute | hour | day
9
+ match period:
10
+ case "minute":
11
+ mins_multiplier = 1
12
+ case "hour":
13
+ mins_multiplier = 60
14
+ case "day":
15
+ mins_multiplier = 1440
16
+ case _:
17
+ raise ValueError(f"Invalid period: {period}")
18
+
19
+ count = build_after["count"]
20
+ if not isinstance(count, int):
21
+ raise ValueError(f"Invalid count: {count}")
22
+
23
+ return count * mins_multiplier
24
+
25
+
26
+ def parse_freshness_config(config_on_node: dict | None) -> FreshnessConfig:
27
+ freshness_config = FreshnessConfig()
28
+ if config_on_node and "build_after" in config_on_node:
29
+ build_after_config = config_on_node["build_after"]
30
+ if "updates_on" in build_after_config:
31
+ updates_on = str(build_after_config["updates_on"]).lower()
32
+ match updates_on:
33
+ case "any" | "all":
34
+ freshness_config.updates_on = updates_on
35
+ case _:
36
+ freshness_config.updates_on = "any"
37
+ freshness_config.minutes_sla = parse_build_after_duration_minutes(
38
+ build_after_config
39
+ )
40
+ return freshness_config
41
+
42
+
43
+ def _build_reverse_dependency_graphs(
44
+ dag: ParsedDag,
45
+ ) -> tuple[dict[str, list[str]], dict[str, list[str]], dict[str, int]]:
46
+ """
47
+ Build reverse dependency graph structures from DAG edges for backwards traversal.
48
+
49
+ Returns:
50
+ - children: parent -> list of children
51
+ - parents: child -> list of parents
52
+ - out_degree: node -> number of downstream dependencies (children count)
53
+ """
54
+ children: dict[str, list[str]] = defaultdict(list)
55
+ parents: dict[str, list[str]] = defaultdict(list)
56
+ out_degree: dict[str, int] = defaultdict(int)
57
+
58
+ for edge in dag.edges:
59
+ parent, child = edge.from_, edge.to_
60
+ children[parent].append(child)
61
+ parents[child].append(parent)
62
+ out_degree[parent] += 1
63
+
64
+ # Initialize out_degree for all nodes (nodes with no children will have 0)
65
+ for node_id in dag.nodes.keys():
66
+ if node_id not in out_degree:
67
+ out_degree[node_id] = 0
68
+
69
+ return children, parents, out_degree
70
+
71
+
72
+ def _propagate_config_to_node(
73
+ node_id: str, children: dict[str, list[str]], dag: ParsedDag
74
+ ) -> None:
75
+ """
76
+ Propagate freshness config from children to the current node.
77
+ A parent only inherits the minimum config of its children if ALL children
78
+ have a defined config; if any child is undefined or has no config, the
79
+ parent remains null.
80
+ """
81
+ node: Node = dag.nodes[node_id]
82
+ if node.node_type != NodeType.MATERIALISATION:
83
+ return
84
+
85
+ materialisation_node: MaterialisationNode = cast(MaterialisationNode, node)
86
+
87
+ # If the node already has a config, don't change it
88
+ if materialisation_node.freshness_config.minutes_sla is not None:
89
+ return
90
+
91
+ child_ids = children.get(node_id, [])
92
+ if not child_ids:
93
+ return
94
+
95
+ # Collect minutes_sla from children; if any child has no config, do not propagate
96
+ child_minutes: list[int] = []
97
+ for child_id in child_ids:
98
+ child_node = dag.nodes.get(child_id)
99
+ if child_node is None or child_node.node_type != NodeType.MATERIALISATION:
100
+ return # undefined or non-materialisation child: parent stays null
101
+ child_materialisation: MaterialisationNode = cast(
102
+ MaterialisationNode, child_node
103
+ )
104
+ if child_materialisation.freshness_config.minutes_sla is None:
105
+ return # child has no config: parent stays null
106
+ child_minutes.append(child_materialisation.freshness_config.minutes_sla)
107
+
108
+ # All children have a defined config: inherit the minimum
109
+ min_sla = min(child_minutes)
110
+ materialisation_node.freshness_config.minutes_sla = min_sla
111
+ for cid in child_ids:
112
+ if (
113
+ cast(MaterialisationNode, dag.nodes[cid]).freshness_config.minutes_sla
114
+ == min_sla
115
+ ):
116
+ materialisation_node.freshness_config.inherited_from = cid
117
+ break
118
+
119
+
120
+ def _enqueue_parents(
121
+ node_id: str,
122
+ parents: dict[str, list[str]],
123
+ out_degree: dict[str, int],
124
+ queue: deque[str],
125
+ ) -> None:
126
+ """Enqueue parent nodes for processing after the current node is processed."""
127
+ for parent in parents[node_id]:
128
+ out_degree[parent] -= 1
129
+ if out_degree[parent] == 0:
130
+ queue.append(parent)
131
+
132
+
133
+ def propagate_freshness_config(parsed_dag: ParsedDag) -> None:
134
+ """
135
+ Propagate freshness config backwards through the DAG.
136
+
137
+ Starts at nodes with no children (end of DAG) and works backwards,
138
+ propagating the minimum minutes_sla from children to parents.
139
+ Only updates nodes that don't already have a config.
140
+ """
141
+ children, parents, out_degree = _build_reverse_dependency_graphs(parsed_dag)
142
+
143
+ # Queue for nodes with no children (out_degree 0) - these are at the end of the DAG
144
+ queue = deque[str]([n for n in parsed_dag.nodes.keys() if out_degree[n] == 0])
145
+
146
+ while queue:
147
+ current = queue.popleft()
148
+
149
+ # Process the node to potentially propagate config from children
150
+ _propagate_config_to_node(node_id=current, children=children, dag=parsed_dag)
151
+
152
+ # Queue parents for processing (work backwards)
153
+ _enqueue_parents(
154
+ node_id=current, parents=parents, out_degree=out_degree, queue=queue
155
+ )
@@ -0,0 +1,26 @@
1
+ from hashlib import sha256
2
+ from os.path import getsize
3
+
4
+ from .constants import MAX_SEED_SIZE_BYTES
5
+ from .logger import log_error, log_warn
6
+ from .utils import load_seed_bytes
7
+
8
+
9
+ def calculate_checksum(
10
+ resource_type: str, node_checksum: str, file_path: str
11
+ ) -> str | None:
12
+ if resource_type != "seed":
13
+ return node_checksum
14
+
15
+ try:
16
+ file_size = getsize(file_path)
17
+ if file_size > MAX_SEED_SIZE_BYTES:
18
+ log_warn(
19
+ f"Seed file {file_path} ({file_size / 1024 / 1024:.2f}MB) is over "
20
+ f"{MAX_SEED_SIZE_BYTES / 1024 / 1024:.2f}MB. Skipping checksum."
21
+ )
22
+ return None
23
+ return sha256(load_seed_bytes(file_path)).hexdigest()
24
+ except FileNotFoundError:
25
+ log_error(f"Seed file {file_path} not found. Cannot check state for this node.")
26
+ return None