Skip to content

Commit 2e15e7b

Browse files
authored
Merge pull request #2 from mxmzdlv/dbapi_official
Switch to official dbapi
2 parents e67de35 + d33f673 commit 2e15e7b

17 files changed

+1352
-342
lines changed

README.rst

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
DB-API interface and SQLAlchemy dialect for BigQuery. Inspired by `PyHive <https://github.com/dropbox/PyHive/>`_.
1+
SQLAlchemy dialect for BigQuery.
22

33

44
Usage
55
=====
66

7-
DB-API
8-
------
9-
.. code-block:: python
10-
11-
import bigquery
12-
cursor = bigquery.connect('project').cursor()
13-
cursor.execute('SELECT * FROM dataset.table LIMIT 10')
14-
print(cursor.fetchone())
15-
print(cursor.fetchall())
16-
17-
SQLAlchemy
18-
----------
197
.. code-block:: python
208
219
from sqlalchemy import *
@@ -25,15 +13,54 @@ SQLAlchemy
2513
logs = Table('dataset.table', MetaData(bind=engine), autoload=True)
2614
print(select([func.count('*')], from_obj=logs).scalar())
2715
16+
17+
Project
18+
_______
19+
`project` in `bigquery://project` is used to instantiate BigQuery client with the specific project ID. To infer project from the environment, use `bigquery://` – without `project`
20+
21+
Table names
22+
___________
23+
To query tables from non-default projects, use the following format for the table name: `project.dataset.table`, e.g.:
24+
25+
.. code-block:: python
26+
27+
sample_table = Table('bigquery-public-data.samples.natality')
28+
29+
Batch size
30+
__________
31+
32+
By default, `arraysize` is set to `5000`. `arraysize` is used to set the batch size for fetching results. To change it, pass `arraysize` to `create_engine()`:
33+
34+
.. code-block:: python
35+
36+
engine = create_engine('bigquery://project', arraysize=1000)
37+
38+
2839
Requirements
2940
============
3041

3142
Install using
3243

33-
- ``pip install git+https://github.com/mxmzdlv/pybigquery.git@master#egg=pybigquery``
44+
- ``pip install pybigquery``
45+
46+
47+
Testing
48+
============
49+
50+
Load sample tables:
51+
52+
./scripts/load_test_data.sh
53+
54+
This will create a dataset `test_pybigquery` with tables named `sample_one_row` and `sample`
55+
56+
Set up an environment and run tests:
57+
pyvenv .env
58+
source .env/bin/activate
59+
pip install -r dev_requirements.txt
60+
pytest
61+
3462

3563
TODO
3664
====
3765

3866
- Support for Record column type
39-
- Add a test suite

bigquery/__init__.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

bigquery/connection.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

bigquery/cursor.py

Lines changed: 0 additions & 143 deletions
This file was deleted.

bigquery/exceptions.py

Lines changed: 0 additions & 54 deletions
This file was deleted.

bigquery/formatter.py

Lines changed: 0 additions & 54 deletions
This file was deleted.

dev_requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
sqlalchemy>=1.1.9
2-
google-cloud>=0.25.0
2+
google-cloud-bigquery>=0.27.0
3+
4+
pytest==3.2.2

0 commit comments

Comments
 (0)