Skip to content

Commit

Permalink
refactor(oracle): remove dependency on private function for temp tabl…
Browse files Browse the repository at this point in the history
…es (#8480)

## Description of changes

The previous workaround for temp tables in Oracle was quite brittle and
broke
when I tried to bump our upper pin on `sqlglot`. I've refactored it to
be
(hopefully) less brittle ~and also bumped the `sqlglot` pin up a few
versions.~

Dropping the version bump from this PR, there are some breaking changes
for postgres, risingwave, and trino, looks like.
  • Loading branch information
gforsyth authored Feb 28, 2024
1 parent b5e6373 commit 809912c
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions ibis/backends/sql/dialects.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SQLite,
Trino,
)
from sqlglot.dialects.dialect import create_with_partitions_sql, rename_func
from sqlglot.dialects.dialect import rename_func

ClickHouse.Generator.TRANSFORMS |= {
sge.ArraySize: rename_func("length"),
Expand Down Expand Up @@ -184,23 +184,26 @@ class Generator(TSQL.Generator):


def _create_sql(self, expression: sge.Create) -> str:
# TODO: should we use CREATE PRIVATE instead? That will set an implicit
# lower bound of Oracle 18c
properties = expression.args.get("properties")
temporary = any(
isinstance(prop, sge.TemporaryProperty)
for prop in (properties.expressions if properties else [])
)

kind = expression.args["kind"]
if (obj := kind.upper()) in ("TABLE", "VIEW") and temporary:
if expression.expression:
return f"CREATE GLOBAL TEMPORARY {obj} {self.sql(expression, 'this')} AS {self.sql(expression, 'expression')}"
else:
# TODO: why does autocommit not work here? need to specify the ON COMMIT part...
return f"CREATE GLOBAL TEMPORARY {obj} {self.sql(expression, 'this')} ON COMMIT PRESERVE ROWS"

return create_with_partitions_sql(self, expression)
if kind.upper() in ("TABLE", "VIEW") and temporary:
# Force insertion of required "GLOBAL" keyword
expression_sql = self.create_sql(expression).replace(
"CREATE TEMPORARY", "CREATE GLOBAL TEMPORARY"
)
if expression.expression: # CREATE ... AS ...
return self.sql(expression_sql, "expression")
else: # CREATE ... ON COMMIT PRESERVE ROWS
# Autocommit does not work here for some reason so we append it manually
return self.sql(
expression_sql + " ON COMMIT PRESERVE ROWS",
"expression",
)
return self.create_sql(expression)


Oracle.Generator.TRANSFORMS |= {
Expand Down

0 comments on commit 809912c

Please sign in to comment.