Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move usage guides to their own docs. #6238

Merged
merged 4 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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