|
2 | 2 | :maxdepth: 0
|
3 | 3 | :hidden:
|
4 | 4 |
|
5 |
| -======== |
6 | 5 | BigQuery
|
7 | 6 | ========
|
8 | 7 |
|
9 |
| -Using the API |
10 |
| -============= |
11 |
| - |
12 | 8 | Authorization / Configuration
|
13 | 9 | -----------------------------
|
14 | 10 |
|
@@ -119,6 +115,15 @@ List datasets for the client's project:
|
119 | 115 | >>> [dataset.name for dataset in datasets]
|
120 | 116 | ['dataset_name']
|
121 | 117 |
|
| 118 | +Refresh metadata for a dataset (to pick up changes made by another client): |
| 119 | + |
| 120 | +.. doctest:: |
| 121 | + |
| 122 | + >>> from gcloud import bigquery |
| 123 | + >>> client = bigquery.Client() |
| 124 | + >>> dataset = client.dataset('dataset_name') |
| 125 | + >>> dataset.reload() # API request |
| 126 | + |
122 | 127 | Patch metadata for a dataset:
|
123 | 128 |
|
124 | 129 | .. doctest::
|
@@ -151,3 +156,83 @@ Delete a dataset:
|
151 | 156 | >>> client = bigquery.Client()
|
152 | 157 | >>> dataset = client.dataset('dataset_name')
|
153 | 158 | >>> dataset.delete() # API request
|
| 159 | + |
| 160 | + |
| 161 | +Tables |
| 162 | +------ |
| 163 | + |
| 164 | +Tables exist within datasets. List tables for the dataset: |
| 165 | + |
| 166 | +.. doctest:: |
| 167 | + |
| 168 | + >>> from gcloud import bigquery |
| 169 | + >>> client = bigquery.Client() |
| 170 | + >>> dataset = client.dataset('dataset_name') |
| 171 | + >>> tables, next_page_token = dataset.list_tables() # API request |
| 172 | + >>> [table.name for table in tables] |
| 173 | + ['table_name'] |
| 174 | + |
| 175 | +Create a table: |
| 176 | + |
| 177 | +.. doctest:: |
| 178 | + |
| 179 | + >>> from gcloud import bigquery |
| 180 | + >>> client = bigquery.Client() |
| 181 | + >>> dataset = client.dataset('dataset_name') |
| 182 | + >>> table = dataset.table(name='person_ages') |
| 183 | + >>> table.create() # API request |
| 184 | + |
| 185 | +Check for the existence of a table: |
| 186 | + |
| 187 | +.. doctest:: |
| 188 | + |
| 189 | + >>> from gcloud import bigquery |
| 190 | + >>> client = bigquery.Client() |
| 191 | + >>> dataset = client.dataset('dataset_name') |
| 192 | + >>> table = dataset.table(name='person_ages') |
| 193 | + >>> table.exists() # API request |
| 194 | + True |
| 195 | + |
| 196 | +Refresh metadata for a table (to pick up changes made by another client): |
| 197 | + |
| 198 | +.. doctest:: |
| 199 | + |
| 200 | + >>> from gcloud import bigquery |
| 201 | + >>> client = bigquery.Client() |
| 202 | + >>> dataset = client.dataset('dataset_name') |
| 203 | + >>> dataset.reload() # API request |
| 204 | + |
| 205 | +Patch specific properties for a table: |
| 206 | + |
| 207 | +.. doctest:: |
| 208 | + |
| 209 | + >>> from gcloud import bigquery |
| 210 | + >>> client = bigquery.Client() |
| 211 | + >>> dataset = client.dataset('dataset_name') |
| 212 | + >>> table = dataset.table(name='person_ages') |
| 213 | + >>> table.patch(friendly_name='Person Ages', |
| 214 | + ... description='Ages of persons') # API request |
| 215 | + |
| 216 | +Update all writable metadata for a table |
| 217 | + |
| 218 | +.. doctest:: |
| 219 | + |
| 220 | + >>> from gcloud import bigquery |
| 221 | + >>> from gcloud.bigquery import SchemaField |
| 222 | + >>> client = bigquery.Client() |
| 223 | + >>> dataset = client.dataset('dataset_name') |
| 224 | + >>> table = dataset.table(name='person_ages') |
| 225 | + >>> table.schema = [ |
| 226 | + ... SchemaField(name='full_name', type='string', mode='required'), |
| 227 | + ... SchemaField(name='age', type='int', mode='required)] |
| 228 | + >>> table.update() # API request |
| 229 | + |
| 230 | +Delete a table: |
| 231 | + |
| 232 | +.. doctest:: |
| 233 | + |
| 234 | + >>> from gcloud import bigquery |
| 235 | + >>> client = bigquery.Client() |
| 236 | + >>> dataset = client.dataset('dataset_name') |
| 237 | + >>> table = dataset.table(name='person_ages') |
| 238 | + >>> table.delete() # API request |
0 commit comments