-
-
Save pingsutw/56d56ce5aea997586cce30ab659859fa to your computer and use it in GitHub Desktop.
Convert BigQuery table to structured dataset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import pyarrow | |
from flytekit import task, StructuredDataset | |
import os | |
@task | |
def pandas_dataframe_to_bq_table() -> StructuredDataset: | |
df = pd.DataFrame({"Name": ["Tom", "Joseph"], "Age": [20, 22]}) | |
return StructuredDataset(dataframe=df, uri='bq://flyte-test-340607.dataset.test1') | |
@task | |
def bq_table_to_dataframe(sd: StructuredDataset) -> pd.DataFrame: | |
# convert to pandas dataframe | |
return sd.open(pd.DataFrame).all() | |
# we could also convert it to arrow table | |
# return sd.open(pyarrow.table).all() | |
if __name__ == "__main__": | |
bq_table_to_dataframe(sd=StructuredDataset(uri="bq://flyte-test-340607.dataset.test1")) | |
pandas_dataframe_to_bq_table() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment