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

Commit d95d036

Browse files
author
Sergey Vasilyev
committed
Satisfy the code formatter
1 parent 8472467 commit d95d036

17 files changed

Lines changed: 100 additions & 37 deletions

data_diff/databases/_connect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def match_path(self, dsn):
9494

9595
class Connect:
9696
"""Provides methods for connecting to a supported database using a URL or connection dict."""
97+
9798
conn_cache: MutableMapping[Hashable, Database]
9899

99100
def __init__(self, database_by_scheme: Dict[str, Database] = DATABASE_BY_SCHEME):

data_diff/databases/base.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,39 @@
2121
from data_diff.queries.extras import ApplyFuncAndNormalizeAsString, Checksum, NormalizeAsString
2222
from data_diff.utils import ArithString, is_uuid, join_iter, safezip
2323
from data_diff.queries.api import Expr, table, Select, SKIP, Explain, Code, this
24-
from data_diff.queries.ast_classes import Alias, BinOp, CaseWhen, Cast, Column, Commit, Concat, ConstantTable, Count, \
25-
CreateTable, Cte, \
26-
CurrentTimestamp, DropTable, Func, \
27-
GroupBy, \
28-
ITable, In, InsertToTable, IsDistinctFrom, \
29-
Join, \
30-
Param, \
31-
Random, \
32-
Root, TableAlias, TableOp, TablePath, \
33-
TimeTravel, TruncateTable, UnaryOp, WhenThen, _ResolveColumn
24+
from data_diff.queries.ast_classes import (
25+
Alias,
26+
BinOp,
27+
CaseWhen,
28+
Cast,
29+
Column,
30+
Commit,
31+
Concat,
32+
ConstantTable,
33+
Count,
34+
CreateTable,
35+
Cte,
36+
CurrentTimestamp,
37+
DropTable,
38+
Func,
39+
GroupBy,
40+
ITable,
41+
In,
42+
InsertToTable,
43+
IsDistinctFrom,
44+
Join,
45+
Param,
46+
Random,
47+
Root,
48+
TableAlias,
49+
TableOp,
50+
TablePath,
51+
TimeTravel,
52+
TruncateTable,
53+
UnaryOp,
54+
WhenThen,
55+
_ResolveColumn,
56+
)
3457
from data_diff.abcs.database_types import (
3558
Array,
3659
Struct,
@@ -414,7 +437,9 @@ def render_checksum(self, c: Compiler, elem: Checksum) -> str:
414437

415438
def render_concat(self, c: Compiler, elem: Concat) -> str:
416439
# We coalesce because on some DBs (e.g. MySQL) concat('a', NULL) is NULL
417-
items = [f"coalesce({self.compile(c, Code(self.to_string(self.compile(c, expr))))}, '<null>')" for expr in elem.exprs]
440+
items = [
441+
f"coalesce({self.compile(c, Code(self.to_string(self.compile(c, expr))))}, '<null>')" for expr in elem.exprs
442+
]
418443
assert items
419444
if len(items) == 1:
420445
return items[0]
@@ -559,17 +584,15 @@ def render_groupby(self, c: Compiler, elem: GroupBy) -> str:
559584
columns=columns,
560585
group_by_exprs=[Code(k) for k in keys],
561586
having_exprs=elem.having_exprs,
562-
)
587+
),
563588
)
564589

565590
keys_str = ", ".join(keys)
566591
columns_str = ", ".join(self.compile(c, x) for x in columns)
567592
having_str = (
568593
" HAVING " + " AND ".join(map(compile_fn, elem.having_exprs)) if elem.having_exprs is not None else ""
569594
)
570-
select = (
571-
f"SELECT {columns_str} FROM {self.compile(c.replace(in_select=True), elem.table)} GROUP BY {keys_str}{having_str}"
572-
)
595+
select = f"SELECT {columns_str} FROM {self.compile(c.replace(in_select=True), elem.table)} GROUP BY {keys_str}{having_str}"
573596

574597
if c.in_select:
575598
select = f"({select}) {c.new_unique_name()}"
@@ -601,7 +624,7 @@ def render_timetravel(self, c: Compiler, elem: TimeTravel) -> str:
601624
# TODO: why is it c.? why not self? time-trvelling is the dialect's thing, isnt't it?
602625
c.time_travel(
603626
elem.table, before=elem.before, timestamp=elem.timestamp, offset=elem.offset, statement=elem.statement
604-
)
627+
),
605628
)
606629

607630
def render_createtable(self, c: Compiler, elem: CreateTable) -> str:
@@ -779,7 +802,6 @@ class _DialectWithMixins(cls, *mixins, *abstract_mixins):
779802
_DialectWithMixins.__name__ = cls.__name__
780803
return _DialectWithMixins()
781804

782-
783805
@property
784806
@abstractmethod
785807
def name(self) -> str:

