#!/usr/bin/env python # Copyright 2015, Google, Inc. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Command-line application to perform an synchronous query in BigQuery. For more information, see the README.md under /bigquery. """ import argparse import json from googleapiclient import discovery from oauth2client.client import GoogleCredentials # [START sync_query] def sync_query( bigquery, project_id, query, timeout=10000, num_retries=5, use_legacy_sql=False): query_data = { 'query': query, 'timeoutMs': timeout, # Set to False to use standard SQL syntax. See: # https://cloud.google.com/bigquery/sql-reference/enabling-standard-sql 'useLegacySql': use_legacy_sql } return bigquery.jobs().query( projectId=project_id, body=query_data).execute(num_retries=num_retries) # [END sync_query] # [START run] def main(project_id, query, timeout, num_r