Path: blob/main/docs/source/src/python/user-guide/io/bigquery.py
7890 views
"""1# --8<-- [start:read]2import polars as pl3from google.cloud import bigquery45client = bigquery.Client()67# Perform a query.8QUERY = (9'SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013` '10'WHERE state = "TX" '11'LIMIT 100')12query_job = client.query(QUERY) # API request13rows = query_job.result() # Waits for query to finish1415df = pl.from_arrow(rows.to_arrow())16# --8<-- [end:read]1718# --8<-- [start:write]19from google.cloud import bigquery2021client = bigquery.Client()2223# Write DataFrame to stream as parquet file; does not hit disk24with io.BytesIO() as stream:25df.write_parquet(stream)26stream.seek(0)27parquet_options = bigquery.ParquetOptions()28parquet_options.enable_list_inference = True29job = client.load_table_from_file(30stream,31destination='tablename',32project='projectname',33job_config=bigquery.LoadJobConfig(34source_format=bigquery.SourceFormat.PARQUET,35parquet_options=parquet_options,36),37)38job.result() # Waits for the job to complete39# --8<-- [end:write]40"""414243