Skip to content

Commit

Permalink
Move usage guides to their own docs. (#6238)
Browse files Browse the repository at this point in the history
* Move usage guides to their own docs.

The API reference links were buried behind pages of
code samples. Moving the how-to guides to their own
pages makes the documentation easier to navigate.

* Reorganize howto guides into sections. Add links to relevant methods.

* Move 'more examples' to bottom of the examples section.

Add section headers to Dataset how-to guides.

* Move howto to usage directory
  • Loading branch information
tswast authored Oct 19, 2018
1 parent 333c52a commit 9108464
Show file tree
Hide file tree
Showing 11 changed files with 481 additions and 446 deletions.
45 changes: 2 additions & 43 deletions bigquery/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,56 +74,15 @@ Windows
Example Usage
-------------

Create a dataset
~~~~~~~~~~~~~~~~
Perform a query
~~~~~~~~~~~~~~~

.. code:: python
from google.cloud import bigquery
from google.cloud.bigquery import Dataset
client = bigquery.Client()
dataset_ref = client.dataset('dataset_name')
dataset = Dataset(dataset_ref)
dataset.description = 'my dataset'
dataset = client.create_dataset(dataset) # API request
Load data from CSV
~~~~~~~~~~~~~~~~~~

.. code:: python
import csv
from google.cloud import bigquery
from google.cloud.bigquery import LoadJobConfig
from google.cloud.bigquery import SchemaField
client = bigquery.Client()
SCHEMA = [
SchemaField('full_name', 'STRING', mode='required'),
SchemaField('age', 'INTEGER', mode='required'),
]
table_ref = client.dataset('dataset_name').table('table_name')
load_config = LoadJobConfig()
load_config.skip_leading_rows = 1
load_config.schema = SCHEMA
# Contents of csv_file.csv:
# Name,Age
# Tim,99
with open('csv_file.csv', 'rb') as readable:
client.load_table_from_file(
readable, table_ref, job_config=load_config) # API request
Perform a query
~~~~~~~~~~~~~~~

.. code:: python
# Perform a query.
QUERY = (
'SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013` '
Expand Down
Loading

0 comments on commit 9108464

Please sign in to comment.