data_diff/databases/bigquery.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ def time_travel(
139139
)
140140

141141

142-
class Dialect(BaseDialect, Mixin_Schema, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue):
142+
class Dialect(
143+
BaseDialect, Mixin_Schema, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue
144+
):
143145
name = "BigQuery"
144146
ROUNDS_ON_PREC_LOSS = False # Technically BigQuery doesn't allow implicit rounding or truncation
145147
TYPE_CLASSES = {

data_diff/databases/duckdb.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def random_sample_ratio_approx(self, tbl: ITable, ratio: float) -> ITable:
6868
return code("SELECT * FROM ({tbl}) USING SAMPLE {percent}%;", tbl=tbl, percent=int(100 * ratio))
6969

7070

71-
class Dialect(BaseDialect, Mixin_Schema, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue):
71+
class Dialect(
72+
BaseDialect, Mixin_Schema, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue
73+
):
7274
name = "DuckDB"
7375
ROUNDS_ON_PREC_LOSS = False
7476
SUPPORTS_PRIMARY_KEY = True

data_diff/databases/mssql.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ def md5_as_int(self, s: str) -> str:
5858
return f"convert(bigint, convert(varbinary, '0x' + RIGHT(CONVERT(NVARCHAR(32), HashBytes('MD5', {s}), 2), {CHECKSUM_HEXDIGITS}), 1))"
5959

6060

61-
class Dialect(BaseDialect, Mixin_Schema, Mixin_OptimizerHints, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue):
61+
class Dialect(
62+
BaseDialect,
63+
Mixin_Schema,
64+
Mixin_OptimizerHints,
65+
Mixin_MD5,
66+
Mixin_NormalizeValue,
67+
AbstractMixin_MD5,
68+
AbstractMixin_NormalizeValue,
69+
):
6270
name = "MsSQL"
6371
ROUNDS_ON_PREC_LOSS = True
6472
SUPPORTS_PRIMARY_KEY = True

data_diff/databases/mysql.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ def normalize_uuid(self, value: str, coltype: ColType_UUID) -> str:
6060
return f"TRIM(CAST({value} AS char))"
6161

6262

63-
class Dialect(BaseDialect, Mixin_Schema, Mixin_OptimizerHints, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue):
63+
class Dialect(
64+
BaseDialect,
65+
Mixin_Schema,
66+
Mixin_OptimizerHints,
67+
Mixin_MD5,
68+
Mixin_NormalizeValue,
69+
AbstractMixin_MD5,
70+
AbstractMixin_NormalizeValue,
71+
):
6472
name = "MySQL"
6573
ROUNDS_ON_PREC_LOSS = True
6674
SUPPORTS_PRIMARY_KEY = True

data_diff/databases/oracle.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ def list_tables(self, table_schema: str, like: Compilable = None) -> Compilable:
8080
)
8181

8282

83-
class Dialect(BaseDialect, Mixin_Schema, Mixin_OptimizerHints, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue):
83+
class Dialect(
84+
BaseDialect,
85+
Mixin_Schema,
86+
Mixin_OptimizerHints,
87+
Mixin_MD5,
88+
Mixin_NormalizeValue,
89+
AbstractMixin_MD5,
90+
AbstractMixin_NormalizeValue,
91+
):
8492
name = "Oracle"
8593
SUPPORTS_PRIMARY_KEY = True
8694
SUPPORTS_INDEXES = True

data_diff/databases/postgresql.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ def normalize_json(self, value: str, _coltype: JSON) -> str:
6060
return f"{value}::text"
6161

6262

63-
class PostgresqlDialect(BaseDialect, Mixin_Schema, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue):
63+
class PostgresqlDialect(
64+
BaseDialect, Mixin_Schema, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue
65+
):
6466
name = "PostgreSQL"
6567
ROUNDS_ON_PREC_LOSS = True
6668
SUPPORTS_PRIMARY_KEY = True

data_diff/databases/presto.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def normalize_boolean(self, value: str, _coltype: Boolean) -> str:
7676
return self.to_string(f"cast ({value} as int)")
7777

7878

79-
class Dialect(BaseDialect, Mixin_Schema, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue):
79+
class Dialect(
80+
BaseDialect, Mixin_Schema, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue
81+
):
8082
name = "Presto"
8183
ROUNDS_ON_PREC_LOSS = True
8284
TYPE_CLASSES = {

data_diff/databases/snowflake.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ def time_travel(
104104
return code(f"{{table}} {at_or_before}({key} => {{value}})", table=table, value=value)
105105

106106

107-
class Dialect(BaseDialect, Mixin_Schema, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue):
107+
class Dialect(
108+
BaseDialect, Mixin_Schema, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue
109+
):
108110
name = "Snowflake"
109111
ROUNDS_ON_PREC_LOSS = False
110112
TYPE_CLASSES = {

0 commit comments

Comments
 (0)