datahub-bq-connector-session-patch 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.
- datahub_bq_connector_session_patch-0.1.0/.gitignore +7 -0
- datahub_bq_connector_session_patch-0.1.0/LICENSE +202 -0
- datahub_bq_connector_session_patch-0.1.0/Makefile +165 -0
- datahub_bq_connector_session_patch-0.1.0/PKG-INFO +287 -0
- datahub_bq_connector_session_patch-0.1.0/README.md +265 -0
- datahub_bq_connector_session_patch-0.1.0/UPSTREAM-ISSUE.md +167 -0
- datahub_bq_connector_session_patch-0.1.0/pyproject.toml +48 -0
- datahub_bq_connector_session_patch-0.1.0/recipes/bq-session-attribution-europe.yml +93 -0
- datahub_bq_connector_session_patch-0.1.0/recipes/bq-session-attribution-south-america.yml +93 -0
- datahub_bq_connector_session_patch-0.1.0/recipes/local/01-catalog.yml +56 -0
- datahub_bq_connector_session_patch-0.1.0/recipes/local/02-usage-sidecar.yml +63 -0
- datahub_bq_connector_session_patch-0.1.0/src/datahub_bq_connector_session_patch/__init__.py +36 -0
- datahub_bq_connector_session_patch-0.1.0/src/datahub_bq_connector_session_patch/patch.py +201 -0
- datahub_bq_connector_session_patch-0.1.0/src/datahub_bq_connector_session_patch/resolver.py +298 -0
- datahub_bq_connector_session_patch-0.1.0/src/datahub_bq_connector_session_patch/source.py +100 -0
- datahub_bq_connector_session_patch-0.1.0/tests/test_measure_scope.py +80 -0
- datahub_bq_connector_session_patch-0.1.0/tests/test_recipes.py +155 -0
- datahub_bq_connector_session_patch-0.1.0/tests/test_resolver.py +266 -0
- datahub_bq_connector_session_patch-0.1.0/tests/test_session_patch.py +180 -0
- datahub_bq_connector_session_patch-0.1.0/tests/test_source.py +142 -0
- datahub_bq_connector_session_patch-0.1.0/tools/diff_runs.py +120 -0
- datahub_bq_connector_session_patch-0.1.0/tools/measure_scope.py +223 -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,165 @@
|
|
|
1
|
+
# datahub-bq-connector-session-patch — build and distribution
|
|
2
|
+
#
|
|
3
|
+
# Artifacts land in dist/, which is git-ignored. The wheel is the deliverable: it is what
|
|
4
|
+
# gets installed into a DataHub executor's own interpreter via the sidecar recipe's
|
|
5
|
+
# `extra_pip_requirements`, alongside the executor's pinned acryl-datahub. It registers
|
|
6
|
+
# the `datahub_bq_connector_session_patch` source type; the production recipe keeps `type: bigquery`
|
|
7
|
+
# and is unaffected.
|
|
8
|
+
#
|
|
9
|
+
# Shipping a new build:
|
|
10
|
+
#
|
|
11
|
+
# make release # bump patch, rebuild, verify -> dist/
|
|
12
|
+
# make release BUMP=minor # same, bumping the minor component
|
|
13
|
+
# make publish # only if a package index is configured
|
|
14
|
+
#
|
|
15
|
+
# `make build` alone rebuilds the current version without touching pyproject.toml.
|
|
16
|
+
#
|
|
17
|
+
# Every target that reads dist/ goes through `verify-dist` first, which refuses to
|
|
18
|
+
# proceed if dist/ holds anything other than the current version's sdist and wheel.
|
|
19
|
+
# Nothing is ever uploaded by a bare glob, so a stale artifact cannot ride along.
|
|
20
|
+
|
|
21
|
+
UV ?= uv
|
|
22
|
+
DIST := dist
|
|
23
|
+
PKG := datahub-bq-connector-session-patch
|
|
24
|
+
DISTNAME := $(subst -,_,$(PKG))
|
|
25
|
+
BUMP ?= patch
|
|
26
|
+
VENV := .venv
|
|
27
|
+
PYTHON_VERSION ?= 3.11
|
|
28
|
+
VERSION = $(shell $(UV) version --short 2>/dev/null)
|
|
29
|
+
|
|
30
|
+
# The exact artifacts for the version currently in pyproject.toml — never `dist/*`.
|
|
31
|
+
SDIST = $(DIST)/$(DISTNAME)-$(VERSION).tar.gz
|
|
32
|
+
WHEEL = $(DIST)/$(DISTNAME)-$(VERSION)-*.whl
|
|
33
|
+
|
|
34
|
+
.DEFAULT_GOAL := help
|
|
35
|
+
.PHONY: help version clean build dist verify-dist check test gate venv bump release publish require-uv
|
|
36
|
+
|
|
37
|
+
# `release` chains bump -> build -> check, each of which reads or rewrites the version
|
|
38
|
+
# and the contents of dist/. Under -j those interleave and verify-dist can stat a
|
|
39
|
+
# half-deleted dist/ or resolve $(VERSION) mid-bump. Ordering here is correctness.
|
|
40
|
+
.NOTPARALLEL:
|
|
41
|
+
|
|
42
|
+
help: ## Show this help
|
|
43
|
+
@echo "$(PKG) — targets:"
|
|
44
|
+
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
|
|
45
|
+
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-12s\033[0m %s\n", $$1, $$2}'
|
|
46
|
+
@echo
|
|
47
|
+
@echo " variables: BUMP=patch|minor|major PYTHON_VERSION=$(PYTHON_VERSION) UV=$(UV)"
|
|
48
|
+
|
|
49
|
+
require-uv: ## Fail with a readable message if the version cannot be read
|
|
50
|
+
@test -n "$(VERSION)" || { \
|
|
51
|
+
echo "ERROR: could not read the project version."; \
|
|
52
|
+
echo " '$(UV) version --short' produced nothing — is uv installed, and is this"; \
|
|
53
|
+
echo " running from the package directory? Diagnose with: $(UV) version"; \
|
|
54
|
+
exit 1; }
|
|
55
|
+
|
|
56
|
+
version: require-uv ## Print the current version
|
|
57
|
+
@echo $(VERSION)
|
|
58
|
+
|
|
59
|
+
clean: ## Remove build artifacts
|
|
60
|
+
rm -rf $(DIST) build src/*.egg-info *.egg-info
|
|
61
|
+
|
|
62
|
+
build: clean ## Build sdist + wheel into dist/ (always from clean)
|
|
63
|
+
$(UV) build --out-dir $(DIST)
|
|
64
|
+
@echo
|
|
65
|
+
@ls -l $(DIST)
|
|
66
|
+
|
|
67
|
+
dist: build ## Alias for build
|
|
68
|
+
|
|
69
|
+
verify-dist: require-uv ## Assert dist/ holds exactly the current version, nothing stale
|
|
70
|
+
@test -d $(DIST) \
|
|
71
|
+
|| { echo "no $(DIST)/ — run 'make build' first"; exit 1; }
|
|
72
|
+
@test -f $(SDIST) \
|
|
73
|
+
|| { echo "ERROR: no sdist for $(PKG) $(VERSION) in $(DIST)/ — run 'make build'"; exit 1; }
|
|
74
|
+
@ls $(WHEEL) >/dev/null 2>&1 \
|
|
75
|
+
|| { echo "ERROR: no wheel for $(PKG) $(VERSION) in $(DIST)/ — run 'make build'"; exit 1; }
|
|
76
|
+
@stale=$$(find $(DIST) -type f ! -name '.*' \
|
|
77
|
+
! -name '$(DISTNAME)-$(VERSION).tar.gz' \
|
|
78
|
+
! -name '$(DISTNAME)-$(VERSION)-*.whl'); \
|
|
79
|
+
if [ -n "$$stale" ]; then \
|
|
80
|
+
echo "ERROR: $(DIST)/ holds files that are not $(PKG) $(VERSION):"; \
|
|
81
|
+
echo "$$stale" | sed 's/^/ /'; \
|
|
82
|
+
echo; \
|
|
83
|
+
echo "Refusing to continue — these would be shipped alongside the new build."; \
|
|
84
|
+
echo "Run 'make build' to rebuild from clean."; \
|
|
85
|
+
exit 1; \
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
check: verify-dist ## Verify the built artifacts are well-formed and complete
|
|
89
|
+
uvx twine check $(SDIST) $(WHEEL)
|
|
90
|
+
@echo
|
|
91
|
+
@for w in $(WHEEL); do \
|
|
92
|
+
echo "--- $$w ---"; \
|
|
93
|
+
unzip -l "$$w" | sed 's/^/ /'; \
|
|
94
|
+
echo " entry points:"; \
|
|
95
|
+
unzip -p "$$w" '*/entry_points.txt' | sed 's/^/ /'; \
|
|
96
|
+
done
|
|
97
|
+
@unzip -p $(WHEEL) '*/entry_points.txt' \
|
|
98
|
+
| grep -q 'datahub.ingestion.source.plugins' \
|
|
99
|
+
|| { echo "ERROR: wheel is missing the source entry point"; exit 1; }
|
|
100
|
+
@echo
|
|
101
|
+
@echo "OK — $(PKG) $(VERSION) registers its source entry point"
|
|
102
|
+
|
|
103
|
+
# The range here must match MIN/MAX_ACRYL_DATAHUB in src/datahub_bq_connector_session_patch/patch.py and
|
|
104
|
+
# the `test` extra in pyproject.toml — this patch reaches into private internals, so
|
|
105
|
+
# "tested against" is the only guarantee it has.
|
|
106
|
+
test: ## Run the test suite against a real acryl-datahub (no venv setup needed)
|
|
107
|
+
PYTHONPATH=src $(UV) run --no-project --python 3.11 \
|
|
108
|
+
--with 'acryl-datahub[bigquery]>=1.6,<1.8' --with pytest --with pyyaml \
|
|
109
|
+
pytest tests/ -q
|
|
110
|
+
|
|
111
|
+
# The acceptance gate from the design doc: the same scenario must FAIL on stock
|
|
112
|
+
# acryl-datahub and PASS patched. A green `gate` is what proves the patch still bites
|
|
113
|
+
# after an acryl-datahub bump — `test` alone would stay green if upstream fixed the
|
|
114
|
+
# defect out from under us, and then this package would be dead weight.
|
|
115
|
+
gate: ## Prove the defect still exists on stock and that the patch still fixes it
|
|
116
|
+
@echo "--- stock acryl-datahub (must FAIL) ---"
|
|
117
|
+
@PYTHONPATH=src $(UV) run --no-project --python 3.11 \
|
|
118
|
+
--with 'acryl-datahub[bigquery]>=1.6,<1.8' --with pytest \
|
|
119
|
+
python tests/test_session_patch.py; \
|
|
120
|
+
status=$$?; \
|
|
121
|
+
if [ $$status -eq 0 ]; then \
|
|
122
|
+
echo; echo "ERROR: stock acryl-datahub PASSED — upstream may have fixed this."; \
|
|
123
|
+
echo "Re-read the design doc before shipping; this package may be obsolete."; \
|
|
124
|
+
exit 1; \
|
|
125
|
+
fi; \
|
|
126
|
+
echo " (exit $$status — correct: the defect is present)"
|
|
127
|
+
@echo
|
|
128
|
+
@echo "--- patched (must PASS) ---"
|
|
129
|
+
@PYTHONPATH=src $(UV) run --no-project --python 3.11 \
|
|
130
|
+
--with 'acryl-datahub[bigquery]>=1.6,<1.8' --with pytest \
|
|
131
|
+
python tests/test_session_patch.py --patched \
|
|
132
|
+
|| { echo; echo "ERROR: the patch no longer recovers the read."; exit 1; }
|
|
133
|
+
@echo
|
|
134
|
+
@echo "OK — defect reproduced on stock, fixed patched"
|
|
135
|
+
|
|
136
|
+
# A project-local .venv, for interactive work and for the tools/ scripts — which need
|
|
137
|
+
# real BigQuery credentials and so cannot run under `uv run --no-project`. Henrik's zsh
|
|
138
|
+
# auto_venv chpwd hook activates it on cd into this directory.
|
|
139
|
+
#
|
|
140
|
+
# `test` and `gate` deliberately do NOT use it: they build a throwaway environment per
|
|
141
|
+
# run, so a stale or hand-modified .venv can never make them pass.
|
|
142
|
+
venv: ## Create .venv (python 3.11) with the package installed editable + test extras
|
|
143
|
+
$(UV) venv $(VENV) --python $(PYTHON_VERSION)
|
|
144
|
+
VIRTUAL_ENV=$(VENV) $(UV) pip install -e '.[test]'
|
|
145
|
+
@echo
|
|
146
|
+
@echo "Created $(VENV) — cd out and back in to activate, or: source $(VENV)/bin/activate"
|
|
147
|
+
|
|
148
|
+
bump: require-uv ## Bump the version in pyproject.toml (BUMP=patch|minor|major)
|
|
149
|
+
@echo "$(PKG): $(VERSION) -> bumping $(BUMP)"
|
|
150
|
+
$(UV) version --frozen --bump $(BUMP)
|
|
151
|
+
|
|
152
|
+
release: test gate bump build check ## Test, bump the version, rebuild, and verify
|
|
153
|
+
@echo
|
|
154
|
+
@echo "$(PKG) $(VERSION) built and verified. Artifacts:"
|
|
155
|
+
@ls -1 $(DIST)
|
|
156
|
+
@echo
|
|
157
|
+
@echo "Commit the pyproject.toml version bump, then 'make publish' if you have an index."
|
|
158
|
+
|
|
159
|
+
publish: check ## Upload the current version to a package index (UV_PUBLISH_URL / _TOKEN)
|
|
160
|
+
@echo
|
|
161
|
+
@echo "Will upload exactly these files:"
|
|
162
|
+
@ls -1 $(SDIST) $(WHEEL) | sed 's/^/ /'
|
|
163
|
+
@printf "Publish $(PKG) $(VERSION) to %s? [y/N] " "$${UV_PUBLISH_URL:-the default index}"; \
|
|
164
|
+
read ans; [ "$$ans" = "y" ] || { echo "aborted"; exit 1; }
|
|
165
|
+
$(UV) publish $(SDIST) $(WHEEL)
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: datahub-bq-connector-session-patch
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DataHub BigQuery sidecar source: attribute reads whose SQL does not qualify its table names
|
|
5
|
+
Project-URL: Homepage, https://github.com/gutro/dv-datahub/tree/master/datahub-bq-connector-session-patch
|
|
6
|
+
Project-URL: Repository, https://github.com/gutro/dv-datahub
|
|
7
|
+
Project-URL: Issues, https://github.com/gutro/dv-datahub/issues
|
|
8
|
+
Author: DataVantage Platform
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: bigquery,datahub,ingestion,lineage,usage
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Database
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Provides-Extra: test
|
|
18
|
+
Requires-Dist: acryl-datahub[bigquery]<1.8,>=1.6; extra == 'test'
|
|
19
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
20
|
+
Requires-Dist: pyyaml; extra == 'test'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# datahub-bq-connector-session-patch
|
|
24
|
+
|
|
25
|
+
A DataHub BigQuery **sidecar source** that attributes reads whose SQL did not qualify
|
|
26
|
+
its table names — the ones the stock connector sees, misfiles and silently discards.
|
|
27
|
+
|
|
28
|
+
Full diagnosis, design, verification and limits:
|
|
29
|
+
`datavantage/docs/datahub-unqualified-read-attribution.md`.
|
|
30
|
+
|
|
31
|
+
## The problem
|
|
32
|
+
|
|
33
|
+
A client with a BigQuery *default dataset* set can write `SELECT ... FROM Bets_Details`.
|
|
34
|
+
BigQuery fills in the blank at run time, but never records it: `INFORMATION_SCHEMA.JOBS`
|
|
35
|
+
carries the SQL text and the billing project, not the job's default dataset.
|
|
36
|
+
|
|
37
|
+
DataHub's connector substitutes `_SESSION` for the missing dataset
|
|
38
|
+
(`queries_extractor.py:542,558`), on the assumption that a bare name is usually a
|
|
39
|
+
temporary table. Its own temp-table rule then flags anything whose dataset starts with
|
|
40
|
+
`_` (`:309`), and the aggregator drops it — for usage
|
|
41
|
+
(`sql_parsing_aggregator.py:1022`) and for the query entity (`:1693`).
|
|
42
|
+
|
|
43
|
+
So the connector *sees* the table name, guesses the wrong container, and discards the
|
|
44
|
+
result. Nothing is reported: the sibling branch of `is_temp_table` records what it drops,
|
|
45
|
+
this one returns `True` in silence. Measured here: one client, 2,866 jobs in 7 days,
|
|
46
|
+
100% unqualified, 0 usage rows.
|
|
47
|
+
|
|
48
|
+
**A `0` in DataHub usage is therefore ambiguous** — "nobody reads this", or "read
|
|
49
|
+
constantly, with unqualified SQL". Decommissioning decisions depend on telling those apart.
|
|
50
|
+
|
|
51
|
+
## What this does
|
|
52
|
+
|
|
53
|
+
For upstreams that landed in `_SESSION`, it resolves the bare table name against the
|
|
54
|
+
tables DataHub discovered during its own schema pass. A name matching more than one
|
|
55
|
+
discovered table is **left untouched** — dropped exactly as before, never guessed.
|
|
56
|
+
|
|
57
|
+
It ships as a distinct source type, so the production recipe stays stock:
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
source:
|
|
61
|
+
type: datahub_bq_connector_session_patch
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Installing
|
|
65
|
+
|
|
66
|
+
Per-recipe, via **Extra Pip Libraries** (DataHub UI) or `extra_pip_requirements`. That
|
|
67
|
+
field is scoped to one recipe, which is what keeps the production recipe unaffected.
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
datahub-bq-connector-session-patch
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The wheel declares **no dependencies** — it imports only `datahub.*`, which any
|
|
74
|
+
environment running a recipe already has. Declaring `acryl-datahub` would let pip
|
|
75
|
+
re-resolve the executor's own pinned copy while installing this. The tested range
|
|
76
|
+
(`>=1.6,<1.8`) is enforced at runtime instead: an out-of-range executor raises a
|
|
77
|
+
structured warning into the ingestion report rather than failing the run.
|
|
78
|
+
|
|
79
|
+
## The sidecar recipe
|
|
80
|
+
|
|
81
|
+
```yaml
|
|
82
|
+
pipeline_name: bq-session-attribution # its OWN name — never the main recipe's
|
|
83
|
+
source:
|
|
84
|
+
type: datahub_bq_connector_session_patch
|
|
85
|
+
config:
|
|
86
|
+
project_id_pattern:
|
|
87
|
+
allow:
|
|
88
|
+
- '^dv-prod-eu-w1(-.+)?-data$'
|
|
89
|
+
- '^dv-ext-prod-eu-w1(-.+)?-data$'
|
|
90
|
+
- '^dv-prod-eu-w1(-.+)?-comp\d+$'
|
|
91
|
+
include_tables: false # lightweight discovery still fills table_refs
|
|
92
|
+
include_views: false
|
|
93
|
+
include_table_lineage: false # refused if true — see below
|
|
94
|
+
include_usage_statistics: true
|
|
95
|
+
use_queries_v2: true
|
|
96
|
+
include_queries: true
|
|
97
|
+
include_query_usage_statistics: true
|
|
98
|
+
region_qualifiers: ['region-europe-west1']
|
|
99
|
+
start_time: '-7 days'
|
|
100
|
+
enable_stateful_time_window: true
|
|
101
|
+
stateful_ingestion:
|
|
102
|
+
enabled: true # the time-window watermark
|
|
103
|
+
remove_stale_metadata: false # refused if true — see below
|
|
104
|
+
env: PROD
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Two settings this source refuses to start with
|
|
108
|
+
|
|
109
|
+
Both were reproduced against a live catalog. They are not style preferences, so they are
|
|
110
|
+
enforced in code rather than left to the YAML:
|
|
111
|
+
|
|
112
|
+
| setting | why it is refused |
|
|
113
|
+
|---|---|
|
|
114
|
+
| `stateful_ingestion.remove_stale_metadata: true` | The sidecar writes a `status` aspect on every dataset it produces usage for, enrolling them in *its* stale-removal checkpoint. Its URN set is **usage-driven**, so any dataset not read that day falls out of the checkpoint and is soft-deleted — datasets the main recipe owns. Normal operation, not an edge case. |
|
|
115
|
+
| `include_table_lineage: true` | Resolved names drive usage attribution only. A mis-resolved write would create a **wrong edge into a real table**, which is worse than the missing usage this package exists to fix. |
|
|
116
|
+
|
|
117
|
+
`remove_stale_metadata` defaults to `true`, so it must be set explicitly. Only the
|
|
118
|
+
combination bites — with `stateful_ingestion.enabled: false` there is no checkpoint and
|
|
119
|
+
nothing is refused.
|
|
120
|
+
|
|
121
|
+
### Scope it to the readers, not to minimise ambiguity
|
|
122
|
+
|
|
123
|
+
`dataset_pattern` should be **wide**. "Ambiguous" means the name matches more than one
|
|
124
|
+
entry in `discovered_tables` *within the recipe's scope*, so narrowing scope removes the
|
|
125
|
+
alternatives rather than resolving between them. If a reader's default dataset is
|
|
126
|
+
`prod_spain_*` but the index holds only `prod_malta_*`, the name resolves **confidently
|
|
127
|
+
and wrongly**.
|
|
128
|
+
|
|
129
|
+
Ambiguity fails safe. A too-narrow index fails silently, in the wrong direction.
|
|
130
|
+
|
|
131
|
+
Widening is otherwise harmless: `disjoint_only` means the sidecar emits only URNs it
|
|
132
|
+
actually recovered, so it stays quiet wherever SQL is already qualified and never
|
|
133
|
+
double-books usage with the main recipe.
|
|
134
|
+
|
|
135
|
+
## Reading the run report
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
rewritten=41 tables (2792 refs) ambiguous=18 names (63 refs) unknown=7 names (12 refs)
|
|
139
|
+
queries_passed=954 queries_skipped=3118 (index=1631 unique names, 412 ambiguous names)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
- **distinct counters** — how much of the catalog was recovered. `rewritten` counts
|
|
143
|
+
distinct resolved **target tables**; `ambiguous` and `unknown` count distinct bare
|
|
144
|
+
**names**. Deliberately not distinct `_SESSION` URNs: those embed the reader project,
|
|
145
|
+
so one table read from five projects would report as five.
|
|
146
|
+
- **`*_refs`** — how many reads that attributed. One hot table read 2,000 times is one
|
|
147
|
+
rewrite and 2,000 references.
|
|
148
|
+
- **`queries_skipped`** — queries whose SQL was already fully qualified. The main recipe
|
|
149
|
+
has those; the sidecar correctly stays out of the way.
|
|
150
|
+
- **`queries_mixed`** — queries carrying *both* an already-resolvable reference and a
|
|
151
|
+
recovered one. Also left to the main recipe, for a subtler reason, below.
|
|
152
|
+
|
|
153
|
+
### Why mixed queries are skipped
|
|
154
|
+
|
|
155
|
+
`disjoint_only` keeps the two pipelines from double-booking **usage**, which is a
|
|
156
|
+
timeseries aspect. It does not, by itself, protect the **query entity**.
|
|
157
|
+
|
|
158
|
+
Query entities are keyed by `get_query_fingerprint(sql, platform, fast=True)` — a pure
|
|
159
|
+
function of the SQL text, so both pipelines derive the *same* `urn:li:query:<fp>`. But
|
|
160
|
+
`querySubjects` is a versioned aspect, not timeseries. If the sidecar emitted its
|
|
161
|
+
narrowed subject set for a query the main recipe also sees, whichever ran last would
|
|
162
|
+
win, and the entity would flip between the two subject sets on every scheduled run.
|
|
163
|
+
|
|
164
|
+
Passing the union instead would fix the subjects and double-book usage for the
|
|
165
|
+
already-resolvable half. Neither is acceptable, so a mixed query is left entirely to the
|
|
166
|
+
main recipe and counted. Measured on `dv-ext-prod-eu-w1-data` over 7 days:
|
|
167
|
+
`queries_mixed=0` — the guard costs nothing there, because that client's SQL is
|
|
168
|
+
uniformly unqualified.
|
|
169
|
+
|
|
170
|
+
A per-reader-project breakdown is logged alongside it, so a project that recovers nothing
|
|
171
|
+
shows up at 0.0% rather than vanishing.
|
|
172
|
+
|
|
173
|
+
### Two failures that look like success
|
|
174
|
+
|
|
175
|
+
Both were hit during development. Each leaves the run green and the output plausible:
|
|
176
|
+
|
|
177
|
+
1. **`discovered_tables` is empty at construction.** The source passes a *live reference*
|
|
178
|
+
to `bq_schema_extractor.table_refs`, which only fills during the schema pass. The
|
|
179
|
+
index is built lazily on first use, never in `__init__`.
|
|
180
|
+
2. **Refs are `projects/P/datasets/D/tables/T`, not `P.D.T`.** Naive dotted parsing
|
|
181
|
+
matches nothing.
|
|
182
|
+
|
|
183
|
+
Because of these the source raises a structured **warning** if the index came out empty
|
|
184
|
+
or nothing was rewritten. **Never trust a negative result without checking the index
|
|
185
|
+
size.**
|
|
186
|
+
|
|
187
|
+
## Limits
|
|
188
|
+
|
|
189
|
+
Unique-name resolution only. Where a bare name matches several catalogued objects it is
|
|
190
|
+
dropped. How much that costs depends entirely on the estate:
|
|
191
|
+
|
|
192
|
+
| population | ambiguous names |
|
|
193
|
+
|---|---|
|
|
194
|
+
| views in `dv-ext-prod-eu-w1-data` | **0.0%** (162/162 unique) |
|
|
195
|
+
| views in `dv-prod-eu-w1-data` | **54.4%** |
|
|
196
|
+
| tables referenced estate-wide | 53.0% |
|
|
197
|
+
|
|
198
|
+
The external-facing views carry licence/brand suffixes and are unique by construction.
|
|
199
|
+
The internal estate's per-market layout duplicates names across `prod_malta_*`,
|
|
200
|
+
`prod_spain_*`, `prod_italy_*`…, and the cross-market `common_` layer duplicates a
|
|
201
|
+
further 39 names against them — so roughly half of any bare reads against it stay
|
|
202
|
+
unrecovered.
|
|
203
|
+
|
|
204
|
+
Resolving those needs **leaf-set matching**, not name matching: the colliding
|
|
205
|
+
common-vs-market views have identical names but cleanly distinct leaf sets. That is
|
|
206
|
+
explicitly out of scope — see §9.1 of the design doc for what it would take.
|
|
207
|
+
|
|
208
|
+
## Measuring a scope before shipping it
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
export BQ_SESSION_PATCH_BILLING_PROJECT=dv-ext-prod-eu-w1-data
|
|
212
|
+
python tools/measure_scope.py eu baseline --days 7
|
|
213
|
+
python tools/measure_scope.py eu patched --days 7
|
|
214
|
+
python tools/diff_runs.py runs/mcps_eu_baseline_7d.json runs/mcps_eu_patched_7d.json
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Scope flags: `--projects` for explicit ids, `--project-pattern` to override the region's
|
|
218
|
+
`project_id_pattern.allow` regexes, `--days` for the window.
|
|
219
|
+
|
|
220
|
+
**The billing project must be explicit** — `--billing`, or
|
|
221
|
+
`$BQ_SESSION_PATCH_BILLING_PROJECT`, or inferred when `--projects` names exactly one.
|
|
222
|
+
DataHub passes it straight to `bigquery.Client(...)`, and when it is `None` the client
|
|
223
|
+
inherits whatever `google.auth.default()` resolves: `GOOGLE_CLOUD_PROJECT` first, then the
|
|
224
|
+
ADC file's quota project, then the active gcloud config. A stray env var will therefore
|
|
225
|
+
bill every `INFORMATION_SCHEMA` job to an unrelated project and fail as
|
|
226
|
+
`bigquery.jobs.create` denied against a project you never named. The script refuses to
|
|
227
|
+
start rather than inherit one, and prints both the billing and the ambient project so a
|
|
228
|
+
mismatch is visible.
|
|
229
|
+
|
|
230
|
+
`measure_scope.py` writes MCPs to a file sink (nothing reaches GMS) and prints the
|
|
231
|
+
per-project recovery table; `diff_runs.py` reports datasets gaining usage, query entities
|
|
232
|
+
gained and readers newly attributed, and fails if any `schemaMetadata`,
|
|
233
|
+
`upstreamLineage` or `datasetProperties` aspect leaked into the output.
|
|
234
|
+
|
|
235
|
+
## Trying it against a local DataHub
|
|
236
|
+
|
|
237
|
+
`recipes/local/` holds a two-step pair for a quickstart instance, scoped to one project:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
make venv && source .venv/bin/activate
|
|
241
|
+
datahub ingest -c recipes/local/01-catalog.yml # stock `bigquery` — the catalog
|
|
242
|
+
datahub ingest -c recipes/local/02-usage-sidecar.yml # this package — the recovered usage
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Step 1 runs with usage **on**, exactly as production does, and still misses the
|
|
246
|
+
unqualified reads — that is the premise. Step 2 shows what it missed. Measured against
|
|
247
|
+
`dv-ext-prod-eu-w1-data` over 7 days:
|
|
248
|
+
|
|
249
|
+
| | step 1 (catalog) | step 2 (sidecar) |
|
|
250
|
+
|---|---|---|
|
|
251
|
+
| datasets with a usage aspect | 5 | **+59** |
|
|
252
|
+
| query entities | 170 | **+61** |
|
|
253
|
+
| aspects emitted | schema, lineage, properties, usage, queries | usage and queries only |
|
|
254
|
+
|
|
255
|
+
Both use ADC, so the VPN must be up — VPC-SC blocks ADC while the `bq` CLI keeps
|
|
256
|
+
working, which makes the failure look like a permissions problem.
|
|
257
|
+
|
|
258
|
+
They run **stateless** (`stateful_ingestion.enabled: false`), so re-running re-emits the
|
|
259
|
+
same days. Timeseries aspects append rather than upsert, so repeated local runs
|
|
260
|
+
accumulate duplicate usage documents for a day. Harmless locally; in a real deployment
|
|
261
|
+
keep the stateful time window, which is what makes each day emit exactly once.
|
|
262
|
+
|
|
263
|
+
## Developing
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
make venv # .venv on python 3.11, package installed editable + test extras
|
|
267
|
+
make test # 49 tests against a real acryl-datahub
|
|
268
|
+
make gate # the acceptance gate: must FAIL on stock, PASS patched
|
|
269
|
+
make release # test, gate, bump, rebuild, verify -> dist/
|
|
270
|
+
make publish
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
`make venv` exists for interactive work and for the `tools/` scripts, which need real
|
|
274
|
+
BigQuery credentials and so cannot run in a throwaway environment. `make test` and
|
|
275
|
+
`make gate` deliberately **do not** use it — they build their own environment per run, so
|
|
276
|
+
a stale or hand-modified `.venv` can never make them pass.
|
|
277
|
+
|
|
278
|
+
`make gate` is the one that matters on an acryl-datahub bump. This package patches
|
|
279
|
+
private internals, so `make test` alone would stay green even if upstream fixed the
|
|
280
|
+
defect out from under it — at which point this package is dead weight and should be
|
|
281
|
+
retired, not shipped. `gate` fails loudly in that case.
|
|
282
|
+
|
|
283
|
+
## Upstream
|
|
284
|
+
|
|
285
|
+
The defect is unfixed on `datahub-project/datahub` master as of 2026-09-14. The ask
|
|
286
|
+
there is modest: report the `_SESSION` discard, or offer opt-in resolution against
|
|
287
|
+
discovered tables. See `UPSTREAM-ISSUE.md`.
|