Skip to content

Commit 95d1b34

Browse files
authored
Set project for the bigquery client (#3330)
Signed-off-by: Kevin Su <[email protected]>
1 parent 49755b6 commit 95d1b34

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ coverage.xml
4040
# Version file is auto-generated by setuptools_scm
4141
flytekit/_version.py
4242
testing
43+
.flyte/
4344
.claude/

flytekit/types/structured/bigquery.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,26 @@
2525

2626

2727
def _write_to_bq(structured_dataset: StructuredDataset):
28-
table_id = typing.cast(str, structured_dataset.uri).split("://", 1)[1].replace(":", ".")
29-
client = bigquery.Client()
28+
"""Write a StructuredDataset to BigQuery using its URI (format: bq://project:dataset.table)."""
29+
uri = structured_dataset.uri
30+
if uri is None:
31+
raise RuntimeError(
32+
"Missing StructuredDataset URI for BigQuery. Expected format: bq://<project>:<dataset>.<table>"
33+
)
34+
35+
# Extract project and BigQuery destination (dataset.table)
36+
project = uri.removeprefix("bq://").split(":", 1)[0]
37+
# Convert project:dataset.table -> project.dataset.table
38+
dst = uri.split("://", 1)[1].replace(":", ".")
39+
40+
client = bigquery.Client(project=project)
41+
42+
# Convert Arrow table to pandas DataFrame if needed
3043
df = structured_dataset.dataframe
3144
if isinstance(df, pa.Table):
3245
df = df.to_pandas()
33-
client.load_table_from_dataframe(df, table_id)
46+
47+
client.load_table_from_dataframe(df, dst)
3448

3549

3650
def _read_from_bq(

0 commit comments

Comments
 (0)