Skip to content

Commit

Permalink
Replace google.datalab with google.cloud for bigquery in notebooks
Browse files Browse the repository at this point in the history
Using google-cloud-bigquery because datalab in python3.7 yields syntax
error (see googledatalab/pydatalab#711)
  • Loading branch information
mark-velez committed Dec 27, 2019
1 parent 54f1497 commit 2036e2b
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions data_steward/notebooks/bq.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import os
from google.cloud import bigquery

from google import datalab
from google.datalab import bigquery

# In Windows we found that datalab project_id resolution prioritizes an obscure config.json over env vars
# APPLICATION_ID or PROJECT_ID. This explicitly sets it to env var PROJECT_ID.
datalab.Context.default().set_project_id(project_id=os.getenv('PROJECT_ID'))
client = bigquery.Client()


# Wrapper so we can more easily swap to whatever client library we prefer in the future
def query(q, use_cache=False):
return bigquery.Query(q).execute(output_options=bigquery.QueryOutput.dataframe(use_cache=use_cache)).result()
query_job_config = bigquery.job.QueryJobConfig(use_query_cache=use_cache)
return client.query(q, job_config=query_job_config).to_dataframe()

0 comments on commit 2036e2b

Please sign in to comment.