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

Commit 23b4b21

Browse files
committed
feat: create an instance of the dialect instead of class object
1 parent caf766c commit 23b4b21

File tree

14 files changed

+33
-26
lines changed

14 files changed

+33
-26
lines changed

data_diff/databases/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,13 +907,16 @@ class Database(abc.ABC):
907907
Instanciated using :meth:`~data_diff.connect`
908908
"""
909909

910+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = BaseDialect
911+
910912
SUPPORTS_ALPHANUMS: ClassVar[bool] = True
911913
SUPPORTS_UNIQUE_CONSTAINT: ClassVar[bool] = False
912914
CONNECT_URI_KWPARAMS: ClassVar[List[str]] = []
913915

914916
default_schema: Optional[str] = None
915917
_interactive: bool = False
916918
is_closed: bool = False
919+
_dialect: BaseDialect = None
917920

918921
@property
919922
def name(self):
@@ -1142,10 +1145,13 @@ def close(self):
11421145
return super().close()
11431146

11441147
@property
1145-
@abstractmethod
11461148
def dialect(self) -> BaseDialect:
11471149
"The dialect of the database. Used internally by Database, and also available publicly."
11481150

1151+
if not self._dialect:
1152+
self._dialect = self.DIALECT_CLASS()
1153+
return self._dialect
1154+
11491155
@property
11501156
@abstractmethod
11511157
def CONNECT_URI_HELP(self) -> str:

data_diff/databases/bigquery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import re
2-
from typing import Any, List, Union
2+
from typing import Any, ClassVar, List, Union, Type
33

44
import attrs
55

@@ -182,9 +182,9 @@ def normalize_struct(self, value: str, _coltype: Struct) -> str:
182182

183183
@attrs.define(frozen=False, init=False, kw_only=True)
184184
class BigQuery(Database):
185+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
185186
CONNECT_URI_HELP = "bigquery://<project>/<dataset>"
186187
CONNECT_URI_PARAMS = ["dataset"]
187-
dialect = Dialect()
188188

189189
project: str
190190
dataset: str

data_diff/databases/clickhouse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Optional, Type
1+
from typing import Any, ClassVar, Dict, Optional, Type
22

33
import attrs
44

@@ -167,7 +167,7 @@ def normalize_timestamp(self, value: str, coltype: TemporalType) -> str:
167167

168168
@attrs.define(frozen=False, init=False, kw_only=True)
169169
class Clickhouse(ThreadedDatabase):
170-
dialect = Dialect()
170+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
171171
CONNECT_URI_HELP = "clickhouse://<user>:<password>@<host>/<database>"
172172
CONNECT_URI_PARAMS = ["database?"]
173173

data_diff/databases/databricks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import math
2-
from typing import Any, Dict, Sequence
2+
from typing import Any, ClassVar, Dict, Sequence, Type
33
import logging
44

55
import attrs
@@ -101,7 +101,7 @@ def normalize_boolean(self, value: str, _coltype: Boolean) -> str:
101101

102102
@attrs.define(frozen=False, init=False, kw_only=True)
103103
class Databricks(ThreadedDatabase):
104-
dialect = Dialect()
104+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
105105
CONNECT_URI_HELP = "databricks://:<access_token>@<server_hostname>/<http_path>"
106106
CONNECT_URI_PARAMS = ["catalog", "schema"]
107107

data_diff/databases/duckdb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Union
1+
from typing import Any, ClassVar, Dict, Union, Type
22

33
import attrs
44

@@ -119,7 +119,7 @@ def normalize_boolean(self, value: str, _coltype: Boolean) -> str:
119119

120120
@attrs.define(frozen=False, init=False, kw_only=True)
121121
class DuckDB(Database):
122-
dialect = Dialect()
122+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
123123
SUPPORTS_UNIQUE_CONSTAINT = False # Temporary, until we implement it
124124
CONNECT_URI_HELP = "duckdb://<dbname>@<filepath>"
125125
CONNECT_URI_PARAMS = ["database", "dbpath"]

data_diff/databases/mssql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Optional
1+
from typing import Any, ClassVar, Dict, Optional, Type
22

33
import attrs
44

@@ -153,7 +153,7 @@ def to_md5(self, s: str) -> str:
153153

154154
@attrs.define(frozen=False, init=False, kw_only=True)
155155
class MsSQL(ThreadedDatabase):
156-
dialect = Dialect()
156+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
157157
CONNECT_URI_HELP = "mssql://<user>:<password>@<host>/<database>/<schema>"
158158
CONNECT_URI_PARAMS = ["database", "schema"]
159159

data_diff/databases/mysql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict
1+
from typing import Any, ClassVar, Dict, Type
22

33
import attrs
44

@@ -120,7 +120,7 @@ def normalize_uuid(self, value: str, coltype: ColType_UUID) -> str:
120120

121121
@attrs.define(frozen=False, init=False, kw_only=True)
122122
class MySQL(ThreadedDatabase):
123-
dialect = Dialect()
123+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
124124
SUPPORTS_ALPHANUMS = False
125125
SUPPORTS_UNIQUE_CONSTAINT = True
126126
CONNECT_URI_HELP = "mysql://<user>:<password>@<host>/<database>"

data_diff/databases/oracle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Optional
1+
from typing import Any, ClassVar, Dict, List, Optional, Type
22

33
import attrs
44

@@ -160,7 +160,7 @@ def normalize_number(self, value: str, coltype: FractionalType) -> str:
160160

161161
@attrs.define(frozen=False, init=False, kw_only=True)
162162
class Oracle(ThreadedDatabase):
163-
dialect = Dialect()
163+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
164164
CONNECT_URI_HELP = "oracle://<user>:<password>@<host>/<database>"
165165
CONNECT_URI_PARAMS = ["database?"]
166166

data_diff/databases/postgresql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def normalize_json(self, value: str, _coltype: JSON) -> str:
122122

123123
@attrs.define(frozen=False, init=False, kw_only=True)
124124
class PostgreSQL(ThreadedDatabase):
125-
dialect = PostgresqlDialect()
125+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = PostgresqlDialect
126126
SUPPORTS_UNIQUE_CONSTAINT = True
127127
CONNECT_URI_HELP = "postgresql://<user>:<password>@<host>/<database>"
128128
CONNECT_URI_PARAMS = ["database?"]

data_diff/databases/presto.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from functools import partial
22
import re
3-
from typing import Any
3+
from typing import Any, ClassVar, Type
44

55
import attrs
66

@@ -153,7 +153,7 @@ def normalize_boolean(self, value: str, _coltype: Boolean) -> str:
153153

154154
@attrs.define(frozen=False, init=False, kw_only=True)
155155
class Presto(Database):
156-
dialect = Dialect()
156+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
157157
CONNECT_URI_HELP = "presto://<user>@<host>/<catalog>/<schema>"
158158
CONNECT_URI_PARAMS = ["catalog", "schema"]
159159

data_diff/databases/redshift.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
TimestampTZ,
1313
)
1414
from data_diff.databases.postgresql import (
15+
BaseDialect,
1516
PostgreSQL,
1617
MD5_HEXDIGITS,
1718
CHECKSUM_HEXDIGITS,
@@ -79,7 +80,7 @@ def normalize_json(self, value: str, _coltype: JSON) -> str:
7980

8081
@attrs.define(frozen=False, init=False, kw_only=True)
8182
class Redshift(PostgreSQL):
82-
dialect = Dialect()
83+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
8384
CONNECT_URI_HELP = "redshift://<user>:<password>@<host>/<database>"
8485
CONNECT_URI_PARAMS = ["database?"]
8586

data_diff/databases/snowflake.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Union, List
1+
from typing import Any, ClassVar, Union, List, Type
22
import logging
33

44
import attrs
@@ -96,7 +96,7 @@ def normalize_boolean(self, value: str, _coltype: Boolean) -> str:
9696

9797
@attrs.define(frozen=False, init=False, kw_only=True)
9898
class Snowflake(Database):
99-
dialect = Dialect()
99+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
100100
CONNECT_URI_HELP = "snowflake://<user>:<password>@<account>/<database>/<SCHEMA>?warehouse=<WAREHOUSE>"
101101
CONNECT_URI_PARAMS = ["database", "schema"]
102102
CONNECT_URI_KWPARAMS = ["warehouse"]

data_diff/databases/trino.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import Any
1+
from typing import Any, ClassVar, Type
22

33
import attrs
44

55
from data_diff.abcs.database_types import TemporalType, ColType_UUID
66
from data_diff.databases import presto
77
from data_diff.databases.base import import_helper
8-
from data_diff.databases.base import TIMESTAMP_PRECISION_POS
8+
from data_diff.databases.base import TIMESTAMP_PRECISION_POS, BaseDialect
99

1010

1111
@import_helper("trino")
@@ -34,7 +34,7 @@ def normalize_uuid(self, value: str, coltype: ColType_UUID) -> str:
3434

3535
@attrs.define(frozen=False, init=False, kw_only=True)
3636
class Trino(presto.Presto):
37-
dialect = Dialect()
37+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
3838
CONNECT_URI_HELP = "trino://<user>@<host>/<catalog>/<schema>"
3939
CONNECT_URI_PARAMS = ["catalog", "schema"]
4040

data_diff/databases/vertica.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List
1+
from typing import Any, ClassVar, Dict, List, Type
22

33
import attrs
44

@@ -135,7 +135,7 @@ def normalize_boolean(self, value: str, _coltype: Boolean) -> str:
135135

136136
@attrs.define(frozen=False, init=False, kw_only=True)
137137
class Vertica(ThreadedDatabase):
138-
dialect = Dialect()
138+
DIALECT_CLASS: ClassVar[Type[BaseDialect]] = Dialect
139139
CONNECT_URI_HELP = "vertica://<user>:<password>@<host>/<database>"
140140
CONNECT_URI_PARAMS = ["database?"]
141141

0 commit comments

Comments
 (0)