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

Commit 5fdd257

Browse files
authored
Merge pull request #117 from datafold/issue115
Oracle: Added support for schemas (Issue #115)
2 parents 6ed2a0e + 1522854 commit 5fdd257

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

data_diff/databases/oracle.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class Oracle(ThreadedDatabase):
1818
def __init__(self, host, port, user, password, *, database, thread_count, **kw):
1919
assert not port
2020
self.kwargs = dict(user=user, password=password, dsn="%s/%s" % (host, database), **kw)
21+
22+
self.default_schema = user
23+
2124
super().__init__(thread_count=thread_count)
2225

2326
def create_connection(self):
@@ -45,13 +48,11 @@ def to_string(self, s: str):
4548
return f"cast({s} as varchar(1024))"
4649

4750
def select_table_schema(self, path: DbPath) -> str:
48-
if len(path) > 1:
49-
raise ValueError("Unexpected table path for oracle")
50-
(table,) = path
51+
schema, table = self._normalize_table_path(path)
5152

5253
return (
5354
f"SELECT column_name, data_type, 6 as datetime_precision, data_precision as numeric_precision, data_scale as numeric_scale"
54-
f" FROM USER_TAB_COLUMNS WHERE table_name = '{table.upper()}'"
55+
f" FROM ALL_TAB_COLUMNS WHERE table_name = '{table.upper()}' AND owner = '{schema.upper()}'"
5556
)
5657

5758
def normalize_timestamp(self, value: str, coltype: TemporalType) -> str:

data_diff/sql.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,12 @@ class Checksum(Sql):
114114
exprs: Sequence[SqlOrStr]
115115

116116
def compile(self, c: Compiler):
117-
compiled_exprs = ", ".join(map(c.compile, self.exprs))
118-
expr = f"concat({compiled_exprs})"
117+
if len(self.exprs) > 1:
118+
compiled_exprs = ", ".join(map(c.compile, self.exprs))
119+
expr = f"concat({compiled_exprs})"
120+
else:
121+
expr ,= self.exprs
122+
expr = c.compile(expr)
119123
md5 = c.database.md5_to_int(expr)
120124
return f"sum({md5})"
121125

0 commit comments

Comments
 (0)