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

Commit 3196c35

Browse files
authored
Merge pull request #184 from datafold/issue123
Bugfix for Oracle - didn't properly handing .rounds attribute.
2 parents d21b071 + 3ce2fcb commit 3196c35

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

data_diff/databases/oracle.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .database_types import *
44
from .base import ThreadedDatabase, import_helper, ConnectError, QueryError
5-
from .base import DEFAULT_DATETIME_PRECISION, DEFAULT_NUMERIC_PRECISION
5+
from .base import DEFAULT_DATETIME_PRECISION, TIMESTAMP_PRECISION_POS
66

77
SESSION_TIME_ZONE = None # Changed by the tests
88

@@ -69,7 +69,14 @@ def select_table_schema(self, path: DbPath) -> str:
6969
)
7070

7171
def normalize_timestamp(self, value: str, coltype: TemporalType) -> str:
72-
return f"to_char(cast({value} as timestamp({coltype.precision})), 'YYYY-MM-DD HH24:MI:SS.FF6')"
72+
if coltype.rounds:
73+
return f"to_char(cast({value} as timestamp({coltype.precision})), 'YYYY-MM-DD HH24:MI:SS.FF6')"
74+
else:
75+
if coltype.precision > 0:
76+
truncated = f"to_char({value}, 'YYYY-MM-DD HH24:MI:SS.FF{coltype.precision}')"
77+
else:
78+
truncated = f"to_char({value}, 'YYYY-MM-DD HH24:MI:SS.')"
79+
return f"RPAD({truncated}, {TIMESTAMP_PRECISION_POS+6}, '0')"
7380

7481
def normalize_number(self, value: str, coltype: FractionalType) -> str:
7582
# FM999.9990

data_diff/utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,24 @@ def number_to_human(n):
5757
def _join_if_any(sym, args):
5858
args = list(args)
5959
if not args:
60-
return ''
60+
return ""
6161
return sym.join(str(a) for a in args if a)
6262

63-
def remove_password_from_url(url: str, replace_with: str="***") -> str:
63+
64+
def remove_password_from_url(url: str, replace_with: str = "***") -> str:
6465
parsed = urlparse(url)
65-
account = parsed.username or ''
66+
account = parsed.username or ""
6667
if parsed.password:
67-
account += ':' + replace_with
68+
account += ":" + replace_with
6869
host = _join_if_any(":", filter(None, [parsed.hostname, parsed.port]))
6970
netloc = _join_if_any("@", filter(None, [account, host]))
7071
replaced = parsed._replace(netloc=netloc)
7172
return replaced.geturl()
7273

74+
7375
def join_iter(joiner: Any, iterable: iter) -> iter:
7476
it = iter(iterable)
7577
yield next(it)
7678
for i in it:
7779
yield joiner
7880
yield i
79-

0 commit comments

Comments
 (0)