Skip to content
This repository was archived by the owner on Dec 22, 2022. It is now read-only.

Commit 8f94063

Browse files
committed
Merge pull request #1 from tylertreat/master
Merging in remote master
2 parents a4461c1 + 97a55bc commit 8f94063

16 files changed

+2367
-622
lines changed

README.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Simple Python client for interacting with Google BigQuery.
55

66
This client provides an API for retrieving and inserting BigQuery data by wrapping Google's low-level API client library. It also provides facilities that make it convenient to access data that is tied to an App Engine appspot, such as request logs.
77

8+
[Documentation](http://tylertreat.github.io/BigQuery-Python/)
9+
810
# Installation
911

1012
`pip install bigquery-python`
@@ -29,7 +31,7 @@ client = get_client(project_id, service_account=service_account,
2931
# JSON key provided by Google
3032
json_key = 'key.json'
3133

32-
client = get_client(project_id, json_key_file=json_key, readonly=True)
34+
client = get_client(json_key_file=json_key, readonly=True)
3335

3436
# Submit an async query.
3537
job_id, _results = client.query('SELECT * FROM dataset.my_table LIMIT 1000')
@@ -99,13 +101,32 @@ conditions = [
99101
}
100102
]
101103

104+
grouping = ['Timestamp']
105+
106+
having = [
107+
{
108+
'field': 'Timestamp',
109+
'type': 'INTEGER',
110+
'comparators': [
111+
{
112+
'condition': '==',
113+
'negate': False,
114+
'value': 1399478981
115+
}
116+
]
117+
}
118+
]
119+
120+
order_by ={'fields': ['Timestamp'], 'direction': 'desc'}
121+
102122
query = render_query(
103123
'dataset',
104124
['table'],
105125
select=selects,
106126
conditions=conditions,
107-
groupings=['Timestamp'],
108-
order_by={'field': 'Timestamp', 'direction': 'desc'}
127+
groupings=grouping,
128+
having=having,
129+
order_by=order_by
109130
)
110131

111132
job_id, _ = client.query(query)
@@ -168,6 +189,34 @@ try:
168189
except BigQueryTimeoutException:
169190
print "Timeout"
170191

192+
# write to permanent table with UDF in query string
193+
external_udf_uris = ["gs://bigquery-sandbox-udf/url_decode.js"]
194+
query = """SELECT requests, title
195+
FROM
196+
urlDecode(
197+
SELECT
198+
title, sum(requests) AS num_requests
199+
FROM
200+
[fh-bigquery:wikipedia.pagecounts_201504]
201+
WHERE language = 'fr'
202+
GROUP EACH BY title
203+
)
204+
WHERE title LIKE '%ç%'
205+
ORDER BY requests DESC
206+
LIMIT 100
207+
"""
208+
job = client.write_to_table(
209+
query,
210+
'dataset',
211+
'table',
212+
external_udf_uris=external_udf_uris
213+
)
214+
215+
try:
216+
job_resource = client.wait_for_job(job, timeout=60)
217+
print job_resource
218+
except BigQueryTimeoutException:
219+
print "Timeout"
171220

172221
# write to temporary table
173222
job = client.write_to_table('SELECT * FROM dataset.original_table LIMIT 100')
@@ -176,6 +225,8 @@ try:
176225
print job_resource
177226
except BigQueryTimeoutException:
178227
print "Timeout"
228+
229+
179230
```
180231

181232
# Import data from Google cloud storage

bigquery/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from __future__ import absolute_import
2+
3+
from .version import __version__
4+
25
from .client import get_client
36
from .client import (
47
BIGQUERY_SCOPE,

0 commit comments

Comments
 (0)