diffdb-core 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diffdb/__init__.py +179 -0
- diffdb/concurrency/__init__.py +10 -0
- diffdb/concurrency/pool.py +88 -0
- diffdb/concurrency/stream.py +111 -0
- diffdb/core/__init__.py +38 -0
- diffdb/core/differ.py +136 -0
- diffdb/core/hash_differ.py +390 -0
- diffdb/core/segment.py +323 -0
- diffdb/core/sql.py +81 -0
- diffdb/core/summary.py +179 -0
- diffdb/databases/__init__.py +59 -0
- diffdb/databases/_connect.py +210 -0
- diffdb/databases/base.py +266 -0
- diffdb/databases/bigquery.py +54 -0
- diffdb/databases/clickhouse.py +35 -0
- diffdb/databases/databricks.py +40 -0
- diffdb/databases/dialects/_base.yaml +182 -0
- diffdb/databases/dialects/bigquery.yaml +39 -0
- diffdb/databases/dialects/clickhouse.yaml +42 -0
- diffdb/databases/dialects/databricks.yaml +36 -0
- diffdb/databases/dialects/duckdb.yaml +48 -0
- diffdb/databases/dialects/mysql.yaml +45 -0
- diffdb/databases/dialects/oracle.yaml +44 -0
- diffdb/databases/dialects/postgresql.yaml +44 -0
- diffdb/databases/dialects/presto.yaml +37 -0
- diffdb/databases/dialects/redshift.yaml +11 -0
- diffdb/databases/dialects/snowflake.yaml +55 -0
- diffdb/databases/dialects/trino.yaml +5 -0
- diffdb/databases/dialects/vertica.yaml +39 -0
- diffdb/databases/duckdb.py +40 -0
- diffdb/databases/mysql.py +38 -0
- diffdb/databases/oracle.py +99 -0
- diffdb/databases/postgresql.py +34 -0
- diffdb/databases/presto.py +41 -0
- diffdb/databases/redshift.py +12 -0
- diffdb/databases/snowflake.py +55 -0
- diffdb/databases/trino.py +41 -0
- diffdb/databases/vertica.py +43 -0
- diffdb/databases/yaml_dialect.py +428 -0
- diffdb/geometry/__init__.py +42 -0
- diffdb/geometry/arithmetic.py +141 -0
- diffdb/geometry/bisection.py +100 -0
- diffdb/geometry/vector.py +42 -0
- diffdb/telemetry/__init__.py +11 -0
- diffdb/telemetry/info_tree.py +52 -0
- diffdb/telemetry/query_tracker.py +53 -0
- diffdb/types.py +302 -0
- diffdb/utils.py +121 -0
- diffdb_core-0.1.0.dist-info/METADATA +315 -0
- diffdb_core-0.1.0.dist-info/RECORD +53 -0
- diffdb_core-0.1.0.dist-info/WHEEL +5 -0
- diffdb_core-0.1.0.dist-info/licenses/LICENSE.md +87 -0
- diffdb_core-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: diffdb-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Cross-database table diffing by recursive checksum bisection, with declarative YAML SQL dialects
|
|
5
|
+
Author: Sarath Mohan
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/sarath-mec/diffdb-core
|
|
8
|
+
Project-URL: Documentation, https://github.com/sarath-mec/diffdb-core/blob/main/ARCHITECTURE.md
|
|
9
|
+
Project-URL: Issues, https://github.com/sarath-mec/diffdb-core/issues
|
|
10
|
+
Keywords: database,diff,data-validation,migration,checksum,oracle,postgresql
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Database
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE.md
|
|
21
|
+
Requires-Dist: dsnparse>=0.2.0
|
|
22
|
+
Requires-Dist: pyyaml>=6.0
|
|
23
|
+
Provides-Extra: oracle
|
|
24
|
+
Requires-Dist: oracledb>=2.0.0; extra == "oracle"
|
|
25
|
+
Provides-Extra: postgresql
|
|
26
|
+
Requires-Dist: psycopg2-binary>=2.9.0; extra == "postgresql"
|
|
27
|
+
Provides-Extra: redshift
|
|
28
|
+
Requires-Dist: psycopg2-binary>=2.9.0; extra == "redshift"
|
|
29
|
+
Provides-Extra: mysql
|
|
30
|
+
Requires-Dist: pymysql>=1.0.0; extra == "mysql"
|
|
31
|
+
Provides-Extra: snowflake
|
|
32
|
+
Requires-Dist: snowflake-connector-python>=3.0.0; extra == "snowflake"
|
|
33
|
+
Requires-Dist: cryptography>=41.0.0; extra == "snowflake"
|
|
34
|
+
Provides-Extra: bigquery
|
|
35
|
+
Requires-Dist: google-cloud-bigquery>=3.0.0; extra == "bigquery"
|
|
36
|
+
Provides-Extra: databricks
|
|
37
|
+
Requires-Dist: databricks-sql-connector>=2.0.0; extra == "databricks"
|
|
38
|
+
Provides-Extra: duckdb
|
|
39
|
+
Requires-Dist: duckdb>=0.9.0; extra == "duckdb"
|
|
40
|
+
Provides-Extra: trino
|
|
41
|
+
Requires-Dist: trino>=0.320.0; extra == "trino"
|
|
42
|
+
Provides-Extra: presto
|
|
43
|
+
Requires-Dist: presto-python-client>=0.8.0; extra == "presto"
|
|
44
|
+
Provides-Extra: clickhouse
|
|
45
|
+
Requires-Dist: clickhouse-driver>=0.2.0; extra == "clickhouse"
|
|
46
|
+
Provides-Extra: vertica
|
|
47
|
+
Requires-Dist: vertica-python>=1.0.0; extra == "vertica"
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
# diffdb-core
|
|
51
|
+
|
|
52
|
+
Compare tables across different databases without moving the data. `diffdb` pushes a
|
|
53
|
+
`count(*)` + checksum query for each key range down to both databases, and recursively splits only the ranges
|
|
54
|
+
whose checksums differ. Rows are downloaded only for the small segments that actually contain differences,
|
|
55
|
+
then paired by key into a per-row, per-column summary.
|
|
56
|
+
|
|
57
|
+
Built for validating database migrations (e.g. Oracle → PostgreSQL), where the two sides run on different
|
|
58
|
+
engines and a `FULL OUTER JOIN` isn't possible.
|
|
59
|
+
|
|
60
|
+
- **12 databases** through declarative YAML dialects: PostgreSQL, Oracle, MySQL, Snowflake, BigQuery, Redshift,
|
|
61
|
+
Databricks, DuckDB, Trino, Presto, ClickHouse, Vertica.
|
|
62
|
+
- **Any pair**: the source and target can be different engines; each side renders values to the same text before hashing.
|
|
63
|
+
- **No metadata reads**: you pass the columns, their native types and optional SQL transform rules, so the
|
|
64
|
+
engine sends only four read-only query shapes and never touches the catalog.
|
|
65
|
+
- **Non-unique keys** work: bisection columns need only be selective, and duplicate rows are counted.
|
|
66
|
+
- **Per-key summary**: changed rows with their differing columns, source-only and target-only rows, duplicate keys.
|
|
67
|
+
- **Telemetry**: every query, row count, checksum and duration can be captured for auditing.
|
|
68
|
+
|
|
69
|
+
## Install
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install "diffdb-core[postgresql,oracle]" # pick the extras for your databases
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Extras: `oracle`, `postgresql`, `redshift`, `mysql`, `snowflake`, `bigquery`, `databricks`, `duckdb`, `trino`,
|
|
76
|
+
`presto`, `clickhouse`, `vertica`. The package is imported as `diffdb`. Python ≥ 3.12.
|
|
77
|
+
|
|
78
|
+
## Quick start
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from diffdb import connect_to_table, diff_tables
|
|
82
|
+
|
|
83
|
+
# Every compared column with its native datatype. Source and target are paired by position,
|
|
84
|
+
# so both dicts list the columns in the same order (bisection columns first).
|
|
85
|
+
src = connect_to_table(
|
|
86
|
+
"oracle://app_user:pwd@oracle-host:1521/ORCL",
|
|
87
|
+
"SALES.CUSTOMER",
|
|
88
|
+
bisection_columns=("CUSTOMER_ID",),
|
|
89
|
+
columns={
|
|
90
|
+
"CUSTOMER_ID": {"datatype": "NUMBER(10,0)"},
|
|
91
|
+
"EMAIL": {"datatype": "VARCHAR2(200)"},
|
|
92
|
+
"BALANCE": {"datatype": "NUMBER(12,2)"},
|
|
93
|
+
"NOTES": {"datatype": "NUMBER(10,0)", "transform_rule": 'DBMS_LOB.GETLENGTH("NOTES")'}, # CLOB -> length
|
|
94
|
+
},
|
|
95
|
+
)
|
|
96
|
+
tgt = connect_to_table(
|
|
97
|
+
"postgresql://app_user:pwd@pg-host:5432/sales",
|
|
98
|
+
"sales.customer",
|
|
99
|
+
bisection_columns=("customer_id",),
|
|
100
|
+
columns={
|
|
101
|
+
"customer_id": {"datatype": "bigint"},
|
|
102
|
+
"email": {"datatype": "varchar(200)"},
|
|
103
|
+
"balance": {"datatype": "numeric(12,2)"},
|
|
104
|
+
"notes": {"datatype": "integer", "transform_rule": 'LENGTH("notes")'},
|
|
105
|
+
},
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
diff = diff_tables(src, tgt)
|
|
109
|
+
try:
|
|
110
|
+
summary = diff.summarize(limit=1000) # stop after 1000 differing keys
|
|
111
|
+
finally:
|
|
112
|
+
diff.close()
|
|
113
|
+
|
|
114
|
+
print(summary.changed, summary.source_only, summary.target_only, summary.limit_reached)
|
|
115
|
+
for kd in summary.key_diffs: # kind: changed | source_only | target_only | duplicate_key
|
|
116
|
+
if kd.kind == "changed":
|
|
117
|
+
for cd in kd.column_diffs:
|
|
118
|
+
print(kd.key, cd.target_column, cd.source_value, "->", cd.target_value)
|
|
119
|
+
else: # source_only | target_only | duplicate_key: the unpaired rows
|
|
120
|
+
print(kd.key, kd.kind, kd.source_rows, kd.target_rows)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Rows are paired into `changed` results by `key_columns`, which default to the bisection columns; see
|
|
124
|
+
[Keys and the per-key summary](#keys-and-the-per-key-summary).
|
|
125
|
+
|
|
126
|
+
You can also iterate the raw stream (`for sign, row in diff_tables(...)`, with `-` = source only and `+` = target
|
|
127
|
+
only), get counts with `get_stats_dict()`, and capture every query with `track_queries=True, return_queries=True`.
|
|
128
|
+
See [ARCHITECTURE.md](https://github.com/sarath-mec/diffdb-core/blob/main/ARCHITECTURE.md#6-python-api-reference--practical-recipes) for these recipes.
|
|
129
|
+
|
|
130
|
+
### Connections
|
|
131
|
+
|
|
132
|
+
`connect()` / `connect_to_table()` take a URI (`postgresql://user:pwd@host:5432/db`) or a dict whose `driver` is
|
|
133
|
+
one of the schemes above and whose other keys go to that database's Python driver:
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
import diffdb
|
|
137
|
+
|
|
138
|
+
pg = diffdb.connect({"driver": "postgresql", "host": "pg-host", "port": 5432, "database": "sales",
|
|
139
|
+
"user": "app_user", "password": "..."})
|
|
140
|
+
ora = diffdb.connect({"driver": "oracle", "user": "app_user", "password": "...",
|
|
141
|
+
"dsn": "oracle-host:1521/ORCLPDB1"}, thread_count=4)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
An existing `Database` can be passed to `connect_to_table()` instead of a URI, so one connection pool serves many tables.
|
|
145
|
+
|
|
146
|
+
## How it works
|
|
147
|
+
|
|
148
|
+
1. **Divide**: the key space of `bisection_columns` (from `min`/`max`) is split into `bisection_factor` ranges (default 32).
|
|
149
|
+
2. **Checksum**: for each range, both databases compute `count(*)` and the sum of a 60-bit integer taken from the MD5
|
|
150
|
+
of each row, where the row is its normalized columns joined with `'|'`.
|
|
151
|
+
3. **Recurse**: ranges with equal counts and checksums are done. The others are split again until they hold fewer
|
|
152
|
+
rows than `bisection_threshold` (default 16,384).
|
|
153
|
+
4. **Download & compare**: only those small ranges are downloaded and compared in memory.
|
|
154
|
+
5. **Summarize**: `summarize()` pairs the differing rows by `key_columns` (default: the bisection columns).
|
|
155
|
+
|
|
156
|
+
For a table bisected on `(ADDRESS_SK, ORACLE_COLUMN_NAME)` the checksum queries look like this. Oracle (database
|
|
157
|
+
character set isn't AL32UTF8, so the row is converted first, to hash the same bytes as PostgreSQL; detected from
|
|
158
|
+
`NLS_CHARACTERSET` or forced with a `hash_charset` connection setting):
|
|
159
|
+
|
|
160
|
+
```sql
|
|
161
|
+
SELECT
|
|
162
|
+
count(*),
|
|
163
|
+
sum(to_number(substr(standard_hash(CONVERT((
|
|
164
|
+
NVL(to_char("ADDRESS_SK", 'FM99999999999999999999999999999999999999'), '<null>')
|
|
165
|
+
|| '|' || NVL("ORACLE_COLUMN_NAME", '<null>')
|
|
166
|
+
|| '|' || NVL(to_char(cast(("UPDATE_TMSTMP" + INTERVAL '+5' HOUR) as timestamp(6)), 'YYYY-MM-DD HH24:MI:SS.FF6'), '<null>')
|
|
167
|
+
|| '|' || NVL("UPDATE_USER_ID", '<null>')
|
|
168
|
+
), 'AL32UTF8'), 'MD5'), 18), 'xxxxxxxxxxxxxxx'))
|
|
169
|
+
FROM "SALES"."ADDRESS_AUDIT"
|
|
170
|
+
WHERE ("ADDRESS_SK" >= 1405) AND ("ORACLE_COLUMN_NAME" >= 'active_ind')
|
|
171
|
+
AND ("ADDRESS_SK" < 2662) AND ("ORACLE_COLUMN_NAME" < 'dffkhzQ2yoa4QcQl')
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
PostgreSQL (with a `COLLATE "C"` transform rule on the string bisection column, see Limitations):
|
|
175
|
+
|
|
176
|
+
```sql
|
|
177
|
+
SELECT
|
|
178
|
+
count(*),
|
|
179
|
+
sum(('x' || substring(md5((
|
|
180
|
+
coalesce("address_sk"::varchar, '<null>')
|
|
181
|
+
|| '|' || coalesce(("oracle_column_name" COLLATE "C"), '<null>')
|
|
182
|
+
|| '|' || coalesce(to_char("update_tmstmp"::timestamp(6), 'YYYY-mm-dd HH24:MI:SS.US'), '<null>')
|
|
183
|
+
|| '|' || coalesce("update_user_id", '<null>')
|
|
184
|
+
)), 18))::bit(60)::bigint)
|
|
185
|
+
FROM "sales"."address_audit"
|
|
186
|
+
WHERE ("address_sk" >= 1405) AND (("oracle_column_name" COLLATE "C") >= 'active_ind')
|
|
187
|
+
AND ("address_sk" < 2662) AND (("oracle_column_name" COLLATE "C") < 'dffkhzQ2yoa4QcQl')
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Defining columns
|
|
191
|
+
|
|
192
|
+
`TableSegment` (or `connect_to_table`) takes:
|
|
193
|
+
|
|
194
|
+
| Argument | Meaning |
|
|
195
|
+
| :--- | :--- |
|
|
196
|
+
| `bisection_columns` | Columns that split the table into key ranges. Need not be unique, but should be selective and indexed: one value holding more rows than `bisection_threshold` can't be split and is downloaded whole (with a warning). Integers, decimals, timestamps, UUIDs and alphanumeric strings are supported. |
|
|
197
|
+
| `columns` | `{name: {"datatype": "<native type>", "transform_rule": "<sql>"}}` for every compared column, bisection columns included. `transform_rule` replaces the column (wrapped in parentheses); `datatype` is then the type of the expression's result. |
|
|
198
|
+
| `key_columns` | Columns identifying a logical row in the summary (default: `bisection_columns`). Used only to report differences; see [Keys and the per-key summary](#keys-and-the-per-key-summary). |
|
|
199
|
+
| `where` | Optional SQL filter added to every query, e.g. a time window. |
|
|
200
|
+
|
|
201
|
+
All problems with `columns` (missing datatype, unknown or unsupported type, bisection column not listed) are
|
|
202
|
+
reported together in one `ValueError`.
|
|
203
|
+
|
|
204
|
+
**Types.** The engine compares numbers, strings, timestamps/dates and booleans (hashed as `1`/`0`); `NULL` is
|
|
205
|
+
`'<null>'` on every side. LOB and binary types (`CLOB`, `BLOB`, `RAW`, `bytea`, …) are rejected on purpose: reduce
|
|
206
|
+
them with a `transform_rule` (e.g. a length). When the two sides declare different precisions, both are compared
|
|
207
|
+
at the lower one. An unscaled decimal (Oracle `NUMBER`, PostgreSQL `numeric`) is compared as a whole number, with a
|
|
208
|
+
warning; declare a scale on both sides (`NUMBER(12,2)` / `numeric(12,2)`) to compare decimals.
|
|
209
|
+
|
|
210
|
+
## Keys and the per-key summary
|
|
211
|
+
|
|
212
|
+
The diff itself works on whole rows: a range whose checksums differ is downloaded, and every row that isn't
|
|
213
|
+
present on the other side, value for value, comes out as `('-', row)` (source only) or `('+', row)` (target only).
|
|
214
|
+
`key_columns` decide how `summarize()` and `get_stats_dict()` turn those rows into results. They are never sent to
|
|
215
|
+
the database and don't change which rows are compared.
|
|
216
|
+
|
|
217
|
+
- **Bisection columns vs key columns**: `bisection_columns` split the table into ranges (they should be indexed);
|
|
218
|
+
`key_columns` say which rows are "the same row" (usually the primary key). The default is the bisection columns.
|
|
219
|
+
- **Positions, not names**: the two sides are paired by column position, so the key columns must sit at the same
|
|
220
|
+
positions in both `columns` dicts; `diff_tables` checks this before running any query.
|
|
221
|
+
- **Not unique**: keys may repeat. Nothing in the database is checked.
|
|
222
|
+
- **Include every bisection column** in the key when you can. Both versions of a key then land in the same range, so
|
|
223
|
+
pairing stays exact even when `summarize(limit=N)` stops the run early.
|
|
224
|
+
|
|
225
|
+
### How rows become `key_diffs`
|
|
226
|
+
|
|
227
|
+
All differing rows are grouped by key. Rows that appear identically on both sides cancel out first, so only the
|
|
228
|
+
leftover rows of a key decide its `kind`:
|
|
229
|
+
|
|
230
|
+
| Leftover rows for a key | `kind` | What the `KeyDiff` holds | Counted in |
|
|
231
|
+
| :--- | :--- | :--- | :--- |
|
|
232
|
+
| 1 source, 1 target | `changed` | `column_diffs`: the differing columns, with both sides' names and values | `changed` (1) |
|
|
233
|
+
| source only (1 or more) | `source_only` | `source_rows` | `source_only` (one per row) |
|
|
234
|
+
| target only (1 or more) | `target_only` | `target_rows` | `target_only` (one per row) |
|
|
235
|
+
| both sides, not exactly 1 and 1 (e.g. 2 source, 1 target) | `duplicate_key` | `source_rows` and `target_rows`, unpaired, no `column_diffs` | `source_only` and `target_only` (one per row) |
|
|
236
|
+
|
|
237
|
+
`summary.duplicate_keys` is `True` when any key had more than one leftover row on a side. Rows hold the values as
|
|
238
|
+
downloaded (normalized strings), in `columns` order with the bisection columns first.
|
|
239
|
+
|
|
240
|
+
For example, with `key_columns=("ORDER_ID", "LINE_NO")` these differing rows:
|
|
241
|
+
|
|
242
|
+
```text
|
|
243
|
+
- (1, 1, QTY 5) + (1, 1, QTY 6) one row each side
|
|
244
|
+
- (2, 1, QTY 3) source only
|
|
245
|
+
+ (3, 1, QTY 9) target only
|
|
246
|
+
- (4, 1, QTY 2) + (4, 1, QTY 8) key 4 is duplicated in the source:
|
|
247
|
+
- (4, 1, QTY 7) 2 source rows, 1 target row
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
summarize to (`summary.as_dict()["key_diffs"]`, abridged):
|
|
251
|
+
|
|
252
|
+
```text
|
|
253
|
+
key ["1","1"] changed column_diffs [QTY/qty: "5" -> "6"]
|
|
254
|
+
key ["2","1"] source_only source_rows [["2","1","3"]]
|
|
255
|
+
key ["3","1"] target_only target_rows [["3","1","9"]]
|
|
256
|
+
key ["4","1"] duplicate_key source_rows [["4","1","2"], ["4","1","7"]] target_rows [["4","1","8"]]
|
|
257
|
+
|
|
258
|
+
counts: changed 1, source_only 3, target_only 2; duplicate_keys: true
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Duplicates often look like ordinary differences, because matching copies cancel:
|
|
262
|
+
|
|
263
|
+
| Source rows for a key | Target rows | Reported as |
|
|
264
|
+
| :--- | :--- | :--- |
|
|
265
|
+
| `A`, `A` | `A`, `A` | nothing (identical) |
|
|
266
|
+
| `A`, `A` | `A` | `source_only` with one row `A` (the extra copy); `duplicate_keys` stays `False` |
|
|
267
|
+
| `A`, `B` | `A`, `C` | `changed`, `B` → `C` (the `A` copies cancel) |
|
|
268
|
+
| `B`, `C` | `D` | `duplicate_key`: no way to tell which source row became `D` |
|
|
269
|
+
|
|
270
|
+
Use a key that is unique in your data when you need every difference to be a `changed` row. Use `duplicate_key`
|
|
271
|
+
entries and `duplicate_keys` as the signal to look at the rows yourself.
|
|
272
|
+
|
|
273
|
+
## Known limitations
|
|
274
|
+
|
|
275
|
+
- **String collation**: Oracle sorts strings by bytes, PostgreSQL by its collation by default, so the same key
|
|
276
|
+
range selects different rows. Add `COLLATE "C"` as the PostgreSQL `transform_rule` of string bisection columns.
|
|
277
|
+
That bypasses the default index (create one with `COLLATE "C"`), so prefer numeric bisection columns.
|
|
278
|
+
- **Alphanumeric keys**: string bisection keys may only contain `space - . 0-9 A-Z _ a-z`
|
|
279
|
+
(`diffdb/geometry/arithmetic.py`). Bisect on another column when keys contain other characters.
|
|
280
|
+
- **Oracle 4000-byte limit**: the row string must fit in a `VARCHAR2` (`ORA-01489` otherwise). Compare very wide
|
|
281
|
+
text columns through a transform rule such as `LENGTH(col)`.
|
|
282
|
+
- **Live data**: rows changing during a run show up as differences. Restrict `where` to a stable window.
|
|
283
|
+
- **Character sets**: values both drivers decode to the same Unicode text compare equal at row level, but a
|
|
284
|
+
checksum mismatch still costs a download of that segment.
|
|
285
|
+
|
|
286
|
+
## Adding a database
|
|
287
|
+
|
|
288
|
+
1. A YAML dialect in `src/diffdb/databases/dialects/<db>.yaml` that `extends: _base.yaml` and declares its SQL
|
|
289
|
+
fragments, type mapping and normalization templates. `_base.yaml` documents every key; unknown keys, type
|
|
290
|
+
classes and template placeholders are rejected when the dialect loads.
|
|
291
|
+
2. A small driver class in `src/diffdb/databases/<db>.py` (driver import and connection creation), registered in
|
|
292
|
+
`DATABASE_BY_SCHEME` (`src/diffdb/databases/_connect.py`).
|
|
293
|
+
|
|
294
|
+
The new dialect must render every value byte-identically to its counterpart. See
|
|
295
|
+
[ARCHITECTURE.md](https://github.com/sarath-mec/diffdb-core/blob/main/ARCHITECTURE.md#4-declarative-yaml-dialect-framework).
|
|
296
|
+
|
|
297
|
+
## Development
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
uv sync # installs the package with pytest, ruff and duckdb
|
|
301
|
+
uv run pytest # no external database needed
|
|
302
|
+
uv run ruff check .
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
The tests include unit tests, a DuckDB end-to-end diff with planted differences, and golden snapshots of the SQL
|
|
306
|
+
every dialect generates (`tests/golden/`). After an intended dialect or SQL change, regenerate and review them:
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
DIFFDB_UPDATE_GOLDEN=1 uv run python -m unittest tests.test_dialects tests.test_query_snapshot
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## License
|
|
313
|
+
|
|
314
|
+
MIT. `diffdb` adapts code from [reladiff](https://github.com/erezsh/reladiff) and
|
|
315
|
+
[sqeleton](https://github.com/erezsh/sqeleton) (both MIT, by Erez Shinan); see [LICENSE.md](https://github.com/sarath-mec/diffdb-core/blob/main/LICENSE.md).
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
diffdb/__init__.py,sha256=PhkqQCz-eZ0ZXI9i1oIDquksRiYtp3MQMQJ0gKRkQa8,7599
|
|
2
|
+
diffdb/types.py,sha256=oYGHaVCbaFpE3cLvITDgPIOm7XD9Bgy48ljBG4VhsMA,9927
|
|
3
|
+
diffdb/utils.py,sha256=ia_5f2ZC9tUl0oR89fFexjyU9SMKKSfFPx7slsazmfo,2911
|
|
4
|
+
diffdb/concurrency/__init__.py,sha256=R3quisr2f23EPhe0IgkldEwrbGgymG3nCbwGpj2sIJo,194
|
|
5
|
+
diffdb/concurrency/pool.py,sha256=FGMeIB6XmN4WK5tXNLtHTPgmYsdHyBKR8G-sLJQxDKM,2909
|
|
6
|
+
diffdb/concurrency/stream.py,sha256=_qffVEuhZS5JmVdP_xhtqU3NlG7L350i8bdydHOtUo4,3775
|
|
7
|
+
diffdb/core/__init__.py,sha256=xdHLxcF-PUgxdNDn8zQzOtodmODt7mBZchrmlk69FGA,789
|
|
8
|
+
diffdb/core/differ.py,sha256=MErq-JGiahiO3oBNsyHrVaduuatHNuia17F5Ht7_OF4,5412
|
|
9
|
+
diffdb/core/hash_differ.py,sha256=aoi5Ae4SAwpdNxwGUT9TUsg9g_b_aKJBi2_XQfSI6wc,18336
|
|
10
|
+
diffdb/core/segment.py,sha256=-lnHIOezd0f2WQ2d4ySIIc8DKhqX1hPzqHMtI8IFXX8,14904
|
|
11
|
+
diffdb/core/sql.py,sha256=UThlUTr37917hsfzyubMG0eGAInsyGdnJREwfkKWacU,3342
|
|
12
|
+
diffdb/core/summary.py,sha256=nDozOCpBybrMcHzGcgyVn_D8nozcP8pMZ0JbNclixY8,6922
|
|
13
|
+
diffdb/databases/__init__.py,sha256=uzzoY2Q93X6vEPdniCsj7_pWoxVc7GeBgOGtLyuFgCE,1201
|
|
14
|
+
diffdb/databases/_connect.py,sha256=beHHv3sNcuU4r8kSMsFpDjwaE_hCEUS2mkkJ8z7id_M,6854
|
|
15
|
+
diffdb/databases/base.py,sha256=-vEGzFX12NcZlnbMWY_Fqidxnfdt-yIGyJ8vruSJ3Lw,8666
|
|
16
|
+
diffdb/databases/bigquery.py,sha256=mDk_C2PJGu1avVl_hj0r95xYiVTT2PsJaAJrvvVzLVk,1464
|
|
17
|
+
diffdb/databases/clickhouse.py,sha256=rbcqZMmbK0SNhklcAnWmIDQ18aMpXERJVERM0IiT7ws,1014
|
|
18
|
+
diffdb/databases/databricks.py,sha256=Kq15SnUFaYFMGNU9LwiQqbnW1AwrM-rYMN7KQ4AgAEY,1040
|
|
19
|
+
diffdb/databases/duckdb.py,sha256=BjbsiSEAEC1HuxQ0VgGuweE80Y2N4EIWI4E1lholxcc,922
|
|
20
|
+
diffdb/databases/mysql.py,sha256=TOi00N1ZHaeINEufwXUX8_egckdksvBfYuGD3-PJh4I,1075
|
|
21
|
+
diffdb/databases/oracle.py,sha256=qJGfyiv7sgtWbW3jhX-45FZ2gN2YOzFA70TO1Hb-t7I,4132
|
|
22
|
+
diffdb/databases/postgresql.py,sha256=OdpgKVgGp5CFg_dFc0k1TRHZ-QXF40hJRq5IvYrj8YA,948
|
|
23
|
+
diffdb/databases/presto.py,sha256=-7fiFR4B5Bu0J2VgAHlv9btU_l1FMV0T4GnQ3UuHDiw,977
|
|
24
|
+
diffdb/databases/redshift.py,sha256=uiVP9Qw5KEA2Rm2qdo6nZOiTUWn-SNZsprOdj_oTfaw,303
|
|
25
|
+
diffdb/databases/snowflake.py,sha256=Cpb_EyjbfmVIBbzr0BMtWU4mwHiqEQmJznnj_DFTB7Y,2074
|
|
26
|
+
diffdb/databases/trino.py,sha256=UxI7MQWFiBAEHv3VCkxdgiERQLeeJZqPUXoBguTSLxU,956
|
|
27
|
+
diffdb/databases/vertica.py,sha256=uOql6twPLBv3gDKXqL5V1SmWBzjMGMweOyDZUdD-P_c,1106
|
|
28
|
+
diffdb/databases/yaml_dialect.py,sha256=0wS4HpFx5RePCoq5BouyBZGszLwo7LWZgMEJMVB35ac,18891
|
|
29
|
+
diffdb/databases/dialects/_base.yaml,sha256=r6w0QBYtmpBa7tKMNWx2vU6Tjt6-C9KqZu77aGXyMwY,10508
|
|
30
|
+
diffdb/databases/dialects/bigquery.yaml,sha256=Oy0VRenuvrGvEQgZgFM3TW6hvtD96WwQMAymKMyWiXA,1185
|
|
31
|
+
diffdb/databases/dialects/clickhouse.yaml,sha256=2PG-lrgh0UFq6bWj-hCxjfD4O6Ts7eD-HGMSmgSIvHY,960
|
|
32
|
+
diffdb/databases/dialects/databricks.yaml,sha256=QqzGNgy-_FNhVoJCxWBzhGul1fBymgXeaIAKHDSyGgc,855
|
|
33
|
+
diffdb/databases/dialects/duckdb.yaml,sha256=P85UtFxBAVe5BhJZwW1vxi2-UWceXpeZAQnH3nUzIgk,1274
|
|
34
|
+
diffdb/databases/dialects/mysql.yaml,sha256=-_AzeLpwWKD5ZEEaIOjUsKZ52qYd0GI36H2FN7VK5-o,1047
|
|
35
|
+
diffdb/databases/dialects/oracle.yaml,sha256=qj3yDW-kyhdiO1w890IhZB_xg7CRaIkfSZrUZ19_xW0,1612
|
|
36
|
+
diffdb/databases/dialects/postgresql.yaml,sha256=YbRsHklAd7ejKV-e0Dj-5s1f3Cz1HRqJ0q3Q7ORJ8VY,1302
|
|
37
|
+
diffdb/databases/dialects/presto.yaml,sha256=U8hRRa5VGg9eWFkLctR4pp3OmNAH15V5pBPBM7tu8_I,849
|
|
38
|
+
diffdb/databases/dialects/redshift.yaml,sha256=XGSYKQcsUWbDp3dtGi4p5znFYrmgKII_vW20bzYnrMk,249
|
|
39
|
+
diffdb/databases/dialects/snowflake.yaml,sha256=_bwpnV3vV0Ohmhm2ruVUAg-dVSdVMybb67Ijc50VP1s,1686
|
|
40
|
+
diffdb/databases/dialects/trino.yaml,sha256=c0fiQ7A9GZN7Atn5bh8dA5Qosx2FNKIbdqS9ATYclCI,107
|
|
41
|
+
diffdb/databases/dialects/vertica.yaml,sha256=Vg8UPkfKqNenLGjmu8r-m-BBguk75fgdlWVnUqMM_wo,945
|
|
42
|
+
diffdb/geometry/__init__.py,sha256=N9BD7v4GCrt7WsNBay4VcPSSvVFRCnKNmbNmt8H1hlo,859
|
|
43
|
+
diffdb/geometry/arithmetic.py,sha256=yBXKHZgDpmfG6tfhuy1vcSJhY51IA9nNEP0NJVRRwbk,4377
|
|
44
|
+
diffdb/geometry/bisection.py,sha256=L7KrgQy7F2MbrXAruc0GNNr36aqLLH2Z6PKfs-LTUqA,3440
|
|
45
|
+
diffdb/geometry/vector.py,sha256=27ok3tu-DpnOQXs8HfVWBMSKWl3HI9W9KSk3AuHrMuE,1512
|
|
46
|
+
diffdb/telemetry/__init__.py,sha256=LQDy9L2cF3WqZkQbGE12HHXcMNpNIirplzxZKWJMqrQ,239
|
|
47
|
+
diffdb/telemetry/info_tree.py,sha256=nqt9IGLdy0x3WLevhYd8AsTiflIH26hsuLNF2Sm4BzE,1521
|
|
48
|
+
diffdb/telemetry/query_tracker.py,sha256=wK4Q3ERcCudkJsjpkaONqS-UEjEEAPuobHOupJS_nKs,1692
|
|
49
|
+
diffdb_core-0.1.0.dist-info/licenses/LICENSE.md,sha256=BhpQu7Vh18Qd-5AmNYVqaeUSvHWTk1n_9atj9r4kRhs,3701
|
|
50
|
+
diffdb_core-0.1.0.dist-info/METADATA,sha256=hxHeEk_yez68unYo6YZkKVD8N3r_UDcEjlrAvP7ZxKE,16672
|
|
51
|
+
diffdb_core-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
52
|
+
diffdb_core-0.1.0.dist-info/top_level.txt,sha256=34BdAwNkIALSU7RVEmtdtebfvtoIdf1ruWC7ByXO2H4,7
|
|
53
|
+
diffdb_core-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sarath Mohan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Third-Party Software Notices & Attributions
|
|
26
|
+
|
|
27
|
+
`diffdb` incorporates, adapts, or derives code from the following open-source projects under the permissive **MIT License**:
|
|
28
|
+
|
|
29
|
+
### 1. `reladiff`
|
|
30
|
+
- **Source**: https://github.com/erezsh/reladiff
|
|
31
|
+
- **Copyright**: Copyright (c) 2024 Erez Shinan
|
|
32
|
+
- **License**: MIT License
|
|
33
|
+
|
|
34
|
+
```text
|
|
35
|
+
MIT License
|
|
36
|
+
|
|
37
|
+
Copyright (c) 2024 Erez Shinan
|
|
38
|
+
|
|
39
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
40
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
41
|
+
in the Software without restriction, including without limitation the rights
|
|
42
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
43
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
44
|
+
furnished to do so, subject to the following conditions:
|
|
45
|
+
|
|
46
|
+
The above copyright notice and this permission notice shall be included in all
|
|
47
|
+
copies or substantial portions of the Software.
|
|
48
|
+
|
|
49
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
50
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
51
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
52
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
53
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
54
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
55
|
+
SOFTWARE.
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
### 2. `sqeleton`
|
|
61
|
+
- **Source**: https://github.com/erezsh/sqeleton
|
|
62
|
+
- **Copyright**: Copyright (c) 2023 Erez Shinan
|
|
63
|
+
- **License**: MIT License
|
|
64
|
+
|
|
65
|
+
```text
|
|
66
|
+
MIT License
|
|
67
|
+
|
|
68
|
+
Copyright (c) 2023 Erez Shinan
|
|
69
|
+
|
|
70
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
71
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
72
|
+
in the Software without restriction, including without limitation the rights
|
|
73
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
74
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
75
|
+
furnished to do so, subject to the following conditions:
|
|
76
|
+
|
|
77
|
+
The above copyright notice and this permission notice shall be included in all
|
|
78
|
+
copies or substantial portions of the Software.
|
|
79
|
+
|
|
80
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
81
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
82
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
83
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
84
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
85
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
86
|
+
SOFTWARE.
|
|
87
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
diffdb
|