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

Commit

Permalink
Merge branch 'master' into pass-inline-key-to-snowflake
Browse files Browse the repository at this point in the history
  • Loading branch information
vvkh committed Dec 6, 2023
2 parents 3b5d92b + b3d4223 commit 086f353
Show file tree
Hide file tree
Showing 47 changed files with 33,382 additions and 6,167 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/formatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ on:

jobs:
linter_name:
name: runner / black
name: runner / ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check files using the black formatter
uses: rickstaa/action-black@v1
id: black_formatter
- uses: actions/checkout@v3
- name: Check files using the ruff formatter
uses: chartboost/ruff-action@v1
id: ruff_formatter
with:
black_args: ". -l 120"
- name: Annotate diff changes using reviewdog
if: steps.black_formatter.outputs.is_formatted == 'true'
uses: reviewdog/action-suggester@v1
args: format
- name: Auto commit ruff formatting
uses: stefanzweifel/git-auto-commit-action@v5
with:
tool_name: blackfmt
commit_message: 'style fixes by ruff'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,6 @@ benchmark_*.png

# VSCode
.vscode

# History
.history
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
default_language_version:
python: python3

repos:
# Run the Ruff linter.
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.2
hooks:
# Run the Ruff formatter.
- id: ruff-format
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Once inside, you can install the dependencies.

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

- Run `pre-commit install` to automatically format your code before committing.

At the bare minimum, you need MySQL to run the tests.

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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ More information about the algorithm and performance considerations can be found
# Get started

## Validating dbt model changes between dev and prod
⚡ 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!
⚡ 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!

## Compare data tables between databases
🔀 To compare data between databases, install `data-diff` with specific database adapters, e.g.:
Expand Down
20 changes: 19 additions & 1 deletion data_diff/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,20 @@ def write_usage(self, prog: str, args: str = "", prefix: Optional[str] = None) -
metavar="PATH",
help="Specify manifest to utilize for 'prod' comparison paths instead of using configuration.",
)
@click.option(
"-pd",
"--prod-database",
"prod_database",
default=None,
help="Override the dbt production database configuration within dbt_project.yml",
)
@click.option(
"-ps",
"--prod-schema",
"prod_schema",
default=None,
help="Override the dbt production schema configuration within dbt_project.yml",
)
def main(conf, run, **kw):
log_handlers = _get_log_handlers(kw["dbt"])
if kw["table2"] is None and kw["database2"]:
Expand Down Expand Up @@ -323,6 +337,8 @@ def main(conf, run, **kw):
where_flag=kw["where"],
stats_flag=kw["stats"],
columns_flag=kw["columns"],
production_database_flag=kw["prod_database"],
production_schema_flag=kw["prod_schema"],
)
else:
return _data_diff(
Expand Down Expand Up @@ -366,6 +382,8 @@ def _data_diff(
cloud,
dbt_profiles_dir,
dbt_project_dir,
prod_database,
prod_schema,
select,
state,
threads1=None,
Expand Down Expand Up @@ -519,7 +537,7 @@ def _data_diff(

else:
for op, values in diff_iter:
color = COLOR_SCHEME[op]
color = COLOR_SCHEME.get(op, "grey62")

if json_output:
jsonl = json.dumps([op, list(values)])
Expand Down
19 changes: 17 additions & 2 deletions data_diff/abcs/database_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import decimal
from abc import ABC, abstractmethod
from typing import Tuple, Union
from typing import List, Optional, Tuple, Type, TypeVar, Union
from datetime import datetime

import attrs
Expand All @@ -12,9 +12,24 @@
DbKey = Union[int, str, bytes, ArithUUID, ArithAlphanumeric]
DbTime = datetime

N = TypeVar("N")

@attrs.define(frozen=True)

@attrs.define(frozen=True, kw_only=True)
class ColType:
# Arbitrary metadata added and fetched at runtime.
_notes: List[N] = attrs.field(factory=list, init=False, hash=False, eq=False)

def add_note(self, note: N) -> None:
self._notes.append(note)

def get_note(self, cls: Type[N]) -> Optional[N]:
"""Get the latest added note of type ``cls`` or its descendants."""
for note in reversed(self._notes):
if isinstance(note, cls):
return note
return None

@property
def supported(self) -> bool:
return True
Expand Down
193 changes: 0 additions & 193 deletions data_diff/abcs/mixins.py

This file was deleted.

1 change: 1 addition & 0 deletions data_diff/databases/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from data_diff.databases.base import MD5_HEXDIGITS, CHECKSUM_HEXDIGITS, QueryError, ConnectError, BaseDialect, Database
from data_diff.databases.base import CHECKSUM_OFFSET
from data_diff.databases._connect import connect as connect
from data_diff.databases._connect import Connect as Connect
from data_diff.databases.postgresql import PostgreSQL as PostgreSQL
Expand Down
Loading

0 comments on commit 086f353

Please sign in to comment.