Skip to content

Commit 5a27b34

Browse files
committed
fix(oracle): attempt to support MERGE on backend
1 parent 50c7f21 commit 5a27b34

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

ibis/backends/oracle/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ def raw_sql(self, query: str | sg.Expression, **kwargs: Any) -> Any:
274274
con = self.con
275275
cursor = con.cursor()
276276

277+
# TODO(deepyaman): Refactor this hack.
278+
if "MERGE" in query:
279+
assert "AS " in query
280+
query = query.replace("AS ", "")
281+
277282
try:
278283
cursor.execute(query, **kwargs)
279284
except Exception:

ibis/backends/sql/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,11 @@ def _build_upsert_from_table(
607607
matched=True,
608608
then=sge.Update(
609609
expressions=[
610-
sg.column(col, quoted=quoted).eq(
611-
sg.column(col, source_alias, quoted=quoted)
610+
sg.column(col, table=target_alias).eq(
611+
sg.column(col, table=source_alias)
612612
)
613613
for col in columns
614+
if col != on
614615
]
615616
),
616617
),
@@ -620,7 +621,7 @@ def _build_upsert_from_table(
620621
this=sge.Tuple(expressions=columns),
621622
expression=sge.Tuple(
622623
expressions=[
623-
sg.column(col, source_alias, quoted=quoted)
624+
sg.column(col, table=source_alias)
624625
for col in columns
625626
]
626627
),
@@ -629,10 +630,10 @@ def _build_upsert_from_table(
629630
into=sg.table(target, db=db, catalog=catalog, quoted=quoted).as_(
630631
target_alias
631632
),
632-
using=f"({self.compile(source)}) AS {source_alias}",
633-
on=sg.column(on, table=target_alias, quoted=quoted).eq(
634-
sg.column(on, table=source_alias, quoted=quoted)
635-
),
633+
using=f"({self.compile(source)}) {source_alias}",
634+
on=sge.Paren(this=sg.column(on, table=target_alias).eq(
635+
sg.column(on, table=source_alias)
636+
)),
636637
dialect=compiler.dialect,
637638
)
638639
return query

0 commit comments

Comments
 (0)