Skip to content

Commit 599c404

Browse files
add config option for default write engine
1 parent 8c3c149 commit 599c404

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

bigframes/_config/compute_options.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""Options for displaying objects."""
1616

1717
import dataclasses
18-
from typing import Any, Dict, Optional
18+
from typing import Any, Dict, Literal, Optional
1919

2020

2121
@dataclasses.dataclass
@@ -140,6 +140,17 @@ class ComputeOptions:
140140
int | None: Number of rows, if set.
141141
"""
142142

143+
default_write_engine: Literal["bigquery_load", "bigquery_write"] = "bigquery_write"
144+
"""
145+
Sets the default write engine for uploadin local data to bigquery.
146+
147+
The two options are "bigquery_load" or "bigquery_write". "bigquery_write" is generally
148+
preferred as it is faster, but "bigquery_load" may be used if bigquery write api is unavailable.
149+
150+
Returns:
151+
str: "bigquery_load" or "bigquery_write"
152+
"""
153+
143154
semantic_ops_confirmation_threshold: Optional[int] = 0
144155
"""
145156
Deprecated.

bigframes/session/bq_caching_executor.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,16 @@ def _upload_local_data(self, local_table: local_data.ManagedArrowTable):
598598
# Might be better as a queue and a worker thread
599599
with self._upload_lock:
600600
if local_table not in self.cache._uploaded_local_data:
601-
uploaded = self.loader.write_data(
602-
local_table, bigframes.core.guid.generate_guid()
603-
)
601+
engine = bigframes.options.compute.default_write_engine
602+
if engine == "bigquery_load":
603+
uploaded = self.loader.load_data(
604+
local_table, bigframes.core.guid.generate_guid()
605+
)
606+
else:
607+
assert engine == "bigquery_write"
608+
uploaded = self.loader.write_data(
609+
local_table, bigframes.core.guid.generate_guid()
610+
)
604611
self.cache.cache_remote_replacement(local_table, uploaded)
605612

606613
def _execute_plan_gbq(

tests/system/small/test_large_local_data.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@
2323
large_dataframe.index = large_dataframe.index.astype("Int64")
2424

2525

26+
@pytest.mark.parametrize(
27+
("default_write_engine",),
28+
[
29+
pytest.param("bigquery_load"),
30+
pytest.param("bigquery_write"),
31+
],
32+
)
33+
def test_read_pandas_config_default_engine(
34+
session: bigframes.Session, default_write_engine
35+
):
36+
pytest.importorskip("pandas", minversion="2.0.0")
37+
with bigframes.option_context(
38+
"compute.default_write_engine",
39+
default_write_engine,
40+
):
41+
bf_df = session.read_pandas(large_dataframe)
42+
43+
assert_frame_equal(large_dataframe, bf_df.to_pandas())
44+
45+
2646
def test_read_pandas_defer_noop(session: bigframes.Session):
2747
pytest.importorskip("pandas", minversion="2.0.0")
2848
bf_df = session.read_pandas(large_dataframe, write_engine="_deferred")

0 commit comments

Comments
 (0)