Exemplo n.º 1
0
def read_from_db(query: str) -> pd.DataFrame:
    credentials, project_id = google.auth.default(
        scopes=["https://www.googleapis.com/auth/cloud-platform"]
    )
    client = bigquery.Client(credentials=credentials, project=project_id)
    bqstorage_client = bigquery_storage.BigQueryStorageClient(credentials=credentials)
    df = client.query(query).to_dataframe(bqstorage_client=bqstorage_client)

    return df
Exemplo n.º 2
0
def _make_bqstorage_client(use_bqstorage_api, credentials):
    if not use_bqstorage_api:
        return None

    if bigquery_storage is None:
        raise ImportError(
            "Install the google-cloud-bigquery-storage and fastavro/pyarrow "
            "packages to use the BigQuery Storage API.")

    import google.api_core.gapic_v1.client_info
    import pandas

    client_info = google.api_core.gapic_v1.client_info.ClientInfo(
        user_agent="pandas-{}".format(pandas.__version__))
    return bigquery_storage.BigQueryStorageClient(credentials=credentials,
                                                  client_info=client_info)