29
loading...
This website collects cookies to deliver better user experience
In this post, we assume that you have all your customer data stored in Google BigQuery.
If you are interested in learning more about how to get your data from your data sources into tools like Google BigQuery and other data warehouse solutions in real-time, you should explore the Customer Data Infrastructure tools like RudderStack.
For this post, we assume that you already have a Python development environment set up. If not, we highly recommend you refer to the Python Development Environment Setup Guide.
pip install --upgrade google-cloud-bigquery
from google.cloud import bigquery
from google.oauth2 import service_account
credentials = service_account.Credentials.from_service_account_file(
'path/to/file.json')
project_id = 'my-bq'
client = bigquery.Client(credentials= credentials,project=project_id)
project_id
and the location of your JSON key file by replacing the 'path/to/file.json'
with the actual path to the locally stored JSON file.In Google BigQuery, the project is a top-level container and provides default access control across all the datasets.
Query_Job
instance containing the results.query_job = client.query("""
SELECT *
FROM dataset.my_table
LIMIT 1000 """)
results = query_job.result() # Wait for the job to complete.
job_config.use_legacy_sql = True
query_job = client.query("""
SELECT *
FROM dataset.my_table
LIMIT 1000""", job_config = job_config)
results = query_job.result() # Wait for the job to complete.
install.packages("bigrquery")
Note that this authorization needs to be done only once. The subsequent requests will automatically refresh the access credentials.
query_exec
with your project ID and query string.#import library
library(bigrquery)
#Your project ID here
project_id <- "your-project-id" # Your project ID goes here
#Sample query
sql_string <- "SELECT * FROM dataset.my_table LIMIT 1000"
#Execute the query and storing the result
query_results <- query_exec(sql_string, project = project_id, useLegacySql = FALSE)
useLegacySql
to TRUE
in your query_exec
function.