@@ -256,27 +256,13 @@ def _register_in_memory_table(self, op: ops.InMemoryTable) -> None:
256
256
# only register if we haven't already done so
257
257
if (name := op .name ) not in self .list_tables ():
258
258
quoted = self .compiler .quoted
259
- column_defs = [
260
- sg .exp .ColumnDef (
261
- this = sg .to_identifier (colname , quoted = quoted ),
262
- kind = self .compiler .type_mapper .from_ibis (typ ),
263
- constraints = (
264
- None
265
- if typ .nullable
266
- else [
267
- sg .exp .ColumnConstraint (
268
- kind = sg .exp .NotNullColumnConstraint ()
269
- )
270
- ]
271
- ),
272
- )
273
- for colname , typ in schema .items ()
274
- ]
275
259
276
260
ident = sg .to_identifier (name , quoted = quoted )
277
261
create_stmt = sg .exp .Create (
278
262
kind = "TABLE" ,
279
- this = sg .exp .Schema (this = ident , expressions = column_defs ),
263
+ this = sg .exp .Schema (
264
+ this = ident , expressions = schema .to_sqlglot (self .dialect )
265
+ ),
280
266
)
281
267
create_stmt_sql = create_stmt .sql (self .name )
282
268
@@ -366,27 +352,16 @@ def create_table(
366
352
else :
367
353
query = None
368
354
369
- type_mapper = self .compiler .type_mapper
370
- column_defs = [
371
- sge .ColumnDef (
372
- this = sg .to_identifier (colname , quoted = quoted ),
373
- kind = type_mapper .from_ibis (typ ),
374
- constraints = (
375
- None
376
- if typ .nullable
377
- else [sge .ColumnConstraint (kind = sge .NotNullColumnConstraint ())]
378
- ),
379
- )
380
- for colname , typ in (schema or table .schema ()).items ()
381
- ]
382
-
383
355
if overwrite :
384
356
temp_name = util .gen_name (f"{ self .name } _table" )
385
357
else :
386
358
temp_name = name
387
359
360
+ if not schema :
361
+ schema = table .schema ()
362
+
388
363
table = sg .table (temp_name , catalog = database , quoted = quoted )
389
- target = sge .Schema (this = table , expressions = column_defs )
364
+ target = sge .Schema (this = table , expressions = schema . to_sqlglot ( self . dialect ) )
390
365
391
366
create_stmt = sge .Create (kind = "TABLE" , this = target )
392
367
0 commit comments