diffdb-core 0.1.1__tar.gz → 0.1.2__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.
- {diffdb_core-0.1.1/src/diffdb_core.egg-info → diffdb_core-0.1.2}/PKG-INFO +152 -4
- {diffdb_core-0.1.1 → diffdb_core-0.1.2}/README.md +151 -3
- {diffdb_core-0.1.1 → diffdb_core-0.1.2/diffdb_core.egg-info}/PKG-INFO +152 -4
- diffdb_core-0.1.2/diffdb_core.egg-info/SOURCES.txt +64 -0
- {diffdb_core-0.1.1 → diffdb_core-0.1.2}/pyproject.toml +11 -2
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/__init__.py +1 -1
- diffdb_core-0.1.1/src/diffdb_core.egg-info/SOURCES.txt +0 -64
- {diffdb_core-0.1.1 → diffdb_core-0.1.2}/LICENSE.md +0 -0
- {diffdb_core-0.1.1 → diffdb_core-0.1.2}/MANIFEST.in +0 -0
- {diffdb_core-0.1.1/src → diffdb_core-0.1.2}/diffdb_core.egg-info/dependency_links.txt +0 -0
- {diffdb_core-0.1.1/src → diffdb_core-0.1.2}/diffdb_core.egg-info/requires.txt +0 -0
- {diffdb_core-0.1.1/src → diffdb_core-0.1.2}/diffdb_core.egg-info/top_level.txt +0 -0
- {diffdb_core-0.1.1 → diffdb_core-0.1.2}/setup.cfg +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/concurrency/__init__.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/concurrency/pool.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/concurrency/stream.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/core/__init__.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/core/differ.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/core/hash_differ.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/core/segment.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/core/sql.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/core/summary.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/__init__.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/_connect.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/base.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/bigquery.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/clickhouse.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/databricks.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/dialects/_base.yaml +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/dialects/bigquery.yaml +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/dialects/clickhouse.yaml +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/dialects/databricks.yaml +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/dialects/duckdb.yaml +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/dialects/mysql.yaml +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/dialects/oracle.yaml +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/dialects/postgresql.yaml +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/dialects/presto.yaml +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/dialects/redshift.yaml +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/dialects/snowflake.yaml +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/dialects/trino.yaml +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/dialects/vertica.yaml +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/duckdb.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/mysql.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/oracle.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/postgresql.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/presto.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/redshift.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/snowflake.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/trino.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/vertica.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/databases/yaml_dialect.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/geometry/__init__.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/geometry/arithmetic.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/geometry/bisection.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/geometry/vector.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/telemetry/__init__.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/telemetry/info_tree.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/telemetry/query_tracker.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/types.py +0 -0
- {diffdb_core-0.1.1/src/diffdb → diffdb_core-0.1.2/src}/utils.py +0 -0
- {diffdb_core-0.1.1 → diffdb_core-0.1.2}/tests/golden/dialect_sql.json +0 -0
- {diffdb_core-0.1.1 → diffdb_core-0.1.2}/tests/golden/query_sql.json +0 -0
- {diffdb_core-0.1.1 → diffdb_core-0.1.2}/tests/test_connect.py +0 -0
- {diffdb_core-0.1.1 → diffdb_core-0.1.2}/tests/test_dialects.py +0 -0
- {diffdb_core-0.1.1 → diffdb_core-0.1.2}/tests/test_diffdb_core.py +0 -0
- {diffdb_core-0.1.1 → diffdb_core-0.1.2}/tests/test_e2e_duckdb.py +0 -0
- {diffdb_core-0.1.1 → diffdb_core-0.1.2}/tests/test_query_snapshot.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: diffdb-core
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Cross-database table diffing by recursive checksum bisection, with declarative YAML SQL dialects
|
|
5
5
|
Author: Sarath Mohan
|
|
6
6
|
License: MIT
|
|
@@ -67,6 +67,10 @@ engines and a `FULL OUTER JOIN` isn't possible.
|
|
|
67
67
|
- **Per-key summary**: changed rows with their differing columns, source-only and target-only rows, duplicate keys.
|
|
68
68
|
- **Telemetry**: every query, row count, checksum and duration can be captured for auditing.
|
|
69
69
|
|
|
70
|
+
diffdb-core is the third iteration of this tooling, after `simple-dv-tool` and `ibis-dv-tool`, and is built on
|
|
71
|
+
reladiff's algorithm. See [Background](#background-from-aggregate-fingerprints-to-checksum-bisection) for how it got
|
|
72
|
+
here and [How diffdb-core differs from reladiff](#how-diffdb-core-differs-from-reladiff) for what changed.
|
|
73
|
+
|
|
70
74
|
## Install
|
|
71
75
|
|
|
72
76
|
```bash
|
|
@@ -286,13 +290,157 @@ entries and `duplicate_keys` as the signal to look at the rows yourself.
|
|
|
286
290
|
- **Character sets**: values both drivers decode to the same Unicode text compare equal at row level, but a
|
|
287
291
|
checksum mismatch still costs a download of that segment.
|
|
288
292
|
|
|
293
|
+
## Background: from aggregate fingerprints to checksum bisection
|
|
294
|
+
|
|
295
|
+
diffdb-core is the third iteration of my migration data-validation tooling. The first two are archived and kept
|
|
296
|
+
for reference.
|
|
297
|
+
|
|
298
|
+
### 1. simple-dv-tool: hand-written aggregate SQL
|
|
299
|
+
|
|
300
|
+
[simple-dv-tool](https://github.com/sarath-mec/simple-dv-tool) validated Hive / MySQL → BigQuery migrations from a
|
|
301
|
+
notebook. It split the source into N batches by ranking on a split key, sent each batch's source key range to
|
|
302
|
+
BigQuery as a temp table, and compared **aggregate fingerprints** per batch: `COUNT(1)`, and per column
|
|
303
|
+
`COUNT(DISTINCT c)`, null count, `MIN(c)` and `MAX(c)`. The results were compared in DuckDB, and a BigQuery UDF
|
|
304
|
+
decided what counted as a match (rounding, timezone shifts, NULL-like strings).
|
|
305
|
+
|
|
306
|
+
- Every query was an f-string, with engine-specific code (Hive `DESCRIBE` parsing, MySQL collation, BigQuery scripting).
|
|
307
|
+
- The target could only be BigQuery, and each table was configured by hand.
|
|
308
|
+
|
|
309
|
+
### 2. ibis-dv-tool: the same idea on Ibis, database-wide
|
|
310
|
+
|
|
311
|
+
[ibis-dv-tool](https://github.com/sarath-mec/ibis-dv-tool) kept the fingerprint idea but wrote every query as an
|
|
312
|
+
[Ibis](https://ibis-project.org/) expression, compiled to each backend's SQL, so any Ibis-supported pair worked. It
|
|
313
|
+
added a database-wide mapping phase (a metadata view in each database, fuzzy table/column matching, a reviewable
|
|
314
|
+
YAML config per table) and a **detailed** mode that pulled small tables into pandas and diffed them cell by cell on
|
|
315
|
+
the primary key.
|
|
316
|
+
|
|
317
|
+
Both tools hit the same limits:
|
|
318
|
+
|
|
319
|
+
- **Fingerprints miss changes.** `COUNT(DISTINCT)`, `MIN` and `MAX` stay the same when a value changes in the
|
|
320
|
+
middle of a range, or when two rows swap values. They show *which batch and column* look wrong, never *which rows*.
|
|
321
|
+
- **Row-level comparison doesn't scale.** Detailed mode had to pull the whole table (or batch) into pandas.
|
|
322
|
+
- **Batches are fixed up front.** Narrowing a mismatch inside a large batch was manual drill-down SQL.
|
|
323
|
+
- **Matching rules ran after the fact.** Values were compared in whatever text each engine returned, then a UDF or
|
|
324
|
+
pandas dtype alignment tried to make them agree.
|
|
325
|
+
|
|
326
|
+
### 3. reladiff: what checksum bisection fixed
|
|
327
|
+
|
|
328
|
+
[reladiff](https://github.com/erezsh/reladiff) (a maintained fork of data-diff) solves those problems with
|
|
329
|
+
**recursive checksum bisection**, which is the algorithm diffdb-core uses:
|
|
330
|
+
|
|
331
|
+
| | simple-dv-tool / ibis-dv-tool | reladiff (and diffdb-core) |
|
|
332
|
+
| :--- | :--- | :--- |
|
|
333
|
+
| What is compared | `COUNT`, `COUNT(DISTINCT)`, `MIN`, `MAX` per column | `count(*)` + sum of an MD5 of **every value of every row** |
|
|
334
|
+
| Detects | changes that move a count, min or max | any changed, missing or extra row |
|
|
335
|
+
| Result | batch + column that differ, plus drill-down SQL | the exact differing rows |
|
|
336
|
+
| Narrowing down | fixed batches; manual drill-down | ranges that differ are split again, automatically, until small |
|
|
337
|
+
| Rows moved | none (summary) or the whole table (detailed) | only the rows of small, mismatching ranges |
|
|
338
|
+
| Cross-engine values | compared as returned, then matched by tolerance rules | normalized to the same text **in SQL** before hashing, with precision lowered to the common minimum |
|
|
339
|
+
|
|
340
|
+
What reladiff doesn't do, and the earlier tools did: database-wide table and column mapping, fuzzy name matching
|
|
341
|
+
and tolerance rules. diffdb-core doesn't do those either; it expects the caller to supply the pairing (see below).
|
|
342
|
+
|
|
343
|
+
## How diffdb-core differs from reladiff
|
|
344
|
+
|
|
345
|
+
diffdb-core adapts reladiff's bisection engine (`HashDiffer`, segments, key-space geometry, threaded yielder; see
|
|
346
|
+
[License](#license)) and changes how tables are described, how dialects are defined and how results are reported.
|
|
347
|
+
|
|
348
|
+
| | reladiff | diffdb-core |
|
|
349
|
+
| :--- | :--- | :--- |
|
|
350
|
+
| Column definitions | column **names** (`key_columns`, `extra_columns`); types read from the database | `columns={name: {"datatype", "transform_rule"}}` per side; nothing read from the database |
|
|
351
|
+
| Metadata queries | reads `information_schema` and samples rows to refine types | none (except Oracle `NLS_CHARACTERSET`, once per connection) |
|
|
352
|
+
| Compare an SQL expression | not supported (create a view) | `transform_rule` on any column, bisection columns included |
|
|
353
|
+
| LOB / binary / unknown types | compared anyway, with a "may result in false positives" warning | rejected up front; reduce them with a `transform_rule` |
|
|
354
|
+
| Dialects | Python classes and mixins from [sqeleton](https://github.com/erezsh/sqeleton), SQL built by its query builder | one validated YAML file per database; SQL built as plain strings in `core/sql.py` |
|
|
355
|
+
| Result | `+`/`-` row stream; `get_stats_dict()` counts | the same stream, plus `summarize()`: per-key, per-column results |
|
|
356
|
+
| Duplicate keys in stats | a key with two differing rows on the same side fails an `assert` | reported as `duplicate_key`, with `duplicate_keys=True` |
|
|
357
|
+
| Limit | `--limit` on rows (CLI; can't be combined with `--stats`) | `summarize(limit=N)` on distinct differing keys, cancels outstanding queries |
|
|
358
|
+
| Algorithms | `hashdiff` (cross-database) and `joindiff` (same database) | `hashdiff` only |
|
|
359
|
+
| Interface | CLI, TOML run config, Python API | Python API only |
|
|
360
|
+
| Incremental runs | `update_column` with `min_update` / `max_update` | a `where` filter |
|
|
361
|
+
|
|
362
|
+
### `transform_rule`: comparing expressions, not just columns
|
|
363
|
+
|
|
364
|
+
In reladiff a compared column is a name that must exist in the table's schema. To compare `TRIM(name)`, a CLOB's
|
|
365
|
+
length, or a string key under binary collation, you have to create a view on each side first.
|
|
366
|
+
|
|
367
|
+
In diffdb-core each column entry can carry a `transform_rule`, an SQL expression used instead of the column, and a
|
|
368
|
+
`datatype` that describes the expression's result:
|
|
369
|
+
|
|
370
|
+
```python
|
|
371
|
+
"NOTES": {"datatype": "NUMBER(10,0)", "transform_rule": 'DBMS_LOB.GETLENGTH("NOTES")'}, # Oracle CLOB
|
|
372
|
+
"notes": {"datatype": "integer", "transform_rule": 'LENGTH("notes")'}, # PostgreSQL text
|
|
373
|
+
"line_code": {"datatype": "varchar(20)", "transform_rule": '"line_code" COLLATE "C"'}, # byte-order bisection
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
- The rule is wrapped in parentheses and used **everywhere** the column appears: in the checksum, the key-range
|
|
377
|
+
`MIN`/`MAX`, the downloaded rows, and the key-range `WHERE` clauses when it's a bisection column (see the
|
|
378
|
+
PostgreSQL query in [How it works](#how-it-works)).
|
|
379
|
+
- Each side has its own rule, so the two sides can use different SQL to reach the same value.
|
|
380
|
+
- The declared `datatype` drives normalization and precision reconciliation, so the result is hashed as the type
|
|
381
|
+
you declared, not the column's original type.
|
|
382
|
+
- This is how unsupported types are handled: LOB and binary columns are rejected unless a rule reduces them to a
|
|
383
|
+
number, string or timestamp. reladiff instead hashes them with a warning, which can report false differences.
|
|
384
|
+
|
|
385
|
+
This is the same idea as ibis-dv-tool's editable `src_matched_cols` (where a source "column" could be a cast), now
|
|
386
|
+
applied inside the hash, on both sides, with a declared type.
|
|
387
|
+
|
|
388
|
+
### YAML dialect declarations
|
|
389
|
+
|
|
390
|
+
reladiff gets its dialects from sqeleton: each database is a Python class composed from mixins
|
|
391
|
+
(`oracle.Dialect, oracle.Mixin_MD5, oracle.Mixin_NormalizeValue, …`), with type parsing and value normalization
|
|
392
|
+
spread across Python methods. Checking that two engines render a timestamp identically means reading code in
|
|
393
|
+
several classes.
|
|
394
|
+
|
|
395
|
+
diffdb-core declares each dialect in one YAML file (`src/databases/dialects/<db>.yaml`):
|
|
396
|
+
|
|
397
|
+
- `extends:` another dialect (usually `_base.yaml`, which holds portable ANSI defaults and documents every key).
|
|
398
|
+
- `syntax:` fragments (quoting, concatenation, `md5_as_int`, …), `type_classes` / `type_regexps` (native type name
|
|
399
|
+
→ diffdb type, e.g. `NUMBER` → `Decimal`), and `normalization:` templates (how each type becomes text before
|
|
400
|
+
hashing).
|
|
401
|
+
- **Validated when it loads**: unknown keys, unknown type classes and unknown template placeholders raise
|
|
402
|
+
`DialectConfigError`, rather than producing wrong SQL at run time.
|
|
403
|
+
- Engine-specific behaviour lives in YAML, not in `if name == ...` branches. The only Python per database is a small
|
|
404
|
+
driver class (import and connection).
|
|
405
|
+
- Every dialect's generated SQL is pinned by golden snapshots (`tests/golden/`), so a YAML change that alters a
|
|
406
|
+
query shows up as a test diff.
|
|
407
|
+
|
|
408
|
+
Columns are also declared, not discovered: you pass the native `datatype` of each column, and the dialect's
|
|
409
|
+
`type_classes` turn it into a diffdb type. That replaces reladiff's `information_schema` query and row sampling.
|
|
410
|
+
|
|
411
|
+
(This YAML is a dialect definition. It is different from reladiff's TOML file, which describes runs, and from
|
|
412
|
+
ibis-dv-tool's YAML, which described the table mapping. diffdb-core has no run-config file.)
|
|
413
|
+
|
|
414
|
+
### Summarization
|
|
415
|
+
|
|
416
|
+
reladiff's result is a stream of `('-', row)` and `('+', row)`. `get_stats_dict()` groups that stream by key and
|
|
417
|
+
returns counts: `rows_A`, `rows_B`, `exclusive_A`, `exclusive_B`, `updated`, `unchanged`, `total`. It doesn't say
|
|
418
|
+
*which* columns of an updated row changed, and it assumes each key has at most one differing row per side.
|
|
419
|
+
|
|
420
|
+
diffdb-core keeps that stream and `get_stats_dict()`, and adds `summarize(limit=N)`, which returns a `DiffSummary`:
|
|
421
|
+
|
|
422
|
+
| | reladiff `get_stats_dict()` | diffdb-core `summarize()` |
|
|
423
|
+
| :--- | :--- | :--- |
|
|
424
|
+
| Granularity | counts only | one `KeyDiff` per differing key |
|
|
425
|
+
| Changed rows | counted as `updated` | `changed`, with a `ColumnDiff` per differing column: source and target column names and values |
|
|
426
|
+
| Missing / extra rows | `exclusive_A` / `exclusive_B` counts | `source_only` / `target_only`, with the rows |
|
|
427
|
+
| Pairing key | the table's key columns | `key_columns`, separate from the bisection columns, need not be unique |
|
|
428
|
+
| Duplicate keys | `AssertionError` when one side has two differing rows for a key | `duplicate_key` entries with all unpaired rows, and `duplicate_keys=True` |
|
|
429
|
+
| Early stop | none for stats | `limit` = number of distinct differing keys; queries are cancelled and `limit_reached=True` |
|
|
430
|
+
| Rows covered | `rows_A` / `rows_B` | `source_scanned` / `target_scanned`, plus `raw_rows` read from the stream |
|
|
431
|
+
| Export | dict | `as_dict()`, JSON-ready |
|
|
432
|
+
|
|
433
|
+
See [Keys and the per-key summary](#keys-and-the-per-key-summary) for how rows are paired. This brings back the
|
|
434
|
+
cell-level report of ibis-dv-tool's detailed mode (key, column, source value, target value) without pulling whole
|
|
435
|
+
tables into memory: only the rows of mismatching segments are ever downloaded.
|
|
436
|
+
|
|
289
437
|
## Adding a database
|
|
290
438
|
|
|
291
|
-
1. A YAML dialect in `src/
|
|
439
|
+
1. A YAML dialect in `src/databases/dialects/<db>.yaml` that `extends: _base.yaml` and declares its SQL
|
|
292
440
|
fragments, type mapping and normalization templates. `_base.yaml` documents every key; unknown keys, type
|
|
293
441
|
classes and template placeholders are rejected when the dialect loads.
|
|
294
|
-
2. A small driver class in `src/
|
|
295
|
-
`DATABASE_BY_SCHEME` (`src/
|
|
442
|
+
2. A small driver class in `src/databases/<db>.py` (driver import and connection creation), registered in
|
|
443
|
+
`DATABASE_BY_SCHEME` (`src/databases/_connect.py`).
|
|
296
444
|
|
|
297
445
|
The new dialect must render every value byte-identically to its counterpart. See
|
|
298
446
|
[ARCHITECTURE.md](https://github.com/sarath-mec/diffdb-core/blob/main/ARCHITECTURE.md#4-declarative-yaml-dialect-framework).
|
|
@@ -18,6 +18,10 @@ engines and a `FULL OUTER JOIN` isn't possible.
|
|
|
18
18
|
- **Per-key summary**: changed rows with their differing columns, source-only and target-only rows, duplicate keys.
|
|
19
19
|
- **Telemetry**: every query, row count, checksum and duration can be captured for auditing.
|
|
20
20
|
|
|
21
|
+
diffdb-core is the third iteration of this tooling, after `simple-dv-tool` and `ibis-dv-tool`, and is built on
|
|
22
|
+
reladiff's algorithm. See [Background](#background-from-aggregate-fingerprints-to-checksum-bisection) for how it got
|
|
23
|
+
here and [How diffdb-core differs from reladiff](#how-diffdb-core-differs-from-reladiff) for what changed.
|
|
24
|
+
|
|
21
25
|
## Install
|
|
22
26
|
|
|
23
27
|
```bash
|
|
@@ -237,13 +241,157 @@ entries and `duplicate_keys` as the signal to look at the rows yourself.
|
|
|
237
241
|
- **Character sets**: values both drivers decode to the same Unicode text compare equal at row level, but a
|
|
238
242
|
checksum mismatch still costs a download of that segment.
|
|
239
243
|
|
|
244
|
+
## Background: from aggregate fingerprints to checksum bisection
|
|
245
|
+
|
|
246
|
+
diffdb-core is the third iteration of my migration data-validation tooling. The first two are archived and kept
|
|
247
|
+
for reference.
|
|
248
|
+
|
|
249
|
+
### 1. simple-dv-tool: hand-written aggregate SQL
|
|
250
|
+
|
|
251
|
+
[simple-dv-tool](https://github.com/sarath-mec/simple-dv-tool) validated Hive / MySQL → BigQuery migrations from a
|
|
252
|
+
notebook. It split the source into N batches by ranking on a split key, sent each batch's source key range to
|
|
253
|
+
BigQuery as a temp table, and compared **aggregate fingerprints** per batch: `COUNT(1)`, and per column
|
|
254
|
+
`COUNT(DISTINCT c)`, null count, `MIN(c)` and `MAX(c)`. The results were compared in DuckDB, and a BigQuery UDF
|
|
255
|
+
decided what counted as a match (rounding, timezone shifts, NULL-like strings).
|
|
256
|
+
|
|
257
|
+
- Every query was an f-string, with engine-specific code (Hive `DESCRIBE` parsing, MySQL collation, BigQuery scripting).
|
|
258
|
+
- The target could only be BigQuery, and each table was configured by hand.
|
|
259
|
+
|
|
260
|
+
### 2. ibis-dv-tool: the same idea on Ibis, database-wide
|
|
261
|
+
|
|
262
|
+
[ibis-dv-tool](https://github.com/sarath-mec/ibis-dv-tool) kept the fingerprint idea but wrote every query as an
|
|
263
|
+
[Ibis](https://ibis-project.org/) expression, compiled to each backend's SQL, so any Ibis-supported pair worked. It
|
|
264
|
+
added a database-wide mapping phase (a metadata view in each database, fuzzy table/column matching, a reviewable
|
|
265
|
+
YAML config per table) and a **detailed** mode that pulled small tables into pandas and diffed them cell by cell on
|
|
266
|
+
the primary key.
|
|
267
|
+
|
|
268
|
+
Both tools hit the same limits:
|
|
269
|
+
|
|
270
|
+
- **Fingerprints miss changes.** `COUNT(DISTINCT)`, `MIN` and `MAX` stay the same when a value changes in the
|
|
271
|
+
middle of a range, or when two rows swap values. They show *which batch and column* look wrong, never *which rows*.
|
|
272
|
+
- **Row-level comparison doesn't scale.** Detailed mode had to pull the whole table (or batch) into pandas.
|
|
273
|
+
- **Batches are fixed up front.** Narrowing a mismatch inside a large batch was manual drill-down SQL.
|
|
274
|
+
- **Matching rules ran after the fact.** Values were compared in whatever text each engine returned, then a UDF or
|
|
275
|
+
pandas dtype alignment tried to make them agree.
|
|
276
|
+
|
|
277
|
+
### 3. reladiff: what checksum bisection fixed
|
|
278
|
+
|
|
279
|
+
[reladiff](https://github.com/erezsh/reladiff) (a maintained fork of data-diff) solves those problems with
|
|
280
|
+
**recursive checksum bisection**, which is the algorithm diffdb-core uses:
|
|
281
|
+
|
|
282
|
+
| | simple-dv-tool / ibis-dv-tool | reladiff (and diffdb-core) |
|
|
283
|
+
| :--- | :--- | :--- |
|
|
284
|
+
| What is compared | `COUNT`, `COUNT(DISTINCT)`, `MIN`, `MAX` per column | `count(*)` + sum of an MD5 of **every value of every row** |
|
|
285
|
+
| Detects | changes that move a count, min or max | any changed, missing or extra row |
|
|
286
|
+
| Result | batch + column that differ, plus drill-down SQL | the exact differing rows |
|
|
287
|
+
| Narrowing down | fixed batches; manual drill-down | ranges that differ are split again, automatically, until small |
|
|
288
|
+
| Rows moved | none (summary) or the whole table (detailed) | only the rows of small, mismatching ranges |
|
|
289
|
+
| Cross-engine values | compared as returned, then matched by tolerance rules | normalized to the same text **in SQL** before hashing, with precision lowered to the common minimum |
|
|
290
|
+
|
|
291
|
+
What reladiff doesn't do, and the earlier tools did: database-wide table and column mapping, fuzzy name matching
|
|
292
|
+
and tolerance rules. diffdb-core doesn't do those either; it expects the caller to supply the pairing (see below).
|
|
293
|
+
|
|
294
|
+
## How diffdb-core differs from reladiff
|
|
295
|
+
|
|
296
|
+
diffdb-core adapts reladiff's bisection engine (`HashDiffer`, segments, key-space geometry, threaded yielder; see
|
|
297
|
+
[License](#license)) and changes how tables are described, how dialects are defined and how results are reported.
|
|
298
|
+
|
|
299
|
+
| | reladiff | diffdb-core |
|
|
300
|
+
| :--- | :--- | :--- |
|
|
301
|
+
| Column definitions | column **names** (`key_columns`, `extra_columns`); types read from the database | `columns={name: {"datatype", "transform_rule"}}` per side; nothing read from the database |
|
|
302
|
+
| Metadata queries | reads `information_schema` and samples rows to refine types | none (except Oracle `NLS_CHARACTERSET`, once per connection) |
|
|
303
|
+
| Compare an SQL expression | not supported (create a view) | `transform_rule` on any column, bisection columns included |
|
|
304
|
+
| LOB / binary / unknown types | compared anyway, with a "may result in false positives" warning | rejected up front; reduce them with a `transform_rule` |
|
|
305
|
+
| Dialects | Python classes and mixins from [sqeleton](https://github.com/erezsh/sqeleton), SQL built by its query builder | one validated YAML file per database; SQL built as plain strings in `core/sql.py` |
|
|
306
|
+
| Result | `+`/`-` row stream; `get_stats_dict()` counts | the same stream, plus `summarize()`: per-key, per-column results |
|
|
307
|
+
| Duplicate keys in stats | a key with two differing rows on the same side fails an `assert` | reported as `duplicate_key`, with `duplicate_keys=True` |
|
|
308
|
+
| Limit | `--limit` on rows (CLI; can't be combined with `--stats`) | `summarize(limit=N)` on distinct differing keys, cancels outstanding queries |
|
|
309
|
+
| Algorithms | `hashdiff` (cross-database) and `joindiff` (same database) | `hashdiff` only |
|
|
310
|
+
| Interface | CLI, TOML run config, Python API | Python API only |
|
|
311
|
+
| Incremental runs | `update_column` with `min_update` / `max_update` | a `where` filter |
|
|
312
|
+
|
|
313
|
+
### `transform_rule`: comparing expressions, not just columns
|
|
314
|
+
|
|
315
|
+
In reladiff a compared column is a name that must exist in the table's schema. To compare `TRIM(name)`, a CLOB's
|
|
316
|
+
length, or a string key under binary collation, you have to create a view on each side first.
|
|
317
|
+
|
|
318
|
+
In diffdb-core each column entry can carry a `transform_rule`, an SQL expression used instead of the column, and a
|
|
319
|
+
`datatype` that describes the expression's result:
|
|
320
|
+
|
|
321
|
+
```python
|
|
322
|
+
"NOTES": {"datatype": "NUMBER(10,0)", "transform_rule": 'DBMS_LOB.GETLENGTH("NOTES")'}, # Oracle CLOB
|
|
323
|
+
"notes": {"datatype": "integer", "transform_rule": 'LENGTH("notes")'}, # PostgreSQL text
|
|
324
|
+
"line_code": {"datatype": "varchar(20)", "transform_rule": '"line_code" COLLATE "C"'}, # byte-order bisection
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
- The rule is wrapped in parentheses and used **everywhere** the column appears: in the checksum, the key-range
|
|
328
|
+
`MIN`/`MAX`, the downloaded rows, and the key-range `WHERE` clauses when it's a bisection column (see the
|
|
329
|
+
PostgreSQL query in [How it works](#how-it-works)).
|
|
330
|
+
- Each side has its own rule, so the two sides can use different SQL to reach the same value.
|
|
331
|
+
- The declared `datatype` drives normalization and precision reconciliation, so the result is hashed as the type
|
|
332
|
+
you declared, not the column's original type.
|
|
333
|
+
- This is how unsupported types are handled: LOB and binary columns are rejected unless a rule reduces them to a
|
|
334
|
+
number, string or timestamp. reladiff instead hashes them with a warning, which can report false differences.
|
|
335
|
+
|
|
336
|
+
This is the same idea as ibis-dv-tool's editable `src_matched_cols` (where a source "column" could be a cast), now
|
|
337
|
+
applied inside the hash, on both sides, with a declared type.
|
|
338
|
+
|
|
339
|
+
### YAML dialect declarations
|
|
340
|
+
|
|
341
|
+
reladiff gets its dialects from sqeleton: each database is a Python class composed from mixins
|
|
342
|
+
(`oracle.Dialect, oracle.Mixin_MD5, oracle.Mixin_NormalizeValue, …`), with type parsing and value normalization
|
|
343
|
+
spread across Python methods. Checking that two engines render a timestamp identically means reading code in
|
|
344
|
+
several classes.
|
|
345
|
+
|
|
346
|
+
diffdb-core declares each dialect in one YAML file (`src/databases/dialects/<db>.yaml`):
|
|
347
|
+
|
|
348
|
+
- `extends:` another dialect (usually `_base.yaml`, which holds portable ANSI defaults and documents every key).
|
|
349
|
+
- `syntax:` fragments (quoting, concatenation, `md5_as_int`, …), `type_classes` / `type_regexps` (native type name
|
|
350
|
+
→ diffdb type, e.g. `NUMBER` → `Decimal`), and `normalization:` templates (how each type becomes text before
|
|
351
|
+
hashing).
|
|
352
|
+
- **Validated when it loads**: unknown keys, unknown type classes and unknown template placeholders raise
|
|
353
|
+
`DialectConfigError`, rather than producing wrong SQL at run time.
|
|
354
|
+
- Engine-specific behaviour lives in YAML, not in `if name == ...` branches. The only Python per database is a small
|
|
355
|
+
driver class (import and connection).
|
|
356
|
+
- Every dialect's generated SQL is pinned by golden snapshots (`tests/golden/`), so a YAML change that alters a
|
|
357
|
+
query shows up as a test diff.
|
|
358
|
+
|
|
359
|
+
Columns are also declared, not discovered: you pass the native `datatype` of each column, and the dialect's
|
|
360
|
+
`type_classes` turn it into a diffdb type. That replaces reladiff's `information_schema` query and row sampling.
|
|
361
|
+
|
|
362
|
+
(This YAML is a dialect definition. It is different from reladiff's TOML file, which describes runs, and from
|
|
363
|
+
ibis-dv-tool's YAML, which described the table mapping. diffdb-core has no run-config file.)
|
|
364
|
+
|
|
365
|
+
### Summarization
|
|
366
|
+
|
|
367
|
+
reladiff's result is a stream of `('-', row)` and `('+', row)`. `get_stats_dict()` groups that stream by key and
|
|
368
|
+
returns counts: `rows_A`, `rows_B`, `exclusive_A`, `exclusive_B`, `updated`, `unchanged`, `total`. It doesn't say
|
|
369
|
+
*which* columns of an updated row changed, and it assumes each key has at most one differing row per side.
|
|
370
|
+
|
|
371
|
+
diffdb-core keeps that stream and `get_stats_dict()`, and adds `summarize(limit=N)`, which returns a `DiffSummary`:
|
|
372
|
+
|
|
373
|
+
| | reladiff `get_stats_dict()` | diffdb-core `summarize()` |
|
|
374
|
+
| :--- | :--- | :--- |
|
|
375
|
+
| Granularity | counts only | one `KeyDiff` per differing key |
|
|
376
|
+
| Changed rows | counted as `updated` | `changed`, with a `ColumnDiff` per differing column: source and target column names and values |
|
|
377
|
+
| Missing / extra rows | `exclusive_A` / `exclusive_B` counts | `source_only` / `target_only`, with the rows |
|
|
378
|
+
| Pairing key | the table's key columns | `key_columns`, separate from the bisection columns, need not be unique |
|
|
379
|
+
| Duplicate keys | `AssertionError` when one side has two differing rows for a key | `duplicate_key` entries with all unpaired rows, and `duplicate_keys=True` |
|
|
380
|
+
| Early stop | none for stats | `limit` = number of distinct differing keys; queries are cancelled and `limit_reached=True` |
|
|
381
|
+
| Rows covered | `rows_A` / `rows_B` | `source_scanned` / `target_scanned`, plus `raw_rows` read from the stream |
|
|
382
|
+
| Export | dict | `as_dict()`, JSON-ready |
|
|
383
|
+
|
|
384
|
+
See [Keys and the per-key summary](#keys-and-the-per-key-summary) for how rows are paired. This brings back the
|
|
385
|
+
cell-level report of ibis-dv-tool's detailed mode (key, column, source value, target value) without pulling whole
|
|
386
|
+
tables into memory: only the rows of mismatching segments are ever downloaded.
|
|
387
|
+
|
|
240
388
|
## Adding a database
|
|
241
389
|
|
|
242
|
-
1. A YAML dialect in `src/
|
|
390
|
+
1. A YAML dialect in `src/databases/dialects/<db>.yaml` that `extends: _base.yaml` and declares its SQL
|
|
243
391
|
fragments, type mapping and normalization templates. `_base.yaml` documents every key; unknown keys, type
|
|
244
392
|
classes and template placeholders are rejected when the dialect loads.
|
|
245
|
-
2. A small driver class in `src/
|
|
246
|
-
`DATABASE_BY_SCHEME` (`src/
|
|
393
|
+
2. A small driver class in `src/databases/<db>.py` (driver import and connection creation), registered in
|
|
394
|
+
`DATABASE_BY_SCHEME` (`src/databases/_connect.py`).
|
|
247
395
|
|
|
248
396
|
The new dialect must render every value byte-identically to its counterpart. See
|
|
249
397
|
[ARCHITECTURE.md](https://github.com/sarath-mec/diffdb-core/blob/main/ARCHITECTURE.md#4-declarative-yaml-dialect-framework).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: diffdb-core
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Cross-database table diffing by recursive checksum bisection, with declarative YAML SQL dialects
|
|
5
5
|
Author: Sarath Mohan
|
|
6
6
|
License: MIT
|
|
@@ -67,6 +67,10 @@ engines and a `FULL OUTER JOIN` isn't possible.
|
|
|
67
67
|
- **Per-key summary**: changed rows with their differing columns, source-only and target-only rows, duplicate keys.
|
|
68
68
|
- **Telemetry**: every query, row count, checksum and duration can be captured for auditing.
|
|
69
69
|
|
|
70
|
+
diffdb-core is the third iteration of this tooling, after `simple-dv-tool` and `ibis-dv-tool`, and is built on
|
|
71
|
+
reladiff's algorithm. See [Background](#background-from-aggregate-fingerprints-to-checksum-bisection) for how it got
|
|
72
|
+
here and [How diffdb-core differs from reladiff](#how-diffdb-core-differs-from-reladiff) for what changed.
|
|
73
|
+
|
|
70
74
|
## Install
|
|
71
75
|
|
|
72
76
|
```bash
|
|
@@ -286,13 +290,157 @@ entries and `duplicate_keys` as the signal to look at the rows yourself.
|
|
|
286
290
|
- **Character sets**: values both drivers decode to the same Unicode text compare equal at row level, but a
|
|
287
291
|
checksum mismatch still costs a download of that segment.
|
|
288
292
|
|
|
293
|
+
## Background: from aggregate fingerprints to checksum bisection
|
|
294
|
+
|
|
295
|
+
diffdb-core is the third iteration of my migration data-validation tooling. The first two are archived and kept
|
|
296
|
+
for reference.
|
|
297
|
+
|
|
298
|
+
### 1. simple-dv-tool: hand-written aggregate SQL
|
|
299
|
+
|
|
300
|
+
[simple-dv-tool](https://github.com/sarath-mec/simple-dv-tool) validated Hive / MySQL → BigQuery migrations from a
|
|
301
|
+
notebook. It split the source into N batches by ranking on a split key, sent each batch's source key range to
|
|
302
|
+
BigQuery as a temp table, and compared **aggregate fingerprints** per batch: `COUNT(1)`, and per column
|
|
303
|
+
`COUNT(DISTINCT c)`, null count, `MIN(c)` and `MAX(c)`. The results were compared in DuckDB, and a BigQuery UDF
|
|
304
|
+
decided what counted as a match (rounding, timezone shifts, NULL-like strings).
|
|
305
|
+
|
|
306
|
+
- Every query was an f-string, with engine-specific code (Hive `DESCRIBE` parsing, MySQL collation, BigQuery scripting).
|
|
307
|
+
- The target could only be BigQuery, and each table was configured by hand.
|
|
308
|
+
|
|
309
|
+
### 2. ibis-dv-tool: the same idea on Ibis, database-wide
|
|
310
|
+
|
|
311
|
+
[ibis-dv-tool](https://github.com/sarath-mec/ibis-dv-tool) kept the fingerprint idea but wrote every query as an
|
|
312
|
+
[Ibis](https://ibis-project.org/) expression, compiled to each backend's SQL, so any Ibis-supported pair worked. It
|
|
313
|
+
added a database-wide mapping phase (a metadata view in each database, fuzzy table/column matching, a reviewable
|
|
314
|
+
YAML config per table) and a **detailed** mode that pulled small tables into pandas and diffed them cell by cell on
|
|
315
|
+
the primary key.
|
|
316
|
+
|
|
317
|
+
Both tools hit the same limits:
|
|
318
|
+
|
|
319
|
+
- **Fingerprints miss changes.** `COUNT(DISTINCT)`, `MIN` and `MAX` stay the same when a value changes in the
|
|
320
|
+
middle of a range, or when two rows swap values. They show *which batch and column* look wrong, never *which rows*.
|
|
321
|
+
- **Row-level comparison doesn't scale.** Detailed mode had to pull the whole table (or batch) into pandas.
|
|
322
|
+
- **Batches are fixed up front.** Narrowing a mismatch inside a large batch was manual drill-down SQL.
|
|
323
|
+
- **Matching rules ran after the fact.** Values were compared in whatever text each engine returned, then a UDF or
|
|
324
|
+
pandas dtype alignment tried to make them agree.
|
|
325
|
+
|
|
326
|
+
### 3. reladiff: what checksum bisection fixed
|
|
327
|
+
|
|
328
|
+
[reladiff](https://github.com/erezsh/reladiff) (a maintained fork of data-diff) solves those problems with
|
|
329
|
+
**recursive checksum bisection**, which is the algorithm diffdb-core uses:
|
|
330
|
+
|
|
331
|
+
| | simple-dv-tool / ibis-dv-tool | reladiff (and diffdb-core) |
|
|
332
|
+
| :--- | :--- | :--- |
|
|
333
|
+
| What is compared | `COUNT`, `COUNT(DISTINCT)`, `MIN`, `MAX` per column | `count(*)` + sum of an MD5 of **every value of every row** |
|
|
334
|
+
| Detects | changes that move a count, min or max | any changed, missing or extra row |
|
|
335
|
+
| Result | batch + column that differ, plus drill-down SQL | the exact differing rows |
|
|
336
|
+
| Narrowing down | fixed batches; manual drill-down | ranges that differ are split again, automatically, until small |
|
|
337
|
+
| Rows moved | none (summary) or the whole table (detailed) | only the rows of small, mismatching ranges |
|
|
338
|
+
| Cross-engine values | compared as returned, then matched by tolerance rules | normalized to the same text **in SQL** before hashing, with precision lowered to the common minimum |
|
|
339
|
+
|
|
340
|
+
What reladiff doesn't do, and the earlier tools did: database-wide table and column mapping, fuzzy name matching
|
|
341
|
+
and tolerance rules. diffdb-core doesn't do those either; it expects the caller to supply the pairing (see below).
|
|
342
|
+
|
|
343
|
+
## How diffdb-core differs from reladiff
|
|
344
|
+
|
|
345
|
+
diffdb-core adapts reladiff's bisection engine (`HashDiffer`, segments, key-space geometry, threaded yielder; see
|
|
346
|
+
[License](#license)) and changes how tables are described, how dialects are defined and how results are reported.
|
|
347
|
+
|
|
348
|
+
| | reladiff | diffdb-core |
|
|
349
|
+
| :--- | :--- | :--- |
|
|
350
|
+
| Column definitions | column **names** (`key_columns`, `extra_columns`); types read from the database | `columns={name: {"datatype", "transform_rule"}}` per side; nothing read from the database |
|
|
351
|
+
| Metadata queries | reads `information_schema` and samples rows to refine types | none (except Oracle `NLS_CHARACTERSET`, once per connection) |
|
|
352
|
+
| Compare an SQL expression | not supported (create a view) | `transform_rule` on any column, bisection columns included |
|
|
353
|
+
| LOB / binary / unknown types | compared anyway, with a "may result in false positives" warning | rejected up front; reduce them with a `transform_rule` |
|
|
354
|
+
| Dialects | Python classes and mixins from [sqeleton](https://github.com/erezsh/sqeleton), SQL built by its query builder | one validated YAML file per database; SQL built as plain strings in `core/sql.py` |
|
|
355
|
+
| Result | `+`/`-` row stream; `get_stats_dict()` counts | the same stream, plus `summarize()`: per-key, per-column results |
|
|
356
|
+
| Duplicate keys in stats | a key with two differing rows on the same side fails an `assert` | reported as `duplicate_key`, with `duplicate_keys=True` |
|
|
357
|
+
| Limit | `--limit` on rows (CLI; can't be combined with `--stats`) | `summarize(limit=N)` on distinct differing keys, cancels outstanding queries |
|
|
358
|
+
| Algorithms | `hashdiff` (cross-database) and `joindiff` (same database) | `hashdiff` only |
|
|
359
|
+
| Interface | CLI, TOML run config, Python API | Python API only |
|
|
360
|
+
| Incremental runs | `update_column` with `min_update` / `max_update` | a `where` filter |
|
|
361
|
+
|
|
362
|
+
### `transform_rule`: comparing expressions, not just columns
|
|
363
|
+
|
|
364
|
+
In reladiff a compared column is a name that must exist in the table's schema. To compare `TRIM(name)`, a CLOB's
|
|
365
|
+
length, or a string key under binary collation, you have to create a view on each side first.
|
|
366
|
+
|
|
367
|
+
In diffdb-core each column entry can carry a `transform_rule`, an SQL expression used instead of the column, and a
|
|
368
|
+
`datatype` that describes the expression's result:
|
|
369
|
+
|
|
370
|
+
```python
|
|
371
|
+
"NOTES": {"datatype": "NUMBER(10,0)", "transform_rule": 'DBMS_LOB.GETLENGTH("NOTES")'}, # Oracle CLOB
|
|
372
|
+
"notes": {"datatype": "integer", "transform_rule": 'LENGTH("notes")'}, # PostgreSQL text
|
|
373
|
+
"line_code": {"datatype": "varchar(20)", "transform_rule": '"line_code" COLLATE "C"'}, # byte-order bisection
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
- The rule is wrapped in parentheses and used **everywhere** the column appears: in the checksum, the key-range
|
|
377
|
+
`MIN`/`MAX`, the downloaded rows, and the key-range `WHERE` clauses when it's a bisection column (see the
|
|
378
|
+
PostgreSQL query in [How it works](#how-it-works)).
|
|
379
|
+
- Each side has its own rule, so the two sides can use different SQL to reach the same value.
|
|
380
|
+
- The declared `datatype` drives normalization and precision reconciliation, so the result is hashed as the type
|
|
381
|
+
you declared, not the column's original type.
|
|
382
|
+
- This is how unsupported types are handled: LOB and binary columns are rejected unless a rule reduces them to a
|
|
383
|
+
number, string or timestamp. reladiff instead hashes them with a warning, which can report false differences.
|
|
384
|
+
|
|
385
|
+
This is the same idea as ibis-dv-tool's editable `src_matched_cols` (where a source "column" could be a cast), now
|
|
386
|
+
applied inside the hash, on both sides, with a declared type.
|
|
387
|
+
|
|
388
|
+
### YAML dialect declarations
|
|
389
|
+
|
|
390
|
+
reladiff gets its dialects from sqeleton: each database is a Python class composed from mixins
|
|
391
|
+
(`oracle.Dialect, oracle.Mixin_MD5, oracle.Mixin_NormalizeValue, …`), with type parsing and value normalization
|
|
392
|
+
spread across Python methods. Checking that two engines render a timestamp identically means reading code in
|
|
393
|
+
several classes.
|
|
394
|
+
|
|
395
|
+
diffdb-core declares each dialect in one YAML file (`src/databases/dialects/<db>.yaml`):
|
|
396
|
+
|
|
397
|
+
- `extends:` another dialect (usually `_base.yaml`, which holds portable ANSI defaults and documents every key).
|
|
398
|
+
- `syntax:` fragments (quoting, concatenation, `md5_as_int`, …), `type_classes` / `type_regexps` (native type name
|
|
399
|
+
→ diffdb type, e.g. `NUMBER` → `Decimal`), and `normalization:` templates (how each type becomes text before
|
|
400
|
+
hashing).
|
|
401
|
+
- **Validated when it loads**: unknown keys, unknown type classes and unknown template placeholders raise
|
|
402
|
+
`DialectConfigError`, rather than producing wrong SQL at run time.
|
|
403
|
+
- Engine-specific behaviour lives in YAML, not in `if name == ...` branches. The only Python per database is a small
|
|
404
|
+
driver class (import and connection).
|
|
405
|
+
- Every dialect's generated SQL is pinned by golden snapshots (`tests/golden/`), so a YAML change that alters a
|
|
406
|
+
query shows up as a test diff.
|
|
407
|
+
|
|
408
|
+
Columns are also declared, not discovered: you pass the native `datatype` of each column, and the dialect's
|
|
409
|
+
`type_classes` turn it into a diffdb type. That replaces reladiff's `information_schema` query and row sampling.
|
|
410
|
+
|
|
411
|
+
(This YAML is a dialect definition. It is different from reladiff's TOML file, which describes runs, and from
|
|
412
|
+
ibis-dv-tool's YAML, which described the table mapping. diffdb-core has no run-config file.)
|
|
413
|
+
|
|
414
|
+
### Summarization
|
|
415
|
+
|
|
416
|
+
reladiff's result is a stream of `('-', row)` and `('+', row)`. `get_stats_dict()` groups that stream by key and
|
|
417
|
+
returns counts: `rows_A`, `rows_B`, `exclusive_A`, `exclusive_B`, `updated`, `unchanged`, `total`. It doesn't say
|
|
418
|
+
*which* columns of an updated row changed, and it assumes each key has at most one differing row per side.
|
|
419
|
+
|
|
420
|
+
diffdb-core keeps that stream and `get_stats_dict()`, and adds `summarize(limit=N)`, which returns a `DiffSummary`:
|
|
421
|
+
|
|
422
|
+
| | reladiff `get_stats_dict()` | diffdb-core `summarize()` |
|
|
423
|
+
| :--- | :--- | :--- |
|
|
424
|
+
| Granularity | counts only | one `KeyDiff` per differing key |
|
|
425
|
+
| Changed rows | counted as `updated` | `changed`, with a `ColumnDiff` per differing column: source and target column names and values |
|
|
426
|
+
| Missing / extra rows | `exclusive_A` / `exclusive_B` counts | `source_only` / `target_only`, with the rows |
|
|
427
|
+
| Pairing key | the table's key columns | `key_columns`, separate from the bisection columns, need not be unique |
|
|
428
|
+
| Duplicate keys | `AssertionError` when one side has two differing rows for a key | `duplicate_key` entries with all unpaired rows, and `duplicate_keys=True` |
|
|
429
|
+
| Early stop | none for stats | `limit` = number of distinct differing keys; queries are cancelled and `limit_reached=True` |
|
|
430
|
+
| Rows covered | `rows_A` / `rows_B` | `source_scanned` / `target_scanned`, plus `raw_rows` read from the stream |
|
|
431
|
+
| Export | dict | `as_dict()`, JSON-ready |
|
|
432
|
+
|
|
433
|
+
See [Keys and the per-key summary](#keys-and-the-per-key-summary) for how rows are paired. This brings back the
|
|
434
|
+
cell-level report of ibis-dv-tool's detailed mode (key, column, source value, target value) without pulling whole
|
|
435
|
+
tables into memory: only the rows of mismatching segments are ever downloaded.
|
|
436
|
+
|
|
289
437
|
## Adding a database
|
|
290
438
|
|
|
291
|
-
1. A YAML dialect in `src/
|
|
439
|
+
1. A YAML dialect in `src/databases/dialects/<db>.yaml` that `extends: _base.yaml` and declares its SQL
|
|
292
440
|
fragments, type mapping and normalization templates. `_base.yaml` documents every key; unknown keys, type
|
|
293
441
|
classes and template placeholders are rejected when the dialect loads.
|
|
294
|
-
2. A small driver class in `src/
|
|
295
|
-
`DATABASE_BY_SCHEME` (`src/
|
|
442
|
+
2. A small driver class in `src/databases/<db>.py` (driver import and connection creation), registered in
|
|
443
|
+
`DATABASE_BY_SCHEME` (`src/databases/_connect.py`).
|
|
296
444
|
|
|
297
445
|
The new dialect must render every value byte-identically to its counterpart. See
|
|
298
446
|
[ARCHITECTURE.md](https://github.com/sarath-mec/diffdb-core/blob/main/ARCHITECTURE.md#4-declarative-yaml-dialect-framework).
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
LICENSE.md
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
diffdb_core.egg-info/PKG-INFO
|
|
6
|
+
diffdb_core.egg-info/SOURCES.txt
|
|
7
|
+
diffdb_core.egg-info/dependency_links.txt
|
|
8
|
+
diffdb_core.egg-info/requires.txt
|
|
9
|
+
diffdb_core.egg-info/top_level.txt
|
|
10
|
+
src/__init__.py
|
|
11
|
+
src/types.py
|
|
12
|
+
src/utils.py
|
|
13
|
+
src/concurrency/__init__.py
|
|
14
|
+
src/concurrency/pool.py
|
|
15
|
+
src/concurrency/stream.py
|
|
16
|
+
src/core/__init__.py
|
|
17
|
+
src/core/differ.py
|
|
18
|
+
src/core/hash_differ.py
|
|
19
|
+
src/core/segment.py
|
|
20
|
+
src/core/sql.py
|
|
21
|
+
src/core/summary.py
|
|
22
|
+
src/databases/__init__.py
|
|
23
|
+
src/databases/_connect.py
|
|
24
|
+
src/databases/base.py
|
|
25
|
+
src/databases/bigquery.py
|
|
26
|
+
src/databases/clickhouse.py
|
|
27
|
+
src/databases/databricks.py
|
|
28
|
+
src/databases/duckdb.py
|
|
29
|
+
src/databases/mysql.py
|
|
30
|
+
src/databases/oracle.py
|
|
31
|
+
src/databases/postgresql.py
|
|
32
|
+
src/databases/presto.py
|
|
33
|
+
src/databases/redshift.py
|
|
34
|
+
src/databases/snowflake.py
|
|
35
|
+
src/databases/trino.py
|
|
36
|
+
src/databases/vertica.py
|
|
37
|
+
src/databases/yaml_dialect.py
|
|
38
|
+
src/databases/dialects/_base.yaml
|
|
39
|
+
src/databases/dialects/bigquery.yaml
|
|
40
|
+
src/databases/dialects/clickhouse.yaml
|
|
41
|
+
src/databases/dialects/databricks.yaml
|
|
42
|
+
src/databases/dialects/duckdb.yaml
|
|
43
|
+
src/databases/dialects/mysql.yaml
|
|
44
|
+
src/databases/dialects/oracle.yaml
|
|
45
|
+
src/databases/dialects/postgresql.yaml
|
|
46
|
+
src/databases/dialects/presto.yaml
|
|
47
|
+
src/databases/dialects/redshift.yaml
|
|
48
|
+
src/databases/dialects/snowflake.yaml
|
|
49
|
+
src/databases/dialects/trino.yaml
|
|
50
|
+
src/databases/dialects/vertica.yaml
|
|
51
|
+
src/geometry/__init__.py
|
|
52
|
+
src/geometry/arithmetic.py
|
|
53
|
+
src/geometry/bisection.py
|
|
54
|
+
src/geometry/vector.py
|
|
55
|
+
src/telemetry/__init__.py
|
|
56
|
+
src/telemetry/info_tree.py
|
|
57
|
+
src/telemetry/query_tracker.py
|
|
58
|
+
tests/test_connect.py
|
|
59
|
+
tests/test_dialects.py
|
|
60
|
+
tests/test_diffdb_core.py
|
|
61
|
+
tests/test_e2e_duckdb.py
|
|
62
|
+
tests/test_query_snapshot.py
|
|
63
|
+
tests/golden/dialect_sql.json
|
|
64
|
+
tests/golden/query_sql.json
|
|
@@ -54,8 +54,17 @@ dev = [
|
|
|
54
54
|
[tool.setuptools.dynamic]
|
|
55
55
|
version = { attr = "diffdb.__version__" }
|
|
56
56
|
|
|
57
|
-
[tool.setuptools
|
|
58
|
-
|
|
57
|
+
[tool.setuptools]
|
|
58
|
+
# The package's source lives directly in src/ and installs as `diffdb`.
|
|
59
|
+
package-dir = { "diffdb" = "src" }
|
|
60
|
+
packages = [
|
|
61
|
+
"diffdb",
|
|
62
|
+
"diffdb.concurrency",
|
|
63
|
+
"diffdb.core",
|
|
64
|
+
"diffdb.databases",
|
|
65
|
+
"diffdb.geometry",
|
|
66
|
+
"diffdb.telemetry",
|
|
67
|
+
]
|
|
59
68
|
|
|
60
69
|
[tool.setuptools.package-data]
|
|
61
70
|
diffdb = ["databases/dialects/*.yaml"]
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
LICENSE.md
|
|
2
|
-
MANIFEST.in
|
|
3
|
-
README.md
|
|
4
|
-
pyproject.toml
|
|
5
|
-
src/diffdb/__init__.py
|
|
6
|
-
src/diffdb/types.py
|
|
7
|
-
src/diffdb/utils.py
|
|
8
|
-
src/diffdb/concurrency/__init__.py
|
|
9
|
-
src/diffdb/concurrency/pool.py
|
|
10
|
-
src/diffdb/concurrency/stream.py
|
|
11
|
-
src/diffdb/core/__init__.py
|
|
12
|
-
src/diffdb/core/differ.py
|
|
13
|
-
src/diffdb/core/hash_differ.py
|
|
14
|
-
src/diffdb/core/segment.py
|
|
15
|
-
src/diffdb/core/sql.py
|
|
16
|
-
src/diffdb/core/summary.py
|
|
17
|
-
src/diffdb/databases/__init__.py
|
|
18
|
-
src/diffdb/databases/_connect.py
|
|
19
|
-
src/diffdb/databases/base.py
|
|
20
|
-
src/diffdb/databases/bigquery.py
|
|
21
|
-
src/diffdb/databases/clickhouse.py
|
|
22
|
-
src/diffdb/databases/databricks.py
|
|
23
|
-
src/diffdb/databases/duckdb.py
|
|
24
|
-
src/diffdb/databases/mysql.py
|
|
25
|
-
src/diffdb/databases/oracle.py
|
|
26
|
-
src/diffdb/databases/postgresql.py
|
|
27
|
-
src/diffdb/databases/presto.py
|
|
28
|
-
src/diffdb/databases/redshift.py
|
|
29
|
-
src/diffdb/databases/snowflake.py
|
|
30
|
-
src/diffdb/databases/trino.py
|
|
31
|
-
src/diffdb/databases/vertica.py
|
|
32
|
-
src/diffdb/databases/yaml_dialect.py
|
|
33
|
-
src/diffdb/databases/dialects/_base.yaml
|
|
34
|
-
src/diffdb/databases/dialects/bigquery.yaml
|
|
35
|
-
src/diffdb/databases/dialects/clickhouse.yaml
|
|
36
|
-
src/diffdb/databases/dialects/databricks.yaml
|
|
37
|
-
src/diffdb/databases/dialects/duckdb.yaml
|
|
38
|
-
src/diffdb/databases/dialects/mysql.yaml
|
|
39
|
-
src/diffdb/databases/dialects/oracle.yaml
|
|
40
|
-
src/diffdb/databases/dialects/postgresql.yaml
|
|
41
|
-
src/diffdb/databases/dialects/presto.yaml
|
|
42
|
-
src/diffdb/databases/dialects/redshift.yaml
|
|
43
|
-
src/diffdb/databases/dialects/snowflake.yaml
|
|
44
|
-
src/diffdb/databases/dialects/trino.yaml
|
|
45
|
-
src/diffdb/databases/dialects/vertica.yaml
|
|
46
|
-
src/diffdb/geometry/__init__.py
|
|
47
|
-
src/diffdb/geometry/arithmetic.py
|
|
48
|
-
src/diffdb/geometry/bisection.py
|
|
49
|
-
src/diffdb/geometry/vector.py
|
|
50
|
-
src/diffdb/telemetry/__init__.py
|
|
51
|
-
src/diffdb/telemetry/info_tree.py
|
|
52
|
-
src/diffdb/telemetry/query_tracker.py
|
|
53
|
-
src/diffdb_core.egg-info/PKG-INFO
|
|
54
|
-
src/diffdb_core.egg-info/SOURCES.txt
|
|
55
|
-
src/diffdb_core.egg-info/dependency_links.txt
|
|
56
|
-
src/diffdb_core.egg-info/requires.txt
|
|
57
|
-
src/diffdb_core.egg-info/top_level.txt
|
|
58
|
-
tests/test_connect.py
|
|
59
|
-
tests/test_dialects.py
|
|
60
|
-
tests/test_diffdb_core.py
|
|
61
|
-
tests/test_e2e_duckdb.py
|
|
62
|
-
tests/test_query_snapshot.py
|
|
63
|
-
tests/golden/dialect_sql.json
|
|
64
|
-
tests/golden/query_sql.json
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|