qualis-bigquery 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.
@@ -0,0 +1,48 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ test:
14
+ name: test (Python ${{ matrix.python-version }})
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ python-version: ["3.12", "3.13"]
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+
23
+ - name: Set up uv
24
+ uses: astral-sh/setup-uv@v3
25
+ with:
26
+ enable-cache: true
27
+
28
+ - name: Set up Python ${{ matrix.python-version }}
29
+ run: uv python install ${{ matrix.python-version }}
30
+
31
+ - name: Install dependencies
32
+ run: uv sync --dev
33
+
34
+ - name: Lint with ruff
35
+ run: uv run ruff check src/ tests/
36
+
37
+ - name: Typecheck with mypy
38
+ run: uv run mypy src/
39
+
40
+ - name: Run tests
41
+ run: uv run pytest --cov=qualis_bigquery --cov-report=term-missing
42
+
43
+ - name: Enforce coverage threshold
44
+ # 55% is appropriate for a thin SDK adapter: SQL templates +
45
+ # adapter dispatch are fully covered via mocked tests; the
46
+ # uncovered paths are connection/stream lifecycle that only
47
+ # exercise with a live BigQuery client.
48
+ run: uv run pytest --cov=qualis_bigquery --cov-fail-under=55
@@ -0,0 +1,60 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ build:
13
+ name: Build sdist and wheel
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - name: Set up uv
19
+ uses: astral-sh/setup-uv@v3
20
+
21
+ - name: Set up Python
22
+ run: uv python install 3.12
23
+
24
+ - name: Build artefacts
25
+ run: uv build
26
+
27
+ - name: Verify version matches tag
28
+ run: |
29
+ VERSION_IN_PYPROJECT=$(grep '^version = ' pyproject.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
30
+ TAG_VERSION="${GITHUB_REF#refs/tags/v}"
31
+ if [ "$VERSION_IN_PYPROJECT" != "$TAG_VERSION" ]; then
32
+ echo "Version mismatch: pyproject.toml says '$VERSION_IN_PYPROJECT', tag is '$TAG_VERSION'"
33
+ exit 1
34
+ fi
35
+ echo "Version $VERSION_IN_PYPROJECT matches tag v$TAG_VERSION"
36
+
37
+ - name: Upload artefacts
38
+ uses: actions/upload-artifact@v4
39
+ with:
40
+ name: dist
41
+ path: dist/
42
+
43
+ publish:
44
+ name: Publish to PyPI
45
+ needs: build
46
+ runs-on: ubuntu-latest
47
+ environment:
48
+ name: pypi
49
+ url: https://pypi.org/p/qualis-bigquery
50
+ permissions:
51
+ id-token: write
52
+ steps:
53
+ - name: Download artefacts
54
+ uses: actions/download-artifact@v4
55
+ with:
56
+ name: dist
57
+ path: dist/
58
+
59
+ - name: Publish to PyPI
60
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,16 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.so
4
+ .venv/
5
+ venv/
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+ .pytest_cache/
10
+ .mypy_cache/
11
+ .ruff_cache/
12
+ .coverage
13
+ htmlcov/
14
+ .env
15
+ *.log
16
+ .DS_Store
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of recording
55
+ instructions given to the Licensor.
56
+
57
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
58
+ whom a Contribution has been received by the Licensor and is included
59
+ in the Work.
60
+
61
+ 2. Grant of Copyright License. Subject to the terms and conditions of
62
+ this License, each Contributor hereby grants to You a perpetual,
63
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
+ copyright license to reproduce, prepare Derivative Works of,
65
+ publicly display, publicly perform, sublicense, and distribute the
66
+ Work and such Derivative Works in Source or Object form.
67
+
68
+ 3. Grant of Patent License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ (except as stated in this section) patent license to make, have made,
72
+ use, offer to sell, sell, import, and otherwise transfer the Work,
73
+ where such license applies only to those Contributions necessary to
74
+ make, use, sell, offer to sell, import, or otherwise transfer the Work.
75
+
76
+ 4. Redistribution. You may reproduce and distribute copies of the
77
+ Work or Derivative Works thereof in any medium, with or without
78
+ modifications, and in Source or Object form, provided that You
79
+ meet the following conditions:
80
+
81
+ (a) You must give any other recipients of the Work or Derivative
82
+ Works a copy of this License; and
83
+
84
+ (b) You must reproduce the above copyright notices for use,
85
+ reproduction, and distribution, and a relevant copyright notice
86
+ in the Derivative Works; and
87
+
88
+ (c) You must retain, in the Source form of any Derivative Works
89
+ that You distribute, all copyright, patent, trademark, and
90
+ attribution notices from the Source form of the Work,
91
+ excluding those notices that do not pertain to any part of
92
+ the Derivative Works; and
93
+
94
+ (d) If the Work includes a "NOTICE" text file, the contents
95
+ of the NOTICE file are for informational purposes only
96
+ and do not modify the License. You may add Your own attribution
97
+ notices within Derivative Works that You distribute, alongside
98
+ or in addition to the NOTICE text from the Work, provided
99
+ that such additional attribution notices cannot be construed
100
+ as modifying the License.
101
+
102
+ You may add Your own license statement for Your modifications and
103
+ may provide additional grant of rights to use, copy, modify, merge,
104
+ publish, distribute, sublicense, and/or sell copies of the Work.
105
+
106
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
107
+ any Contribution intentionally submitted for inclusion in the Work
108
+ by You to the Licensor shall be under the terms and conditions of
109
+ this License, without any additional terms or conditions.
110
+ Notwithstanding the above, nothing herein shall supersede or modify
111
+ the terms of any separate license agreement you may have executed
112
+ with Licensor regarding such Contributions.
113
+
114
+ 6. Trademarks. This License does not grant permission to use the trade
115
+ names, trademarks, service marks, or product names of the Licensor,
116
+ except as required for reasonable and customary use in describing the
117
+ origin of the Work and reproducing the content of the NOTICE file.
118
+
119
+ 7. Disclaimer of Warranty. Unless required by applicable law or
120
+ agreed to in writing, Licensor provides the Work (and each
121
+ Contributor provides its Contributions) on an "AS IS" BASIS,
122
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
123
+ implied, including, without limitation, any warranties or conditions
124
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
125
+ PARTICULAR PURPOSE. You are solely responsible for determining the
126
+ appropriateness of using or reproducing the Work and assume any
127
+ risks associated with Your exercise of permissions under this License.
128
+
129
+ 8. Limitation of Liability. In no event and under no legal theory,
130
+ whether in tort (including negligence), contract, or otherwise,
131
+ unless required by applicable law (such as deliberate and grossly
132
+ negligent acts) or agreed to in writing, shall any Contributor be
133
+ liable to You for damages, including any direct, indirect, special,
134
+ incidental, or exemplary damages of any character arising as a
135
+ result of this License or out of the use or inability to use the
136
+ Work (including but not limited to damages for loss of goodwill,
137
+ work stoppage, computer failure or malfunction, or all other
138
+ commercial damages or losses), even if such Contributor has been
139
+ advised of the possibility of such damages.
140
+
141
+ 9. Accepting Warranty or Additional Liability. While redistributing
142
+ the Work or Derivative Works thereof, You may choose to offer,
143
+ and charge a fee for, acceptance of support, warranty, indemnity,
144
+ or other liability obligations and/or rights consistent with this
145
+ License. However, in accepting such obligations, You may offer only
146
+ conditions that are consistent with this full terms and conditions,
147
+ including warranty disclaimers and limitation of liability contained
148
+ in this License, or any of the terms and conditions contained in a
149
+ Section 9 of the License, including without limitation
150
+ indemnification.
151
+
152
+ END OF TERMS AND CONDITIONS
153
+
154
+ APPENDIX: How to apply the Apache License to your work.
155
+
156
+ To apply the Apache License to your work, attach the following
157
+ boilerplate notice, with the fields enclosed by brackets "[]"
158
+ replaced with your own identifying information. (Don't include
159
+ the brackets!) The text should be enclosed in the appropriate
160
+ comment syntax for the format of the file. We also recommend that
161
+ a file or directory name be given, with a reference to where the
162
+ full text can be found.
163
+
164
+ Copyright 2024 Ahmed Ashraf
165
+
166
+ Licensed under the Apache License, Version 2.0 (the "License");
167
+ you may not use this file except in compliance with the License.
168
+ You may obtain a copy of the License at
169
+
170
+ http://www.apache.org/licenses/LICENSE-2.0
171
+
172
+ Unless required by applicable law or agreed to in writing, software
173
+ distributed under the License is distributed on an "AS IS" BASIS,
174
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
175
+ See the License for the specific language governing permissions and
176
+ limitations under the License.
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: qualis-bigquery
3
+ Version: 0.1.0
4
+ Summary: BigQuery adapter for Qualis (data quality framework)
5
+ Project-URL: Homepage, https://github.com/ahmedashraffcih/qualis-bigquery
6
+ Project-URL: Repository, https://github.com/ahmedashraffcih/qualis-bigquery
7
+ Project-URL: Issues, https://github.com/ahmedashraffcih/qualis-bigquery/issues
8
+ Author-email: Ahmed Ashraf <ahmedashraffcih@gmail.com>
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: bigquery,data-quality,dq,qualis
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Database
19
+ Classifier: Topic :: Software Development :: Quality Assurance
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.12
22
+ Requires-Dist: google-cloud-bigquery>=3.0
23
+ Requires-Dist: qualis>=0.3.1
24
+ Description-Content-Type: text/markdown
25
+
26
+ # qualis-bigquery
27
+
28
+ BigQuery adapter for [Qualis](https://github.com/ahmedashraffcih/qualis) —
29
+ the open-source data quality framework.
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ pip install qualis qualis-bigquery
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ```yaml
40
+ # qualis.yaml
41
+ adapter: bigquery
42
+ project: my-gcp-project
43
+ dataset: my_dataset
44
+ # Auth: standard GCP application default credentials
45
+ # gcloud auth application-default login
46
+ ```
47
+
48
+ ## Supported checks
49
+
50
+ - not_null, unique, between, regex, in_set
51
+ - row_count, not_negative
52
+ - reference_lookup
53
+
54
+ The adapter is read-only by contract — DML statements
55
+ (INSERT/UPDATE/DELETE/MERGE/DROP/CREATE/ALTER) are explicitly refused.
56
+
57
+ ## License
58
+
59
+ Apache 2.0.
@@ -0,0 +1,34 @@
1
+ # qualis-bigquery
2
+
3
+ BigQuery adapter for [Qualis](https://github.com/ahmedashraffcih/qualis) —
4
+ the open-source data quality framework.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ pip install qualis qualis-bigquery
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```yaml
15
+ # qualis.yaml
16
+ adapter: bigquery
17
+ project: my-gcp-project
18
+ dataset: my_dataset
19
+ # Auth: standard GCP application default credentials
20
+ # gcloud auth application-default login
21
+ ```
22
+
23
+ ## Supported checks
24
+
25
+ - not_null, unique, between, regex, in_set
26
+ - row_count, not_negative
27
+ - reference_lookup
28
+
29
+ The adapter is read-only by contract — DML statements
30
+ (INSERT/UPDATE/DELETE/MERGE/DROP/CREATE/ALTER) are explicitly refused.
31
+
32
+ ## License
33
+
34
+ Apache 2.0.
@@ -0,0 +1,62 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "qualis-bigquery"
7
+ version = "0.1.0"
8
+ description = "BigQuery adapter for Qualis (data quality framework)"
9
+ readme = "README.md"
10
+ license = { text = "Apache-2.0" }
11
+ requires-python = ">=3.12"
12
+ authors = [
13
+ { name = "Ahmed Ashraf", email = "ahmedashraffcih@gmail.com" },
14
+ ]
15
+ keywords = ["data-quality", "bigquery", "qualis", "dq"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Intended Audience :: Developers",
19
+ "License :: OSI Approved :: Apache Software License",
20
+ "Operating System :: OS Independent",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Topic :: Database",
24
+ "Topic :: Software Development :: Quality Assurance",
25
+ "Typing :: Typed",
26
+ ]
27
+ dependencies = [
28
+ "qualis>=0.3.1",
29
+ "google-cloud-bigquery>=3.0",
30
+ ]
31
+
32
+ [project.entry-points."qualis.adapters"]
33
+ bigquery = "qualis_bigquery.adapter:BigQueryAdapter"
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/ahmedashraffcih/qualis-bigquery"
37
+ Repository = "https://github.com/ahmedashraffcih/qualis-bigquery"
38
+ Issues = "https://github.com/ahmedashraffcih/qualis-bigquery/issues"
39
+
40
+ [tool.hatch.build.targets.wheel]
41
+ packages = ["src/qualis_bigquery"]
42
+
43
+ [tool.pytest.ini_options]
44
+ testpaths = ["tests"]
45
+
46
+ [tool.mypy]
47
+ strict = true
48
+ python_version = "3.12"
49
+
50
+ [tool.ruff]
51
+ line-length = 100
52
+
53
+ [tool.ruff.lint]
54
+ select = ["E", "F", "I", "B", "UP", "RUF", "TC"]
55
+
56
+ [dependency-groups]
57
+ dev = [
58
+ "mypy>=1.0",
59
+ "pytest>=8.0",
60
+ "pytest-cov>=4.0",
61
+ "ruff>=0.5",
62
+ ]
@@ -0,0 +1,9 @@
1
+ """BigQuery adapter for Qualis."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __version__ = "0.1.0"
6
+
7
+ from qualis_bigquery.adapter import BigQueryAdapter
8
+
9
+ __all__ = ["BigQueryAdapter", "__version__"]
@@ -0,0 +1,206 @@
1
+ """BigQueryAdapter implementing qualis.ports.database.DatabasePort.
2
+
3
+ BigQuery query execution uses parameterised queries via
4
+ ``ScalarQueryParameter`` / ``ArrayQueryParameter``. Authentication uses
5
+ GCP Application Default Credentials.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import TYPE_CHECKING, Any
11
+
12
+ from qualis_bigquery.sql_templates import (
13
+ BETWEEN_SQL,
14
+ IN_SET_SQL,
15
+ NOT_NEGATIVE_SQL,
16
+ NOT_NULL_SQL,
17
+ REFERENCE_LOOKUP_SQL,
18
+ REGEX_SQL,
19
+ ROW_COUNT_SQL,
20
+ UNIQUE_SQL,
21
+ )
22
+
23
+ if TYPE_CHECKING:
24
+ from collections.abc import Iterator
25
+
26
+
27
+ class BigQueryAdapter:
28
+ """Implements DatabasePort against Google BigQuery."""
29
+
30
+ def __init__(self, project: str, location: str | None = None) -> None:
31
+ self._project = project
32
+ self._location = location
33
+ self._client: Any = None
34
+
35
+ def _get_client(self) -> Any:
36
+ if self._client is None:
37
+ from google.cloud import bigquery
38
+ self._client = bigquery.Client(
39
+ project=self._project, location=self._location,
40
+ )
41
+ return self._client
42
+
43
+ def _qualified(self, schema: str, table: str) -> str:
44
+ """Return a ``project.dataset.table`` reference (backticked at SQL-render time)."""
45
+ return f"{self._project}.{schema}.{table}"
46
+
47
+ def _make_scalar_param(self, name: str, value: str) -> Any:
48
+ from google.cloud.bigquery import ScalarQueryParameter
49
+ return ScalarQueryParameter(name, "STRING", value)
50
+
51
+ def _make_array_param(self, name: str, values: list[str]) -> Any:
52
+ from google.cloud.bigquery import ArrayQueryParameter
53
+ return ArrayQueryParameter(name, "STRING", values)
54
+
55
+ def _run_query(
56
+ self, sql: str, parameters: list[Any] | None = None,
57
+ ) -> list[dict[str, Any]]:
58
+ from google.cloud.bigquery import QueryJobConfig
59
+ client = self._get_client()
60
+ config = QueryJobConfig(query_parameters=parameters or [])
61
+ job = client.query(sql, job_config=config)
62
+ return [dict(row.items()) for row in job.result()]
63
+
64
+ # ------------------------------------------------------------------
65
+ # DatabasePort methods
66
+ # ------------------------------------------------------------------
67
+
68
+ def query(self, sql: str, params: dict[str, Any] | None = None) -> list[dict[str, Any]]:
69
+ bq_params = [
70
+ self._make_scalar_param(k, str(v))
71
+ for k, v in (params or {}).items()
72
+ ]
73
+ return self._run_query(sql, bq_params)
74
+
75
+ def execute(self, sql: str, params: dict[str, Any] | None = None) -> int:
76
+ # Safety gate: refuse DML — adapter is read-only by design.
77
+ first_word = sql.strip().split(None, 1)[0].upper() if sql.strip() else ""
78
+ if first_word in {"INSERT", "UPDATE", "DELETE", "MERGE", "DROP", "CREATE", "ALTER"}:
79
+ raise PermissionError(
80
+ f"BigQueryAdapter refuses DML statement starting with {first_word!r}"
81
+ )
82
+ rows = self.query(sql, params)
83
+ return len(rows)
84
+
85
+ def stream(
86
+ self, sql: str, params: dict[str, Any] | None = None,
87
+ chunk_size: int = 10_000,
88
+ ) -> Iterator[list[dict[str, Any]]]:
89
+ bq_params = [
90
+ self._make_scalar_param(k, str(v))
91
+ for k, v in (params or {}).items()
92
+ ]
93
+ from google.cloud.bigquery import QueryJobConfig
94
+ client = self._get_client()
95
+ config = QueryJobConfig(query_parameters=bq_params)
96
+ job = client.query(sql, job_config=config)
97
+ chunk: list[dict[str, Any]] = []
98
+ for row in job.result():
99
+ chunk.append(dict(row.items()))
100
+ if len(chunk) >= chunk_size:
101
+ yield chunk
102
+ chunk = []
103
+ if chunk:
104
+ yield chunk
105
+
106
+ def table_exists(self, schema: str, table: str) -> bool:
107
+ from google.cloud import bigquery
108
+ client = self._get_client()
109
+ ref = bigquery.TableReference.from_string(
110
+ f"{self._project}.{schema}.{table}"
111
+ )
112
+ try:
113
+ client.get_table(ref)
114
+ return True
115
+ except Exception:
116
+ return False
117
+
118
+ def check_not_null(self, schema: str, table: str, column: str) -> dict[str, int]:
119
+ sql = NOT_NULL_SQL.format(column=column, table=self._qualified(schema, table))
120
+ rows = self._run_query(sql)
121
+ return {
122
+ "null_count": int(rows[0]["null_count"]),
123
+ "total_count": int(rows[0]["total_count"]),
124
+ }
125
+
126
+ def check_unique(self, schema: str, table: str, column: str) -> dict[str, int]:
127
+ sql_dup = UNIQUE_SQL.format(column=column, table=self._qualified(schema, table))
128
+ sql_total = ROW_COUNT_SQL.format(table=self._qualified(schema, table))
129
+ dup_rows = self._run_query(sql_dup)
130
+ total_rows = self._run_query(sql_total)
131
+ return {
132
+ "duplicate_count": int(dup_rows[0]["duplicate_count"]) if dup_rows else 0,
133
+ "total_count": int(total_rows[0]["row_count"]) if total_rows else 0,
134
+ }
135
+
136
+ def check_between(
137
+ self, schema: str, table: str, column: str,
138
+ min_val: str, max_val: str,
139
+ ) -> dict[str, int]:
140
+ sql = BETWEEN_SQL.format(column=column, table=self._qualified(schema, table))
141
+ params = [
142
+ self._make_scalar_param("min", min_val),
143
+ self._make_scalar_param("max", max_val),
144
+ ]
145
+ rows = self._run_query(sql, params)
146
+ return {
147
+ "out_of_range_count": int(rows[0]["out_of_range_count"]),
148
+ "total_count": int(rows[0]["total_count"]),
149
+ "checked": int(rows[0]["checked"]),
150
+ }
151
+
152
+ def check_regex(
153
+ self, schema: str, table: str, column: str, pattern: str,
154
+ ) -> dict[str, int]:
155
+ sql = REGEX_SQL.format(column=column, table=self._qualified(schema, table))
156
+ params = [self._make_scalar_param("pattern", pattern)]
157
+ rows = self._run_query(sql, params)
158
+ return {
159
+ "non_matching_count": int(rows[0]["non_matching_count"]),
160
+ "total_count": int(rows[0]["total_count"]),
161
+ }
162
+
163
+ def check_in_set(
164
+ self, schema: str, table: str, column: str, values: list[str],
165
+ ) -> dict[str, int]:
166
+ sql = IN_SET_SQL.format(column=column, table=self._qualified(schema, table))
167
+ params = [self._make_array_param("values", values)]
168
+ rows = self._run_query(sql, params)
169
+ return {
170
+ "invalid_count": int(rows[0]["invalid_count"]),
171
+ "total_count": int(rows[0]["total_count"]),
172
+ }
173
+
174
+ def check_row_count(self, schema: str, table: str) -> dict[str, int]:
175
+ sql = ROW_COUNT_SQL.format(table=self._qualified(schema, table))
176
+ rows = self._run_query(sql)
177
+ return {"row_count": int(rows[0]["row_count"]) if rows else 0}
178
+
179
+ def check_not_negative(
180
+ self, schema: str, table: str, column: str,
181
+ ) -> dict[str, int]:
182
+ sql = NOT_NEGATIVE_SQL.format(column=column, table=self._qualified(schema, table))
183
+ rows = self._run_query(sql)
184
+ return {
185
+ "negative_count": int(rows[0]["negative_count"]),
186
+ "total_count": int(rows[0]["total_count"]),
187
+ }
188
+
189
+ def check_reference_lookup(
190
+ self, schema: str, table: str, column: str,
191
+ valid_values: list[str],
192
+ ) -> dict[str, int]:
193
+ sql = REFERENCE_LOOKUP_SQL.format(
194
+ column=column, table=self._qualified(schema, table),
195
+ )
196
+ params = [self._make_array_param("valid_values", valid_values)]
197
+ rows = self._run_query(sql, params)
198
+ return {
199
+ "invalid_count": int(rows[0]["invalid_count"]),
200
+ "total_count": int(rows[0]["total_count"]),
201
+ }
202
+
203
+ def close(self) -> None:
204
+ if self._client is not None:
205
+ self._client.close()
206
+ self._client = None
File without changes