dbt-state-oss 0.1.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.
- dbt_state_oss-0.1.0/LICENSE +202 -0
- dbt_state_oss-0.1.0/PKG-INFO +178 -0
- dbt_state_oss-0.1.0/README.md +142 -0
- dbt_state_oss-0.1.0/dbt_state_oss/__init__.py +5 -0
- dbt_state_oss-0.1.0/dbt_state_oss/__main__.py +71 -0
- dbt_state_oss-0.1.0/dbt_state_oss/fingerprint.py +48 -0
- dbt_state_oss-0.1.0/dbt_state_oss/servicers.py +203 -0
- dbt_state_oss-0.1.0/dbt_state_oss/store.py +256 -0
- dbt_state_oss-0.1.0/dbt_state_oss.egg-info/PKG-INFO +178 -0
- dbt_state_oss-0.1.0/dbt_state_oss.egg-info/SOURCES.txt +17 -0
- dbt_state_oss-0.1.0/dbt_state_oss.egg-info/dependency_links.txt +1 -0
- dbt_state_oss-0.1.0/dbt_state_oss.egg-info/entry_points.txt +2 -0
- dbt_state_oss-0.1.0/dbt_state_oss.egg-info/requires.txt +19 -0
- dbt_state_oss-0.1.0/dbt_state_oss.egg-info/top_level.txt +1 -0
- dbt_state_oss-0.1.0/pyproject.toml +49 -0
- dbt_state_oss-0.1.0/setup.cfg +4 -0
- dbt_state_oss-0.1.0/tests/test_make_store.py +75 -0
- dbt_state_oss-0.1.0/tests/test_s3_store.py +104 -0
- dbt_state_oss-0.1.0/tests/test_store_unit.py +35 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dbt-state-oss
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Self-hosted decision server for the dbt-state client, with pluggable state storage.
|
|
5
|
+
Author: Pradip Sodha
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/sudo-pradip/dbt-state-oss
|
|
8
|
+
Project-URL: Repository, https://github.com/sudo-pradip/dbt-state-oss
|
|
9
|
+
Project-URL: Issues, https://github.com/sudo-pradip/dbt-state-oss/issues
|
|
10
|
+
Keywords: dbt,dbt-state,grpc,cache,state,s3,azure
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Database
|
|
15
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: query-cache-protobuf>=1.6.0
|
|
20
|
+
Requires-Dist: grpcio>=1.60.0
|
|
21
|
+
Requires-Dist: protobuf>=4.0.0
|
|
22
|
+
Requires-Dist: sqlglot>=27.6.1
|
|
23
|
+
Provides-Extra: azure
|
|
24
|
+
Requires-Dist: azure-identity; extra == "azure"
|
|
25
|
+
Requires-Dist: azure-storage-blob; extra == "azure"
|
|
26
|
+
Provides-Extra: s3
|
|
27
|
+
Requires-Dist: boto3>=1.28; extra == "s3"
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: dbt-core<2.0,>=1.9; extra == "dev"
|
|
30
|
+
Requires-Dist: dbt-postgres<2.0,>=1.9; extra == "dev"
|
|
31
|
+
Requires-Dist: dbt-state; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest; extra == "dev"
|
|
33
|
+
Requires-Dist: build; extra == "dev"
|
|
34
|
+
Requires-Dist: twine; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# dbt-state-oss
|
|
38
|
+
|
|
39
|
+
An open-source, self-hosted decision server for the Apache-2.0
|
|
40
|
+
[`dbt-state`](https://github.com/dbt-labs/dbt-state) client, keeping the state
|
|
41
|
+
store in **your own storage** (local disk, S3, or Azure Blob) instead of dbt
|
|
42
|
+
Labs' hosted, metered service.
|
|
43
|
+
|
|
44
|
+
## Why
|
|
45
|
+
|
|
46
|
+
`dbt-state` skips redundant model executions ("NO-OP" on a second run) and
|
|
47
|
+
auto-defers to prod, without a manifest. But the **decision engine is a hosted,
|
|
48
|
+
metered gRPC service** (`api.state.dbt.com`); the pip package is only a client.
|
|
49
|
+
With no auth, the client silently disables itself and dbt runs vanilla.
|
|
50
|
+
|
|
51
|
+
The client, the protobuf protocol, and the shared libs are all **Apache-2.0**.
|
|
52
|
+
Only the server is closed. This project builds an open replacement server that:
|
|
53
|
+
|
|
54
|
+
- speaks the same gRPC protocol (reuses the client's `*Servicer` stubs),
|
|
55
|
+
- keeps all state in **your own storage** (local disk, S3, or Azure Blob),
|
|
56
|
+
- needs **no dbt Labs account** (insecure channel for dev; your own OAuth/Entra ID for prod).
|
|
57
|
+
|
|
58
|
+
## How the client/server split works (verified against the wheel)
|
|
59
|
+
|
|
60
|
+
- **Client (unchanged, Apache-2.0):** compiles model SQL, extracts deps + table
|
|
61
|
+
refs (sqlglot), reads each input's `last_modified` from the warehouse via an
|
|
62
|
+
adapter extension, hashes seed files, ships **raw SQL + metadata** over gRPC,
|
|
63
|
+
acts on the verdict, and reports outcomes back.
|
|
64
|
+
- **Server (this repo):** computes a semantic fingerprint, matches it against
|
|
65
|
+
stored history for the target table, checks freshness + execution_type, and
|
|
66
|
+
returns **skip / clone / execute**. Persists run records to your chosen
|
|
67
|
+
backend (local, S3, or Azure Blob).
|
|
68
|
+
|
|
69
|
+
Our fingerprint algorithm only has to be **self-consistent** between
|
|
70
|
+
"record a run" and "check a run" - it does not need to match dbt Labs'.
|
|
71
|
+
|
|
72
|
+
## Auth
|
|
73
|
+
|
|
74
|
+
- **Dev / trusted network:** `RUN_CACHE_API_URL=localhost:50051` (non-:443) or
|
|
75
|
+
`RUN_CACHE_API_SECURE=false` -> insecure channel, zero OAuth. In CI/non-interactive,
|
|
76
|
+
set `RUN_CACHE_OAUTH_CLIENT_SECRET=<dummy>` to pass the client's disable-gate
|
|
77
|
+
(presence-checked only; never used on an insecure channel).
|
|
78
|
+
- **Production:** TLS + override `RUN_CACHE_AUTH_URL`/`RUN_CACHE_TOKEN_URL` to your
|
|
79
|
+
own IdP (e.g. Azure Entra ID, same identity that guards your storage). Client does
|
|
80
|
+
OAuth2 and attaches a bearer token; the server validates the JWT.
|
|
81
|
+
|
|
82
|
+
## Repo layout
|
|
83
|
+
|
|
84
|
+
(The pip package ships only `dbt_state_oss/`; the rest is for development.)
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
dbt_state_oss/ the gRPC decision server (the engine)
|
|
88
|
+
example_project/ a tiny dbt-postgres project (seed -> staging -> mart) for local testing
|
|
89
|
+
tests/ unit + S3 integration tests
|
|
90
|
+
docs/ PROTOCOL.md (the reverse-engineered contract), FINDINGS.md (the eval)
|
|
91
|
+
reference/ local copy of dbt-labs' Apache-2.0 client source (gitignored, not committed)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Status
|
|
95
|
+
|
|
96
|
+
**v1 works** — postgres warehouse; `local`, `s3`, and `azure` state stores.
|
|
97
|
+
Verified end-to-end against our own server with zero dbt Labs:
|
|
98
|
+
|
|
99
|
+
| scenario | result |
|
|
100
|
+
|---|---|
|
|
101
|
+
| second run, nothing changed | all models **NO-OP** (reused, no SQL run) |
|
|
102
|
+
| comment / whitespace-only edit | **NO-OP** (semantic fingerprint) |
|
|
103
|
+
| real SQL change to a model | that model rebuilds |
|
|
104
|
+
| real change upstream | downstream rebuilds too (freshness check, cache stays safe) |
|
|
105
|
+
| seed file unchanged | seed **NO-OP** (via values_hash) |
|
|
106
|
+
|
|
107
|
+
Requires postgres `track_commit_timestamp=on` (the client reads freshness from
|
|
108
|
+
`pg_xact_commit_timestamp`); the local docker postgres sets it.
|
|
109
|
+
|
|
110
|
+
### State backends
|
|
111
|
+
|
|
112
|
+
Pick the backend with `--store` (or the `STATE_STORE` env var). Each backend's
|
|
113
|
+
config takes a CLI flag that falls back to its env var. All backends implement
|
|
114
|
+
the same two-method `StateStore` interface, so the roadmap entries are additive.
|
|
115
|
+
|
|
116
|
+
| backend | status | flags | env |
|
|
117
|
+
|---|---|---|---|
|
|
118
|
+
| `local` | supported | `--dir` | `DBTSTATE_LOCAL_DIR` |
|
|
119
|
+
| `s3` | supported | `--bucket`, `--prefix` | `DBTSTATE_S3_BUCKET`, `DBTSTATE_S3_PREFIX` |
|
|
120
|
+
| `azure` | supported | `--account`, `--container`, `--prefix` | `DBTSTATE_AZURE_ACCOUNT`, `DBTSTATE_AZURE_CONTAINER`, `DBTSTATE_AZURE_PREFIX` |
|
|
121
|
+
| `memory` | dev/test only | - | - |
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
dbt-state-oss --store s3 --bucket my-bucket
|
|
125
|
+
dbt-state-oss --store azure --account acct --container dbt-state
|
|
126
|
+
dbt-state-oss --store local --dir ./.state_data
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Roadmap (not yet implemented):**
|
|
130
|
+
- Google Cloud Storage (`gcs`)
|
|
131
|
+
- Fabric OneLake files
|
|
132
|
+
|
|
133
|
+
**Azure auth:** `DefaultAzureCredential` (`az login` locally, OIDC/workload-identity
|
|
134
|
+
in CI, managed identity on Azure). The identity needs the **Storage Blob Data
|
|
135
|
+
Contributor** role on the account (control-plane Owner/Contributor is NOT enough):
|
|
136
|
+
```bash
|
|
137
|
+
az role assignment create --assignee-object-id <your-oid> --assignee-principal-type User \
|
|
138
|
+
--role "Storage Blob Data Contributor" \
|
|
139
|
+
--scope /subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.Storage/storageAccounts/<acct>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**S3 auth:** the boto3 default credential chain (IAM role, instance profile, SSO,
|
|
143
|
+
`AWS_*` env vars, or `~/.aws/credentials`). No keys are read from this repo. The
|
|
144
|
+
identity needs read/write on the bucket; region comes from your standard AWS
|
|
145
|
+
configuration. After `pip install "dbt-state-oss[s3]"`, start the server with
|
|
146
|
+
`dbt-state-oss --store s3 --bucket <bucket>`.
|
|
147
|
+
|
|
148
|
+
Next milestones: GCS / OneLake backends -> fabricspark adapter extension -> clone + prod auth.
|
|
149
|
+
|
|
150
|
+
## Install & run
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
pip install dbt-state-oss # add [s3] or [azure] for those backends
|
|
154
|
+
dbt-state-oss --store local --port 50051
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Then point your dbt-state client at the server (client env vars use the
|
|
158
|
+
`RUN_CACHE_` prefix):
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
export RUN_CACHE_API_URL=localhost:50051 RUN_CACHE_API_SECURE=false RUN_CACHE_OAUTH_CLIENT_SECRET=dev
|
|
162
|
+
dbt build # in your dbt project; run twice and the second run NO-OPs
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
`RUN_CACHE_API_SECURE=false` selects an insecure channel (no OAuth);
|
|
166
|
+
`RUN_CACHE_OAUTH_CLIENT_SECRET` only needs to be *present* to pass the client's
|
|
167
|
+
enable-gate in non-interactive runs. Switch backends with `--store` (see the
|
|
168
|
+
table above), e.g. `dbt-state-oss --store azure --account <acct>` after `az login`.
|
|
169
|
+
|
|
170
|
+
## The NO-OP demo (from a clone)
|
|
171
|
+
|
|
172
|
+
A runnable seed -> staging -> mart project that NO-OPs on the second run lives in
|
|
173
|
+
`example_project/`. It ships only in the repo (not the pip package) and needs a
|
|
174
|
+
postgres with `track_commit_timestamp=on` — the client reads freshness from
|
|
175
|
+
`pg_xact_commit_timestamp`. The example profile expects postgres on `:5433`,
|
|
176
|
+
database `dbt_oss`. Clone the repo, install with the `dev` extra, start the
|
|
177
|
+
server (`--store local`), then `dbt build --target prod` twice from
|
|
178
|
+
`example_project/`.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# dbt-state-oss
|
|
2
|
+
|
|
3
|
+
An open-source, self-hosted decision server for the Apache-2.0
|
|
4
|
+
[`dbt-state`](https://github.com/dbt-labs/dbt-state) client, keeping the state
|
|
5
|
+
store in **your own storage** (local disk, S3, or Azure Blob) instead of dbt
|
|
6
|
+
Labs' hosted, metered service.
|
|
7
|
+
|
|
8
|
+
## Why
|
|
9
|
+
|
|
10
|
+
`dbt-state` skips redundant model executions ("NO-OP" on a second run) and
|
|
11
|
+
auto-defers to prod, without a manifest. But the **decision engine is a hosted,
|
|
12
|
+
metered gRPC service** (`api.state.dbt.com`); the pip package is only a client.
|
|
13
|
+
With no auth, the client silently disables itself and dbt runs vanilla.
|
|
14
|
+
|
|
15
|
+
The client, the protobuf protocol, and the shared libs are all **Apache-2.0**.
|
|
16
|
+
Only the server is closed. This project builds an open replacement server that:
|
|
17
|
+
|
|
18
|
+
- speaks the same gRPC protocol (reuses the client's `*Servicer` stubs),
|
|
19
|
+
- keeps all state in **your own storage** (local disk, S3, or Azure Blob),
|
|
20
|
+
- needs **no dbt Labs account** (insecure channel for dev; your own OAuth/Entra ID for prod).
|
|
21
|
+
|
|
22
|
+
## How the client/server split works (verified against the wheel)
|
|
23
|
+
|
|
24
|
+
- **Client (unchanged, Apache-2.0):** compiles model SQL, extracts deps + table
|
|
25
|
+
refs (sqlglot), reads each input's `last_modified` from the warehouse via an
|
|
26
|
+
adapter extension, hashes seed files, ships **raw SQL + metadata** over gRPC,
|
|
27
|
+
acts on the verdict, and reports outcomes back.
|
|
28
|
+
- **Server (this repo):** computes a semantic fingerprint, matches it against
|
|
29
|
+
stored history for the target table, checks freshness + execution_type, and
|
|
30
|
+
returns **skip / clone / execute**. Persists run records to your chosen
|
|
31
|
+
backend (local, S3, or Azure Blob).
|
|
32
|
+
|
|
33
|
+
Our fingerprint algorithm only has to be **self-consistent** between
|
|
34
|
+
"record a run" and "check a run" - it does not need to match dbt Labs'.
|
|
35
|
+
|
|
36
|
+
## Auth
|
|
37
|
+
|
|
38
|
+
- **Dev / trusted network:** `RUN_CACHE_API_URL=localhost:50051` (non-:443) or
|
|
39
|
+
`RUN_CACHE_API_SECURE=false` -> insecure channel, zero OAuth. In CI/non-interactive,
|
|
40
|
+
set `RUN_CACHE_OAUTH_CLIENT_SECRET=<dummy>` to pass the client's disable-gate
|
|
41
|
+
(presence-checked only; never used on an insecure channel).
|
|
42
|
+
- **Production:** TLS + override `RUN_CACHE_AUTH_URL`/`RUN_CACHE_TOKEN_URL` to your
|
|
43
|
+
own IdP (e.g. Azure Entra ID, same identity that guards your storage). Client does
|
|
44
|
+
OAuth2 and attaches a bearer token; the server validates the JWT.
|
|
45
|
+
|
|
46
|
+
## Repo layout
|
|
47
|
+
|
|
48
|
+
(The pip package ships only `dbt_state_oss/`; the rest is for development.)
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
dbt_state_oss/ the gRPC decision server (the engine)
|
|
52
|
+
example_project/ a tiny dbt-postgres project (seed -> staging -> mart) for local testing
|
|
53
|
+
tests/ unit + S3 integration tests
|
|
54
|
+
docs/ PROTOCOL.md (the reverse-engineered contract), FINDINGS.md (the eval)
|
|
55
|
+
reference/ local copy of dbt-labs' Apache-2.0 client source (gitignored, not committed)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Status
|
|
59
|
+
|
|
60
|
+
**v1 works** — postgres warehouse; `local`, `s3`, and `azure` state stores.
|
|
61
|
+
Verified end-to-end against our own server with zero dbt Labs:
|
|
62
|
+
|
|
63
|
+
| scenario | result |
|
|
64
|
+
|---|---|
|
|
65
|
+
| second run, nothing changed | all models **NO-OP** (reused, no SQL run) |
|
|
66
|
+
| comment / whitespace-only edit | **NO-OP** (semantic fingerprint) |
|
|
67
|
+
| real SQL change to a model | that model rebuilds |
|
|
68
|
+
| real change upstream | downstream rebuilds too (freshness check, cache stays safe) |
|
|
69
|
+
| seed file unchanged | seed **NO-OP** (via values_hash) |
|
|
70
|
+
|
|
71
|
+
Requires postgres `track_commit_timestamp=on` (the client reads freshness from
|
|
72
|
+
`pg_xact_commit_timestamp`); the local docker postgres sets it.
|
|
73
|
+
|
|
74
|
+
### State backends
|
|
75
|
+
|
|
76
|
+
Pick the backend with `--store` (or the `STATE_STORE` env var). Each backend's
|
|
77
|
+
config takes a CLI flag that falls back to its env var. All backends implement
|
|
78
|
+
the same two-method `StateStore` interface, so the roadmap entries are additive.
|
|
79
|
+
|
|
80
|
+
| backend | status | flags | env |
|
|
81
|
+
|---|---|---|---|
|
|
82
|
+
| `local` | supported | `--dir` | `DBTSTATE_LOCAL_DIR` |
|
|
83
|
+
| `s3` | supported | `--bucket`, `--prefix` | `DBTSTATE_S3_BUCKET`, `DBTSTATE_S3_PREFIX` |
|
|
84
|
+
| `azure` | supported | `--account`, `--container`, `--prefix` | `DBTSTATE_AZURE_ACCOUNT`, `DBTSTATE_AZURE_CONTAINER`, `DBTSTATE_AZURE_PREFIX` |
|
|
85
|
+
| `memory` | dev/test only | - | - |
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
dbt-state-oss --store s3 --bucket my-bucket
|
|
89
|
+
dbt-state-oss --store azure --account acct --container dbt-state
|
|
90
|
+
dbt-state-oss --store local --dir ./.state_data
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Roadmap (not yet implemented):**
|
|
94
|
+
- Google Cloud Storage (`gcs`)
|
|
95
|
+
- Fabric OneLake files
|
|
96
|
+
|
|
97
|
+
**Azure auth:** `DefaultAzureCredential` (`az login` locally, OIDC/workload-identity
|
|
98
|
+
in CI, managed identity on Azure). The identity needs the **Storage Blob Data
|
|
99
|
+
Contributor** role on the account (control-plane Owner/Contributor is NOT enough):
|
|
100
|
+
```bash
|
|
101
|
+
az role assignment create --assignee-object-id <your-oid> --assignee-principal-type User \
|
|
102
|
+
--role "Storage Blob Data Contributor" \
|
|
103
|
+
--scope /subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.Storage/storageAccounts/<acct>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**S3 auth:** the boto3 default credential chain (IAM role, instance profile, SSO,
|
|
107
|
+
`AWS_*` env vars, or `~/.aws/credentials`). No keys are read from this repo. The
|
|
108
|
+
identity needs read/write on the bucket; region comes from your standard AWS
|
|
109
|
+
configuration. After `pip install "dbt-state-oss[s3]"`, start the server with
|
|
110
|
+
`dbt-state-oss --store s3 --bucket <bucket>`.
|
|
111
|
+
|
|
112
|
+
Next milestones: GCS / OneLake backends -> fabricspark adapter extension -> clone + prod auth.
|
|
113
|
+
|
|
114
|
+
## Install & run
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pip install dbt-state-oss # add [s3] or [azure] for those backends
|
|
118
|
+
dbt-state-oss --store local --port 50051
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Then point your dbt-state client at the server (client env vars use the
|
|
122
|
+
`RUN_CACHE_` prefix):
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
export RUN_CACHE_API_URL=localhost:50051 RUN_CACHE_API_SECURE=false RUN_CACHE_OAUTH_CLIENT_SECRET=dev
|
|
126
|
+
dbt build # in your dbt project; run twice and the second run NO-OPs
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`RUN_CACHE_API_SECURE=false` selects an insecure channel (no OAuth);
|
|
130
|
+
`RUN_CACHE_OAUTH_CLIENT_SECRET` only needs to be *present* to pass the client's
|
|
131
|
+
enable-gate in non-interactive runs. Switch backends with `--store` (see the
|
|
132
|
+
table above), e.g. `dbt-state-oss --store azure --account <acct>` after `az login`.
|
|
133
|
+
|
|
134
|
+
## The NO-OP demo (from a clone)
|
|
135
|
+
|
|
136
|
+
A runnable seed -> staging -> mart project that NO-OPs on the second run lives in
|
|
137
|
+
`example_project/`. It ships only in the repo (not the pip package) and needs a
|
|
138
|
+
postgres with `track_commit_timestamp=on` — the client reads freshness from
|
|
139
|
+
`pg_xact_commit_timestamp`. The example profile expects postgres on `:5433`,
|
|
140
|
+
database `dbt_oss`. Clone the repo, install with the `dev` extra, start the
|
|
141
|
+
server (`--store local`), then `dbt build --target prod` twice from
|
|
142
|
+
`example_project/`.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Run the dbt-state-oss decision server.
|
|
2
|
+
|
|
3
|
+
dbt-state-oss --store s3 --bucket my-bucket --port 50051
|
|
4
|
+
|
|
5
|
+
Point the dbt-state client at it with:
|
|
6
|
+
RUN_CACHE_API_URL=localhost:50051 RUN_CACHE_API_SECURE=false RUN_CACHE_OAUTH_CLIENT_SECRET=dev
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import os
|
|
12
|
+
from concurrent import futures
|
|
13
|
+
|
|
14
|
+
import grpc
|
|
15
|
+
|
|
16
|
+
from query_cache_protobuf.query_cache.services import (
|
|
17
|
+
client_validation_service_pb2_grpc as val_grpc,
|
|
18
|
+
execution_service_pb2_grpc as exec_grpc,
|
|
19
|
+
health_service_pb2_grpc as health_grpc,
|
|
20
|
+
sql_service_pb2_grpc as sql_grpc,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
from .servicers import (
|
|
24
|
+
ClientValidationServicer,
|
|
25
|
+
ExecutionServicer,
|
|
26
|
+
HealthServicer,
|
|
27
|
+
SQLServicer,
|
|
28
|
+
_Pending,
|
|
29
|
+
_log,
|
|
30
|
+
)
|
|
31
|
+
from .store import make_store
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def serve(port: int, store) -> None:
|
|
35
|
+
pending = _Pending()
|
|
36
|
+
|
|
37
|
+
server = grpc.server(futures.ThreadPoolExecutor(max_workers=16))
|
|
38
|
+
sql_grpc.add_SQLServicer_to_server(SQLServicer(store, pending), server)
|
|
39
|
+
exec_grpc.add_ExecutionServicer_to_server(ExecutionServicer(store, pending), server)
|
|
40
|
+
val_grpc.add_ClientValidationServicer_to_server(ClientValidationServicer(), server)
|
|
41
|
+
health_grpc.add_HealthServicer_to_server(HealthServicer(), server)
|
|
42
|
+
|
|
43
|
+
server.add_insecure_port(f"[::]:{port}")
|
|
44
|
+
server.start()
|
|
45
|
+
_log(f"listening on :{port} (insecure) store={type(store).__name__}")
|
|
46
|
+
server.wait_for_termination()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def main() -> None:
|
|
50
|
+
ap = argparse.ArgumentParser(prog="dbt-state-oss")
|
|
51
|
+
ap.add_argument("--store", choices=["local", "s3", "azure", "memory"],
|
|
52
|
+
help="state backend (env STATE_STORE; default local)")
|
|
53
|
+
ap.add_argument("--port", type=int,
|
|
54
|
+
help="listen port (env DBTSTATE_PORT; default 50051)")
|
|
55
|
+
ap.add_argument("--dir", help="[local] state directory (env DBTSTATE_LOCAL_DIR)")
|
|
56
|
+
ap.add_argument("--bucket", help="[s3] bucket (env DBTSTATE_S3_BUCKET)")
|
|
57
|
+
ap.add_argument("--account", help="[azure] storage account (env DBTSTATE_AZURE_ACCOUNT)")
|
|
58
|
+
ap.add_argument("--container", help="[azure] container (env DBTSTATE_AZURE_CONTAINER)")
|
|
59
|
+
ap.add_argument("--prefix", help="[s3|azure] key prefix (env DBTSTATE_S3_PREFIX/DBTSTATE_AZURE_PREFIX)")
|
|
60
|
+
args = ap.parse_args()
|
|
61
|
+
|
|
62
|
+
port = args.port or int(os.environ.get("DBTSTATE_PORT") or 50051)
|
|
63
|
+
store = make_store(
|
|
64
|
+
store=args.store, dir=args.dir, bucket=args.bucket,
|
|
65
|
+
prefix=args.prefix, account=args.account, container=args.container,
|
|
66
|
+
)
|
|
67
|
+
serve(port, store)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
if __name__ == "__main__":
|
|
71
|
+
main()
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Semantic fingerprint of a model execution.
|
|
2
|
+
|
|
3
|
+
The skip decision compares the incoming fingerprint against stored ones, so the
|
|
4
|
+
fingerprint only needs to be self-consistent (same input -> same hash).
|
|
5
|
+
|
|
6
|
+
Folds in:
|
|
7
|
+
- execution_type (FULL vs MERGE etc. must not collide)
|
|
8
|
+
- the model's own SQL, normalized via sqlglot (whitespace/comments/formatting
|
|
9
|
+
do not change the hash)
|
|
10
|
+
- each dependency SQL passed in query_dependencies, normalized
|
|
11
|
+
|
|
12
|
+
The fingerprint covers only a model's own SQL. Invalidation when an upstream
|
|
13
|
+
changes is handled separately by the freshness check in servicers._is_fresh.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import hashlib
|
|
18
|
+
from typing import Iterable
|
|
19
|
+
|
|
20
|
+
from sqlglot import parse_one
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def normalize_sql(sql: str | None, dialect: str | None) -> str:
|
|
24
|
+
if not sql:
|
|
25
|
+
return ""
|
|
26
|
+
try:
|
|
27
|
+
return parse_one(sql, read=dialect or None).sql(
|
|
28
|
+
dialect=dialect or None, normalize=True, comments=False, pretty=False
|
|
29
|
+
)
|
|
30
|
+
except Exception:
|
|
31
|
+
# Unparseable SQL: fall back to a trimmed raw string so we still hash something stable.
|
|
32
|
+
return sql.strip()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def compute_fingerprint(
|
|
36
|
+
sql: str | None,
|
|
37
|
+
dialect: str | None,
|
|
38
|
+
execution_type: str,
|
|
39
|
+
dependency_queries: Iterable[str],
|
|
40
|
+
) -> str:
|
|
41
|
+
h = hashlib.sha256()
|
|
42
|
+
h.update((execution_type or "").encode())
|
|
43
|
+
h.update(b"\x00")
|
|
44
|
+
h.update(normalize_sql(sql, dialect).encode())
|
|
45
|
+
for dep in sorted(normalize_sql(q, dialect) for q in dependency_queries):
|
|
46
|
+
h.update(b"\x00")
|
|
47
|
+
h.update(dep.encode())
|
|
48
|
+
return h.hexdigest()
|