1
1
from __future__ import annotations
2
2
3
- import atexit
4
3
import contextlib
5
4
import datetime
6
5
import re
@@ -42,7 +41,6 @@ class Backend(SQLBackend, CanCreateDatabase, CanCreateSchema):
42
41
compiler = sc .exasol .compiler
43
42
supports_temporary_tables = False
44
43
supports_create_or_replace = False
45
- supports_in_memory_tables = False
46
44
supports_python_udfs = False
47
45
48
46
@property
@@ -278,14 +276,15 @@ def process_item(item: Any):
278
276
with self ._safe_raw_sql (create_stmt_sql ):
279
277
if not df .empty :
280
278
self .con .ext .insert_multi (name , rows )
281
- atexit .register (self ._clean_up_tmp_table , ident )
282
279
283
- def _clean_up_tmp_table (self , ident : sge . Identifier ) -> None :
284
- with self . _safe_raw_sql (
285
- sge .Drop (kind = "TABLE" , this = ident , exists = True , cascade = True )
286
- ):
280
+ def _clean_up_tmp_table (self , name : str ) -> None :
281
+ ident = sg . to_identifier ( name , quoted = self . compiler . quoted )
282
+ sql = sge .Drop (kind = "TABLE" , this = ident , exists = True , cascade = True )
283
+ with self . _safe_raw_sql ( sql ):
287
284
pass
288
285
286
+ _finalize_memtable = _clean_up_tmp_table
287
+
289
288
def create_table (
290
289
self ,
291
290
name : str ,
@@ -334,11 +333,9 @@ def create_table(
334
333
335
334
quoted = self .compiler .quoted
336
335
337
- temp_memtable_view = None
338
336
if obj is not None :
339
337
if not isinstance (obj , ir .Expr ):
340
338
table = ibis .memtable (obj )
341
- temp_memtable_view = table .op ().name
342
339
else :
343
340
table = obj
344
341
@@ -356,31 +353,29 @@ def create_table(
356
353
if not schema :
357
354
schema = table .schema ()
358
355
359
- table = sg .table (temp_name , catalog = database , quoted = quoted )
360
- target = sge .Schema (this = table , expressions = schema .to_sqlglot (self .dialect ))
356
+ table_expr = sg .table (temp_name , catalog = database , quoted = quoted )
357
+ target = sge .Schema (
358
+ this = table_expr , expressions = schema .to_sqlglot (self .dialect )
359
+ )
361
360
362
361
create_stmt = sge .Create (kind = "TABLE" , this = target )
363
362
364
363
this = sg .table (name , catalog = database , quoted = quoted )
365
364
with self ._safe_raw_sql (create_stmt ):
366
365
if query is not None :
367
366
self .con .execute (
368
- sge .Insert (this = table , expression = query ).sql (self .name )
367
+ sge .Insert (this = table_expr , expression = query ).sql (self .name )
369
368
)
370
369
371
370
if overwrite :
372
371
self .con .execute (
373
372
sge .Drop (kind = "TABLE" , this = this , exists = True ).sql (self .name )
374
373
)
375
374
self .con .execute (
376
- f"RENAME TABLE { table .sql (self .name )} TO { this .sql (self .name )} "
375
+ f"RENAME TABLE { table_expr .sql (self .name )} TO { this .sql (self .name )} "
377
376
)
378
377
379
378
if schema is None :
380
- # Clean up temporary memtable if we've created one
381
- # for in-memory reads
382
- if temp_memtable_view is not None :
383
- self .drop_table (temp_memtable_view )
384
379
return self .table (name , database = database )
385
380
386
381
# preserve the input schema if it was provided
0 commit comments