Skip to content

Commit c3a25f1

Browse files
krzysztof-kwittcpcloud
authored andcommitted
feat(bigquery): support creating tables from in-memory tables
1 parent 4dfabbd commit c3a25f1

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

ibis/backends/bigquery/__init__.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -444,17 +444,22 @@ def create_table(
444444
schema: ibis.Schema | None = None,
445445
database: str | None = None,
446446
) -> None:
447-
if obj is not None:
448-
raise NotImplementedError(
449-
"Parameter obj is not supported for create_table method in BigQuery backend"
450-
)
451-
if schema is None:
452-
raise ValueError("Schema is required")
453-
454-
table_id = self._fully_qualified_name(name, database)
455-
bigquery_schema = ibis_schema_to_bigquery_schema(schema)
456-
table = bq.Table(table_id, schema=bigquery_schema)
457-
self.client.create_table(table)
447+
if obj is None and schema is None:
448+
raise ValueError("The schema or obj parameter is required")
449+
if schema is not None:
450+
table_id = self._fully_qualified_name(name, database)
451+
bigquery_schema = ibis_schema_to_bigquery_schema(schema)
452+
table = bq.Table(table_id, schema=bigquery_schema)
453+
self.client.create_table(table)
454+
else:
455+
project_id, dataset = self._parse_project_and_dataset(database)
456+
if isinstance(obj, pd.DataFrame):
457+
table = ibis.memtable(obj)
458+
else:
459+
table = obj
460+
sql_select = self.compile(table)
461+
table_ref = f"`{project_id}`.`{dataset}`.`{name}`"
462+
self.raw_sql(f'CREATE TABLE {table_ref} AS ({sql_select})')
458463

459464
def drop_table(
460465
self, name: str, database: str | None = None, force: bool = False

ibis/backends/tests/test_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,9 +731,7 @@ def test_agg_memory_table(con):
731731
),
732732
],
733733
)
734-
@pytest.mark.notimpl(
735-
["bigquery", "clickhouse", "dask", "datafusion", "pandas", "polars"]
736-
)
734+
@pytest.mark.notimpl(["clickhouse", "dask", "datafusion", "pandas", "polars"])
737735
def test_create_from_in_memory_table(backend, con, t):
738736
if backend.name() == "snowflake":
739737
pytest.skip("snowflake is unreliable here")

0 commit comments

Comments
 (0)