|
11 | 11 | DbPath, |
12 | 12 | TimestampTZ, |
13 | 13 | ) |
14 | | -from data_diff.abcs.mixins import AbstractMixin_MD5, AbstractMixin_NormalizeValue |
15 | 14 | from data_diff.databases.postgresql import ( |
16 | 15 | PostgreSQL, |
17 | 16 | MD5_HEXDIGITS, |
18 | 17 | CHECKSUM_HEXDIGITS, |
19 | 18 | CHECKSUM_OFFSET, |
20 | 19 | TIMESTAMP_PRECISION_POS, |
21 | 20 | PostgresqlDialect, |
22 | | - Mixin_NormalizeValue, |
23 | | - Mixin_MD5, |
24 | 21 | ) |
25 | 22 |
|
26 | 23 |
|
27 | 24 | @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 | + |
29 | 47 | def md5_as_int(self, s: str) -> str: |
30 | 48 | return f"strtol(substring(md5({s}), {1+MD5_HEXDIGITS-CHECKSUM_HEXDIGITS}), 16)::decimal(38) - {CHECKSUM_OFFSET}" |
31 | 49 |
|
32 | | - |
33 | | -@attrs.define(frozen=False) |
34 | | -class Mixin_NormalizeValue(Mixin_NormalizeValue): |
35 | 50 | def normalize_timestamp(self, value: str, coltype: TemporalType) -> str: |
36 | 51 | if coltype.rounds: |
37 | 52 | timestamp = f"{value}::timestamp(6)" |
@@ -59,30 +74,6 @@ def normalize_json(self, value: str, _coltype: JSON) -> str: |
59 | 74 | return f"nvl2({value}, json_serialize({value}), NULL)" |
60 | 75 |
|
61 | 76 |
|
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 | | - |
86 | 77 | @attrs.define(frozen=False, init=False, kw_only=True) |
87 | 78 | class Redshift(PostgreSQL): |
88 | 79 | dialect = Dialect() |
|
0 commit comments