Skip to content

Commit 5fc062b

Browse files
authored
Merge branch 'main' into bigquery-approx-median
2 parents cd38220 + e5c660c commit 5fc062b

21 files changed

Lines changed: 73 additions & 54 deletions

File tree

ibis/backends/impala/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from ibis.backends.sql import SQLBackend
3232

3333
if TYPE_CHECKING:
34-
from collections.abc import Mapping
34+
from collections.abc import Iterable, Mapping
3535
from pathlib import Path
3636
from urllib.parse import ParseResult
3737

@@ -708,14 +708,14 @@ def _wrap_new_table(self, name, database):
708708

709709
def insert(
710710
self,
711-
name,
711+
name: str,
712712
/,
713-
obj=None,
713+
obj: ir.Table | Any,
714714
*,
715-
database=None,
716-
overwrite=False,
717-
partition=None,
718-
validate=True,
715+
database: str | tuple[str, str] | None = None,
716+
overwrite: bool = False,
717+
partition: Iterable[str] | dict[str, Any] | None = None,
718+
validate: bool = True,
719719
) -> None:
720720
"""Insert into an Impala table.
721721
@@ -733,8 +733,8 @@ def insert(
733733
For partitioned tables, indicate the partition that's being
734734
inserted into, either with an ordered list of partition keys or a
735735
dict of partition field name to value. For example for the
736-
partition (year=2007, month=7), this can be either (2007, 7) or
737-
{'year': 2007, 'month': 7}.
736+
partition (year=2007, region='CA'), this can be either (2007, 'CA') or
737+
{'year': 2007, 'region': 'CA'}.
738738
validate
739739
If True, do more rigorous validation that schema of table being
740740
inserted is compatible with the existing table
@@ -794,6 +794,7 @@ def insert(
794794
statement = ddl.InsertSelect(
795795
self._fully_qualified_name(name, database),
796796
self.compile(obj),
797+
obj.columns,
797798
partition=partition,
798799
partition_schema=partition_schema,
799800
overwrite=overwrite,

ibis/backends/impala/ddl.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
from __future__ import annotations
22

33
import json
4+
from typing import TYPE_CHECKING
45

56
import sqlglot as sg
67

78
import ibis.expr.schema as sch
89
from ibis.backends.sql.datatypes import ImpalaType
910
from ibis.backends.sql.ddl import DDL, DML, CreateDDL, DropFunction, DropObject
1011

12+
if TYPE_CHECKING:
13+
from collections.abc import Iterable
14+
1115

1216
class 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"\nLOCATION '{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}"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ALTER TABLE tbl ADD PARTITION (year=2007, month=4)
1+
ALTER TABLE tbl ADD PARTITION (`year`=2007, `region`='CA')
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ALTER TABLE tbl ADD PARTITION (foo=5, bar="qux")
1+
ALTER TABLE tbl ADD PARTITION (`foo`=5, `bar`='qux')
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
ALTER TABLE tbl ADD PARTITION (year=2007, month=4)
1+
ALTER TABLE tbl ADD PARTITION (`year`=2007, `region`='CA')
22
LOCATION '/users/foo/my-data'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
ALTER TABLE tbl PARTITION (year=2007, month=4)
1+
ALTER TABLE tbl PARTITION (`year`=2007, `region`='CA')
22
SET LOCATION '/users/foo/my-data'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
ALTER TABLE tbl PARTITION (year=2007, month=4)
1+
ALTER TABLE tbl PARTITION (`year`=2007, `region`='CA')
22
SET FILEFORMAT AVRO

ibis/backends/impala/tests/snapshots/test_ddl_compilation/test_alter_partition_properties/out3.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ALTER TABLE tbl PARTITION (year=2007, month=4)
1+
ALTER TABLE tbl PARTITION (`year`=2007, `region`='CA')
22
SET TBLPROPERTIES (
33
'bar'='2',
44
'foo'='1'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ALTER TABLE tbl PARTITION (year=2007, month=4)
1+
ALTER TABLE tbl PARTITION (`year`=2007, `region`='CA')
22
SET SERDEPROPERTIES (
33
'baz'='3'
44
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
ALTER TABLE tbl PARTITION (year=2007, month=4)
1+
ALTER TABLE tbl PARTITION (`year`=2007, `region`='CA')
22
SET LOCATION '/users/foo/my-data'

0 commit comments

Comments
 (0)