Skip to content

Commit a99e992

Browse files
matthew29tangcopybara-github
authored andcommitted
feat: Add option to not overwrite table in Ray on Vertex BQ Write
PiperOrigin-RevId: 598997529
1 parent c708f87 commit a99e992

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

google/cloud/aiplatform/preview/vertex_ray/bigquery_datasource.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ def do_write(
179179
project_id: Optional[str] = None,
180180
dataset: Optional[str] = None,
181181
max_retry_cnt: Optional[int] = DEFAULT_MAX_RETRY_CNT,
182+
overwrite_table: Optional[bool] = True,
182183
) -> List[ObjectRef[WriteResult]]:
183184
def _write_single_block(
184185
block: Block, metadata: BlockMetadata, project_id: str, dataset: str
@@ -251,16 +252,22 @@ def _write_single_block(
251252
dataset_id = dataset.split(".", 1)[0]
252253
try:
253254
client.get_dataset(dataset_id)
254-
print(
255-
f"[Ray on Vertex AI]: Dataset {dataset_id} already exists."
256-
+ "The table will be overwritten if it already exists."
257-
)
258255
except exceptions.NotFound:
259256
client.create_dataset(f"{project_id}.{dataset_id}", timeout=30)
260257
print(f"[Ray on Vertex AI]: Created dataset {dataset_id}")
261258

262-
# Delete table if it already exists
263-
client.delete_table(f"{project_id}.{dataset}", not_found_ok=True)
259+
# Delete table if overwrite_table is True
260+
if overwrite_table:
261+
print(
262+
f"[Ray on Vertex AI]: Attempting to delete table {dataset}"
263+
+ " if it already exists since kwarg overwrite_table = True."
264+
)
265+
client.delete_table(f"{project_id}.{dataset}", not_found_ok=True)
266+
else:
267+
print(
268+
f"[Ray on Vertex AI]: The write will append to table {dataset}"
269+
+ " if it already exists since kwarg overwrite_table = False."
270+
)
264271

265272
print("[Ray on Vertex AI]: Writing", len(blocks), "blocks")
266273
for i in range(len(blocks)):

0 commit comments

Comments
 (0)