|
| 1 | +Ibis BigQuery backend |
| 2 | +===================== |
| 3 | + |
| 4 | +This package provides a [BigQuery](https://cloud.google.com/bigquery) backend |
| 5 | +for [Ibis](https://ibis-project.org/). |
| 6 | + |
| 7 | +Installation |
| 8 | +------------ |
| 9 | + |
| 10 | +Supported Python Versions |
| 11 | +^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 12 | +Python >= 3.7, < 3.10 |
| 13 | + |
| 14 | +Unsupported Python Versions |
| 15 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 16 | +Python < 3.7 |
| 17 | + |
| 18 | +Install with conda: |
| 19 | + |
| 20 | +.. code-block:: console |
| 21 | +
|
| 22 | + conda install -c conda-forge ibis-bigquery |
| 23 | +
|
| 24 | +Install with pip: |
| 25 | + |
| 26 | +.. code-block:: console |
| 27 | +
|
| 28 | + pip install ibis-bigquery |
| 29 | +
|
| 30 | +Usage |
| 31 | +----- |
| 32 | + |
| 33 | +Connecting to BigQuery |
| 34 | +^^^^^^^^^^^^^^^^^^^^^^ |
| 35 | + |
| 36 | +Recommended usage: |
| 37 | + |
| 38 | +.. code-block:: python |
| 39 | +
|
| 40 | + import ibis |
| 41 | +
|
| 42 | + conn = ibis.bigquery.connect( |
| 43 | + project_id=YOUR_PROJECT_ID, |
| 44 | + dataset_id='bigquery-public-data.stackoverflow' |
| 45 | + ) |
| 46 | +
|
| 47 | +Using this library directly: |
| 48 | + |
| 49 | +.. code-block:: python |
| 50 | +
|
| 51 | + import ibis |
| 52 | + import ibis_bigquery |
| 53 | +
|
| 54 | + conn = ibis_bigquery.Backend().connect( |
| 55 | + project_id=YOUR_PROJECT_ID, |
| 56 | + dataset_id='bigquery-public-data.stackoverflow' |
| 57 | + ) |
| 58 | +
|
| 59 | +Running a query |
| 60 | +^^^^^^^^^^^^^^^ |
| 61 | + |
| 62 | +.. code-block:: python |
| 63 | +
|
| 64 | + edu_table = conn.table( |
| 65 | + 'international_education', |
| 66 | + database='bigquery-public-data.world_bank_intl_education') |
| 67 | + edu_table = edu_table['value', 'year', 'country_code', 'indicator_code'] |
| 68 | +
|
| 69 | + country_table = conn.table( |
| 70 | + 'country_code_iso', |
| 71 | + database='bigquery-public-data.utility_us') |
| 72 | + country_table = country_table['country_name', 'alpha_3_code'] |
| 73 | +
|
| 74 | + expression = edu_table.join( |
| 75 | + country_table, |
| 76 | + [edu_table.country_code == country_table.alpha_3_code]) |
| 77 | +
|
| 78 | + print(conn.execute( |
| 79 | + expression[edu_table.year == 2016] |
| 80 | + # Adult literacy rate. |
| 81 | + [edu_table.indicator_code == 'SE.ADT.LITR.ZS'] |
| 82 | + .sort_by([ibis.desc(edu_table.value)]) |
| 83 | + .limit(20) |
| 84 | + )) |
0 commit comments