Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit cf272f3

Browse files
authored
Merge branch 'master' into pass-inline-key-to-snowflake
2 parents be1d947 + b3d4223 commit cf272f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+33382
-6167
lines changed

.github/workflows/formatter.yml

+9-10
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ on:
77

88
jobs:
99
linter_name:
10-
name: runner / black
10+
name: runner / ruff
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
14-
- name: Check files using the black formatter
15-
uses: rickstaa/action-black@v1
16-
id: black_formatter
13+
- uses: actions/checkout@v3
14+
- name: Check files using the ruff formatter
15+
uses: chartboost/ruff-action@v1
16+
id: ruff_formatter
1717
with:
18-
black_args: ". -l 120"
19-
- name: Annotate diff changes using reviewdog
20-
if: steps.black_formatter.outputs.is_formatted == 'true'
21-
uses: reviewdog/action-suggester@v1
18+
args: format
19+
- name: Auto commit ruff formatting
20+
uses: stefanzweifel/git-auto-commit-action@v5
2221
with:
23-
tool_name: blackfmt
22+
commit_message: 'style fixes by ruff'

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,6 @@ benchmark_*.png
147147

148148
# VSCode
149149
.vscode
150+
151+
# History
152+
.history

.pre-commit-config.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
default_language_version:
2+
python: python3
3+
4+
repos:
5+
# Run the Ruff linter.
6+
- repo: https://github.com/astral-sh/ruff-pre-commit
7+
# Ruff version.
8+
rev: v0.1.2
9+
hooks:
10+
# Run the Ruff formatter.
11+
- id: ruff-format

CONTRIBUTING.md

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Once inside, you can install the dependencies.
5454

5555
- Option 2: Run `pip install -e .` to install them, and data-diff, in the global context.
5656

57+
- Run `pre-commit install` to automatically format your code before committing.
58+
5759
At the bare minimum, you need MySQL to run the tests.
5860

5961
You can create a local MySQL instance using `docker-compose up mysql`. The URI for it will be `mysql://mysql:Password1@localhost/mysql`. If you're using a different server, make sure to update `TEST_MYSQL_CONN_STRING` in `tests/common.py`. For your convenience, we recommend creating `tests/local_settings.py`, and to override the value there.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ More information about the algorithm and performance considerations can be found
7272
# Get started
7373

7474
## Validating dbt model changes between dev and prod
75-
⚡ Looking to use `data-diff` in dbt development? Head over to [our `data-diff` + `dbt` documentation](https://docs.datafold.com/development_testing/open_source/) to get started!
75+
⚡ Looking to use `data-diff` in dbt development? Head over to [our `data-diff` + `dbt` documentation](https://docs.datafold.com/development_testing/how_it_works) to get started!
7676

7777
## Compare data tables between databases
7878
🔀 To compare data between databases, install `data-diff` with specific database adapters, e.g.:

data_diff/__main__.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,20 @@ def write_usage(self, prog: str, args: str = "", prefix: Optional[str] = None) -
267267
metavar="PATH",
268268
help="Specify manifest to utilize for 'prod' comparison paths instead of using configuration.",
269269
)
270+
@click.option(
271+
"-pd",
272+
"--prod-database",
273+
"prod_database",
274+
default=None,
275+
help="Override the dbt production database configuration within dbt_project.yml",
276+
)
277+
@click.option(
278+
"-ps",
279+
"--prod-schema",
280+
"prod_schema",
281+
default=None,
282+
help="Override the dbt production schema configuration within dbt_project.yml",
283+
)
270284
def main(conf, run, **kw):
271285
log_handlers = _get_log_handlers(kw["dbt"])
272286
if kw["table2"] is None and kw["database2"]:
@@ -323,6 +337,8 @@ def main(conf, run, **kw):
323337
where_flag=kw["where"],
324338
stats_flag=kw["stats"],
325339
columns_flag=kw["columns"],
340+
production_database_flag=kw["prod_database"],
341+
production_schema_flag=kw["prod_schema"],
326342
)
327343
else:
328344
return _data_diff(
@@ -366,6 +382,8 @@ def _data_diff(
366382
cloud,
367383
dbt_profiles_dir,
368384
dbt_project_dir,
385+
prod_database,
386+
prod_schema,
369387
select,
370388
state,
371389
threads1=None,
@@ -519,7 +537,7 @@ def _data_diff(
519537

520538
else:
521539
for op, values in diff_iter:
522-
color = COLOR_SCHEME[op]
540+
color = COLOR_SCHEME.get(op, "grey62")
523541

524542
if json_output:
525543
jsonl = json.dumps([op, list(values)])

data_diff/abcs/database_types.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import decimal
22
from abc import ABC, abstractmethod
3-
from typing import Tuple, Union
3+
from typing import List, Optional, Tuple, Type, TypeVar, Union
44
from datetime import datetime
55

66
import attrs
@@ -12,9 +12,24 @@
1212
DbKey = Union[int, str, bytes, ArithUUID, ArithAlphanumeric]
1313
DbTime = datetime
1414

15+
N = TypeVar("N")
1516

16-
@attrs.define(frozen=True)
17+
18+
@attrs.define(frozen=True, kw_only=True)
1719
class ColType:
20+
# Arbitrary metadata added and fetched at runtime.
21+
_notes: List[N] = attrs.field(factory=list, init=False, hash=False, eq=False)
22+
23+
def add_note(self, note: N) -> None:
24+
self._notes.append(note)
25+
26+
def get_note(self, cls: Type[N]) -> Optional[N]:
27+
"""Get the latest added note of type ``cls`` or its descendants."""
28+
for note in reversed(self._notes):
29+
if isinstance(note, cls):
30+
return note
31+
return None
32+
1833
@property
1934
def supported(self) -> bool:
2035
return True

data_diff/abcs/mixins.py

-193
This file was deleted.

data_diff/databases/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from data_diff.databases.base import MD5_HEXDIGITS, CHECKSUM_HEXDIGITS, QueryError, ConnectError, BaseDialect, Database
2+
from data_diff.databases.base import CHECKSUM_OFFSET
23
from data_diff.databases._connect import connect as connect
34
from data_diff.databases._connect import Connect as Connect
45
from data_diff.databases.postgresql import PostgreSQL as PostgreSQL

0 commit comments

Comments
 (0)