From 4a0537b85826006bd04623f51430bbe8c8303c2b Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Wed, 11 Sep 2024 07:37:02 -0400 Subject: [PATCH] perf(oracle): speed up existence check --- ibis/backends/oracle/__init__.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ibis/backends/oracle/__init__.py b/ibis/backends/oracle/__init__.py index 51d9427a2a6c6..2481175c600b6 100644 --- a/ibis/backends/oracle/__init__.py +++ b/ibis/backends/oracle/__init__.py @@ -24,7 +24,7 @@ from ibis import util from ibis.backends import CanListDatabase, CanListSchema from ibis.backends.sql import SQLBackend -from ibis.backends.sql.compilers.base import STAR, C +from ibis.backends.sql.compilers.base import NULL, STAR, C if TYPE_CHECKING: from urllib.parse import ParseResult @@ -495,6 +495,21 @@ def drop_table( super().drop_table(name, database=(catalog, db), force=force) + def _in_memory_table_exists(self, name: str) -> bool: + sql = ( + sg.select(NULL) + .from_(sg.to_identifier("USER_OBJECTS", quoted=self.compiler.quoted)) + .where( + C.OBJECT_TYPE.eq(sge.convert("TABLE")), + C.OBJECT_NAME.eq(sge.convert(name)), + ) + .limit(sge.convert(1)) + .sql(self.dialect) + ) + with self.begin() as cur: + results = cur.execute(sql).fetchall() + return bool(results) + def _register_in_memory_table(self, op: ops.InMemoryTable) -> None: schema = op.schema