11from __future__ import annotations
22
33import json
4+ from typing import TYPE_CHECKING
45
56import sqlglot as sg
67
78import ibis .expr .schema as sch
89from ibis .backends .sql .datatypes import ImpalaType
910from ibis .backends .sql .ddl import DDL , DML , CreateDDL , DropFunction , DropObject
1011
12+ if TYPE_CHECKING :
13+ from collections .abc import Iterable
14+
1115
1216class ImpalaBase :
1317 dialect = "hive"
@@ -51,8 +55,7 @@ def __init__(self, name, path=None, can_exist=False):
5155 def compile (self ):
5256 name = self .quote (self .name )
5357
54- create_decl = "CREATE DATABASE"
55- create_line = f"{ create_decl } { self ._if_exists ()} { name } "
58+ create_line = f"CREATE DATABASE { self ._if_exists ()} { name } "
5659 if self .path is not None :
5760 create_line += f"\n LOCATION '{ self .path } '"
5861
@@ -405,15 +408,16 @@ class PartitionProperties(ImpalaBase, DDL):
405408
406409 def __init__ (
407410 self ,
408- table ,
411+ # Must already be fully qualified, eg `my_db`.`my_table`
412+ table_location : str ,
409413 partition ,
410414 partition_schema ,
411415 location = None ,
412416 format = None ,
413417 tbl_properties = None ,
414418 serde_properties = None ,
415419 ):
416- self .table = table
420+ self .table_location = table_location
417421 self .location = location
418422 self .format = self .sanitize_format (format )
419423 self .tbl_properties = tbl_properties
@@ -427,7 +431,7 @@ def compile(self):
427431 part = f"{ self ._command } { part } "
428432
429433 props = self ._format_properties ()
430- return f"ALTER TABLE { self .table } { part } { props } "
434+ return f"ALTER TABLE { self .table_location } { part } { props } "
431435
432436 def _format_properties (self ):
433437 tokens = []
@@ -551,6 +555,7 @@ def __init__(
551555 self ,
552556 table_name ,
553557 select_expr ,
558+ columns : Iterable [str ],
554559 database = None ,
555560 partition = None ,
556561 partition_schema = None ,
@@ -559,6 +564,7 @@ def __init__(
559564 self .table_name = table_name
560565 self .database = database
561566 self .select = select_expr
567+ self .columns = columns
562568
563569 self .partition = partition
564570 self .partition_schema = partition_schema
@@ -577,6 +583,7 @@ def compile(self):
577583 else :
578584 partition = ""
579585
586+ columns_str = "(" + ", " .join (self .quote (col ) for col in self .columns ) + ")"
580587 select_query = self .select
581588 scoped_name = self .scoped_name (self .table_name , self .database )
582- return f"{ cmd } { scoped_name } { partition } \n { select_query } "
589+ return f"{ cmd } { scoped_name } { columns_str } { partition } \n { select_query } "
0 commit comments