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

Commit 3a55b18

Browse files
author
Sergey Vasilyev
committed
Simplify double-inheritance of Redshift dialect from Postgres dialect
All the Postgres mixins are already inherited into the Redshift dialect via its base class, so there is no need to duplicate the mixins.
1 parent 2e1ba41 commit 3a55b18

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

data_diff/databases/redshift.py

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,42 @@
1111
DbPath,
1212
TimestampTZ,
1313
)
14-
from data_diff.abcs.mixins import AbstractMixin_MD5, AbstractMixin_NormalizeValue
1514
from data_diff.databases.postgresql import (
1615
PostgreSQL,
1716
MD5_HEXDIGITS,
1817
CHECKSUM_HEXDIGITS,
1918
CHECKSUM_OFFSET,
2019
TIMESTAMP_PRECISION_POS,
2120
PostgresqlDialect,
22-
Mixin_NormalizeValue,
23-
Mixin_MD5,
2421
)
2522

2623

2724
@attrs.define(frozen=False)
28-
class Mixin_MD5(Mixin_MD5):
25+
class Dialect(PostgresqlDialect):
26+
name = "Redshift"
27+
TYPE_CLASSES: ClassVar[Dict[str, Type[ColType]]] = {
28+
**PostgresqlDialect.TYPE_CLASSES,
29+
"double": Float,
30+
"real": Float,
31+
"super": JSON,
32+
}
33+
SUPPORTS_INDEXES = False
34+
35+
def concat(self, items: List[str]) -> str:
36+
joined_exprs = " || ".join(items)
37+
return f"({joined_exprs})"
38+
39+
def is_distinct_from(self, a: str, b: str) -> str:
40+
return f"({a} IS NULL != {b} IS NULL) OR ({a}!={b})"
41+
42+
def type_repr(self, t) -> str:
43+
if isinstance(t, TimestampTZ):
44+
return f"timestamptz"
45+
return super().type_repr(t)
46+
2947
def md5_as_int(self, s: str) -> str:
3048
return f"strtol(substring(md5({s}), {1+MD5_HEXDIGITS-CHECKSUM_HEXDIGITS}), 16)::decimal(38) - {CHECKSUM_OFFSET}"
3149

32-
33-
@attrs.define(frozen=False)
34-
class Mixin_NormalizeValue(Mixin_NormalizeValue):
3550
def normalize_timestamp(self, value: str, coltype: TemporalType) -> str:
3651
if coltype.rounds:
3752
timestamp = f"{value}::timestamp(6)"
@@ -59,30 +74,6 @@ def normalize_json(self, value: str, _coltype: JSON) -> str:
5974
return f"nvl2({value}, json_serialize({value}), NULL)"
6075

6176

62-
@attrs.define(frozen=False)
63-
class Dialect(PostgresqlDialect, Mixin_MD5, Mixin_NormalizeValue, AbstractMixin_MD5, AbstractMixin_NormalizeValue):
64-
name = "Redshift"
65-
TYPE_CLASSES: ClassVar[Dict[str, Type[ColType]]] = {
66-
**PostgresqlDialect.TYPE_CLASSES,
67-
"double": Float,
68-
"real": Float,
69-
"super": JSON,
70-
}
71-
SUPPORTS_INDEXES = False
72-
73-
def concat(self, items: List[str]) -> str:
74-
joined_exprs = " || ".join(items)
75-
return f"({joined_exprs})"
76-
77-
def is_distinct_from(self, a: str, b: str) -> str:
78-
return f"({a} IS NULL != {b} IS NULL) OR ({a}!={b})"
79-
80-
def type_repr(self, t) -> str:
81-
if isinstance(t, TimestampTZ):
82-
return f"timestamptz"
83-
return super().type_repr(t)
84-
85-
8677
@attrs.define(frozen=False, init=False, kw_only=True)
8778
class Redshift(PostgreSQL):
8879
dialect = Dialect()

0 commit comments

Comments
 (0)