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

Commit accc5dc

Browse files
author
Sergey Vasilyev
committed
Squash the OptimizerHints mixin into the base dialect and thus all dialects (even when not used)
It is currently defined and used only in MS SQL, MySQL, and Oracle. Other databases simply do not support this method. It will not damage the query if we add the SQL comment there if the database does not support it.
1 parent 93c128b commit accc5dc

File tree

5 files changed

+4
-27
lines changed

5 files changed

+4
-27
lines changed

data_diff/abcs/mixins.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,3 @@ class AbstractMixin_MD5(AbstractMixin):
120120
@abstractmethod
121121
def md5_as_int(self, s: str) -> str:
122122
"Provide SQL for computing md5 and returning an int"
123-
124-
125-
@attrs.define(frozen=False)
126-
class AbstractMixin_OptimizerHints(AbstractMixin):
127-
@abstractmethod
128-
def optimizer_hints(self, optimizer_hints: str) -> str:
129-
"""Creates a compatible optimizer_hints string
130-
131-
Parameters:
132-
optimizer_hints - string of optimizer hints
133-
"""

data_diff/databases/base.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@
7474
JSON,
7575
)
7676
from data_diff.abcs.mixins import Compilable
77-
from data_diff.abcs.mixins import (
78-
AbstractMixin_NormalizeValue,
79-
AbstractMixin_OptimizerHints,
80-
)
77+
from data_diff.abcs.mixins import AbstractMixin_NormalizeValue
8178

8279
logger = logging.getLogger("database")
8380
cv_params = contextvars.ContextVar("params")
@@ -198,12 +195,6 @@ def apply_query(callback: Callable[[str], Any], sql_code: Union[str, ThreadLocal
198195
return callback(sql_code)
199196

200197

201-
@attrs.define(frozen=False)
202-
class Mixin_OptimizerHints(AbstractMixin_OptimizerHints):
203-
def optimizer_hints(self, hints: str) -> str:
204-
return f"/*+ {hints} */ "
205-
206-
207198
@attrs.define(frozen=False)
208199
class BaseDialect(abc.ABC):
209200
SUPPORTS_PRIMARY_KEY: ClassVar[bool] = False
@@ -771,6 +762,9 @@ def to_string(self, s: str) -> str:
771762
def set_timezone_to_utc(self) -> str:
772763
"Provide SQL for setting the session timezone to UTC"
773764

765+
def optimizer_hints(self, hints: str) -> str:
766+
return f"/*+ {hints} */ "
767+
774768

775769
T = TypeVar("T", bound=BaseDialect)
776770

data_diff/databases/mssql.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from data_diff.abcs.mixins import AbstractMixin_MD5, AbstractMixin_NormalizeValue
66
from data_diff.databases.base import (
77
CHECKSUM_HEXDIGITS,
8-
Mixin_OptimizerHints,
98
CHECKSUM_OFFSET,
109
QueryError,
1110
ThreadedDatabase,
@@ -39,7 +38,6 @@ def import_mssql():
3938
@attrs.define(frozen=False)
4039
class Dialect(
4140
BaseDialect,
42-
Mixin_OptimizerHints,
4341
AbstractMixin_MD5,
4442
AbstractMixin_NormalizeValue,
4543
):

data_diff/databases/mysql.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
AbstractMixin_NormalizeValue,
2121
)
2222
from data_diff.databases.base import (
23-
Mixin_OptimizerHints,
2423
ThreadedDatabase,
2524
import_helper,
2625
ConnectError,
@@ -44,7 +43,6 @@ def import_mysql():
4443
@attrs.define(frozen=False)
4544
class Dialect(
4645
BaseDialect,
47-
Mixin_OptimizerHints,
4846
AbstractMixin_MD5,
4947
AbstractMixin_NormalizeValue,
5048
):

data_diff/databases/oracle.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from data_diff.abcs.mixins import AbstractMixin_MD5, AbstractMixin_NormalizeValue
2020
from data_diff.databases.base import (
2121
BaseDialect,
22-
Mixin_OptimizerHints,
2322
ThreadedDatabase,
2423
import_helper,
2524
ConnectError,
@@ -43,7 +42,6 @@ def import_oracle():
4342
@attrs.define(frozen=False)
4443
class Dialect(
4544
BaseDialect,
46-
Mixin_OptimizerHints,
4745
AbstractMixin_MD5,
4846
AbstractMixin_NormalizeValue,
4947
):

0 commit comments

Comments
 (0)