Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions data_diff/databases/mssql.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
class MsSQL(ThreadedDatabase):
"AKA sql-server"
# class MsSQL(ThreadedDatabase):
# "AKA sql-server"

def __init__(self, host, port, user, password, *, database, thread_count, **kw):
args = dict(server=host, port=port, database=database, user=user, password=password, **kw)
self._args = {k: v for k, v in args.items() if v is not None}
# def __init__(self, host, port, user, password, *, database, thread_count, **kw):
# args = dict(server=host, port=port, database=database, user=user, password=password, **kw)
# self._args = {k: v for k, v in args.items() if v is not None}

super().__init__(thread_count=thread_count)
# super().__init__(thread_count=thread_count)

def create_connection(self):
mssql = import_mssql()
try:
return mssql.connect(**self._args)
except mssql.Error as e:
raise ConnectError(*e.args) from e
# def create_connection(self):
# mssql = import_mssql()
# try:
# return mssql.connect(**self._args)
# except mssql.Error as e:
# raise ConnectError(*e.args) from e

def quote(self, s: str):
return f"[{s}]"
# def quote(self, s: str):
# return f"[{s}]"

def md5_to_int(self, s: str) -> str:
return f"CONVERT(decimal(38,0), CONVERT(bigint, HashBytes('MD5', {s}), 2))"
# return f"CONVERT(bigint, (CHECKSUM({s})))"
# def md5_to_int(self, s: str) -> str:
# return f"CONVERT(decimal(38,0), CONVERT(bigint, HashBytes('MD5', {s}), 2))"
# # return f"CONVERT(bigint, (CHECKSUM({s})))"

def to_string(self, s: str):
return f"CONVERT(varchar, {s})"
# def to_string(self, s: str):
# return f"CONVERT(varchar, {s})"
16 changes: 8 additions & 8 deletions data_diff/databases/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,26 @@ def _parse_type(
r"TIMESTAMP\((\d)\) WITH LOCAL TIME ZONE": Timestamp,
r"TIMESTAMP\((\d)\) WITH TIME ZONE": TimestampTZ,
}
for regexp, cls in regexps.items():
for regexp, t_cls in regexps.items():
m = re.match(regexp + "$", type_repr)
if m:
datetime_precision = int(m.group(1))
return cls(
return t_cls(
precision=datetime_precision if datetime_precision is not None else DEFAULT_DATETIME_PRECISION,
rounds=self.ROUNDS_ON_PREC_LOSS,
)

cls = {
n_cls = {
"NUMBER": Decimal,
"FLOAT": Float,
}.get(type_repr, None)
if cls:
if issubclass(cls, Decimal):
if n_cls:
if issubclass(n_cls, Decimal):
assert numeric_scale is not None, (type_repr, numeric_precision, numeric_scale)
return cls(precision=numeric_scale)
return n_cls(precision=numeric_scale)

assert issubclass(cls, Float)
return cls(
assert issubclass(n_cls, Float)
return n_cls(
precision=self._convert_db_precision_to_digits(
numeric_precision if numeric_precision is not None else DEFAULT_NUMERIC_PRECISION
)
Expand Down
20 changes: 10 additions & 10 deletions data_diff/databases/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,30 @@ def _parse_type(
r"timestamp\((\d)\)": Timestamp,
r"timestamp\((\d)\) with time zone": TimestampTZ,
}
for regexp, cls in timestamp_regexps.items():
for regexp, t_cls in timestamp_regexps.items():
m = re.match(regexp + "$", type_repr)
if m:
datetime_precision = int(m.group(1))
return cls(
return t_cls(
precision=datetime_precision if datetime_precision is not None else DEFAULT_DATETIME_PRECISION,
rounds=False,
)

number_regexps = {r"decimal\((\d+),(\d+)\)": Decimal}
for regexp, cls in number_regexps.items():
for regexp, n_cls in number_regexps.items():
m = re.match(regexp + "$", type_repr)
if m:
prec, scale = map(int, m.groups())
return cls(scale)
return n_cls(scale)

cls = self.NUMERIC_TYPES.get(type_repr)
if cls:
if issubclass(cls, Integer):
n_cls = self.NUMERIC_TYPES.get(type_repr)
if n_cls:
if issubclass(n_cls, Integer):
assert numeric_precision is not None
return cls(0)
return n_cls(0)

assert issubclass(cls, Float)
return cls(
assert issubclass(n_cls, Float)
return n_cls(
precision=self._convert_db_precision_to_digits(
numeric_precision if numeric_precision is not None else DEFAULT_NUMERIC_PRECISION
)
Expand Down