|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": 35, |
| 5 | + "execution_count": 1, |
6 | 6 | "metadata": {},
|
7 | 7 | "outputs": [],
|
8 | 8 | "source": [
|
|
30 | 30 | "This notebook demonstrates operations for building applications that integrate with BigQuery DataFrames. Follow these samples to build an integration that accepts a BigQuery DataFrames object or returns one."
|
31 | 31 | ]
|
32 | 32 | },
|
| 33 | + { |
| 34 | + "cell_type": "markdown", |
| 35 | + "metadata": {}, |
| 36 | + "source": [ |
| 37 | + "## Attributing requests initiated by BigQuery DataFrames\n", |
| 38 | + "\n", |
| 39 | + "Partners are required to attribute API calls to BigQuery and other Google APIs. Where possible, this should be done via the User-Agent string, but can also be done via job labels if your integration doesn't initialize the BigQuery DataFrames session.\n", |
| 40 | + "\n", |
| 41 | + "### Setting the User-Agent\n", |
| 42 | + "\n", |
| 43 | + "Set [`bpd.options.bigquery.application_name`](https://cloud.google.com/python/docs/reference/bigframes/latest/bigframes._config.bigquery_options.BigQueryOptions#bigframes__config_bigquery_options_BigQueryOptions_application_name) to a compliant string. Reach out to your Google Partner Engineering team contact for further instructions." |
| 44 | + ] |
| 45 | + }, |
33 | 46 | {
|
34 | 47 | "cell_type": "code",
|
35 |
| - "execution_count": 36, |
| 48 | + "execution_count": 2, |
36 | 49 | "metadata": {},
|
37 | 50 | "outputs": [],
|
| 51 | + "source": [ |
| 52 | + "import bigframes.pandas as bpd\n", |
| 53 | + "\n", |
| 54 | + "# Set this to the string informed by your Google Partner Engineering team contact.\n", |
| 55 | + "# Note: This can only be set once per session, so is most appropriate for partners\n", |
| 56 | + "# who provide a Python + BigQuery DataFrames environment to their customers.\n", |
| 57 | + "bpd.options.bigquery.application_name = \"notebook-samples/1.0.0 (GPN:notebook-samples)\"" |
| 58 | + ] |
| 59 | + }, |
| 60 | + { |
| 61 | + "cell_type": "code", |
| 62 | + "execution_count": 3, |
| 63 | + "metadata": {}, |
| 64 | + "outputs": [ |
| 65 | + { |
| 66 | + "name": "stderr", |
| 67 | + "output_type": "stream", |
| 68 | + "text": [ |
| 69 | + "/usr/local/google/home/swast/src/bigframes-2/bigframes/core/global_session.py:113: DefaultLocationWarning: No explicit location is set, so using location US for the session.\n", |
| 70 | + " return func(get_global_session(), *args, **kwargs)\n" |
| 71 | + ] |
| 72 | + } |
| 73 | + ], |
38 | 74 | "source": [
|
39 | 75 | "import bigframes.pandas as bpd\n",
|
40 | 76 | "\n",
|
|
47 | 83 | "}).set_index(\"index\")"
|
48 | 84 | ]
|
49 | 85 | },
|
| 86 | + { |
| 87 | + "cell_type": "markdown", |
| 88 | + "metadata": {}, |
| 89 | + "source": [ |
| 90 | + "### Setting the job label\n", |
| 91 | + "\n", |
| 92 | + "If your application works with customer-created BigQuery DataFrames objects, you might not be able to set the user-agent header because the session has already started (watch https://github.com/googleapis/python-bigquery-dataframes/issues/833 for updates on this limitation). Instead, attach a label to the jobs your application initiates, such as if you are performing `to_gbq()`on an existing DataFrame, as described below.\n", |
| 93 | + "\n", |
| 94 | + "Use `bpd.option_context()` so that the labels are only set during the operations your application performs." |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "cell_type": "code", |
| 99 | + "execution_count": 6, |
| 100 | + "metadata": {}, |
| 101 | + "outputs": [ |
| 102 | + { |
| 103 | + "data": { |
| 104 | + "text/html": [ |
| 105 | + "Query job eb7f3bbe-dda9-4d2f-b195-21de862d7055 is DONE. 0 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:eb7f3bbe-dda9-4d2f-b195-21de862d7055&page=queryresults\">Open Job</a>" |
| 106 | + ], |
| 107 | + "text/plain": [ |
| 108 | + "<IPython.core.display.HTML object>" |
| 109 | + ] |
| 110 | + }, |
| 111 | + "metadata": {}, |
| 112 | + "output_type": "display_data" |
| 113 | + } |
| 114 | + ], |
| 115 | + "source": [ |
| 116 | + "with bpd.option_context(\"compute.extra_query_labels\", {\"application-name\": \"notebook-samples\"}):\n", |
| 117 | + " table_id = df.to_gbq()" |
| 118 | + ] |
| 119 | + }, |
50 | 120 | {
|
51 | 121 | "cell_type": "markdown",
|
52 | 122 | "metadata": {},
|
|
58 | 128 | },
|
59 | 129 | {
|
60 | 130 | "cell_type": "code",
|
61 |
| - "execution_count": 37, |
| 131 | + "execution_count": 7, |
62 | 132 | "metadata": {},
|
63 | 133 | "outputs": [
|
64 | 134 | {
|
65 | 135 | "data": {
|
66 | 136 | "text/html": [
|
67 |
| - "Query job 00b5c727-f2bf-4265-be22-d7d505619db7 is DONE. 0 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:00b5c727-f2bf-4265-be22-d7d505619db7&page=queryresults\">Open Job</a>" |
| 137 | + "Query job 4ad50c3c-91d0-4fef-91f6-0a2c5a30c38f is DONE. 0 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:4ad50c3c-91d0-4fef-91f6-0a2c5a30c38f&page=queryresults\">Open Job</a>" |
68 | 138 | ],
|
69 | 139 | "text/plain": [
|
70 | 140 | "<IPython.core.display.HTML object>"
|
|
76 | 146 | {
|
77 | 147 | "data": {
|
78 | 148 | "text/plain": [
|
79 |
| - "'swast-scratch._63cfa399614a54153cc386c27d6c0c6fdb249f9e.bqdf20240327_43bbc4c64fb947f7b69db570a5641506'" |
| 149 | + "'swast-scratch._63cfa399614a54153cc386c27d6c0c6fdb249f9e.bqdf20240710_sessionf75568_9a045ff143db4f8ab2018994287020f3'" |
80 | 150 | ]
|
81 | 151 | },
|
82 |
| - "execution_count": 37, |
| 152 | + "execution_count": 7, |
83 | 153 | "metadata": {},
|
84 | 154 | "output_type": "execute_result"
|
85 | 155 | }
|
|
102 | 172 | },
|
103 | 173 | {
|
104 | 174 | "cell_type": "code",
|
105 |
| - "execution_count": 38, |
| 175 | + "execution_count": null, |
106 | 176 | "metadata": {},
|
107 | 177 | "outputs": [
|
108 | 178 | {
|
109 | 179 | "data": {
|
110 | 180 | "text/html": [
|
111 |
| - "Query job f9c39ac2-a428-45c9-bb3a-643fc62a1c5b is DONE. 0 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:f9c39ac2-a428-45c9-bb3a-643fc62a1c5b&page=queryresults\">Open Job</a>" |
| 181 | + "Query job 9e7d4b1a-d7fc-4599-bab4-40062c83288e is DONE. 0 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:9e7d4b1a-d7fc-4599-bab4-40062c83288e&page=queryresults\">Open Job</a>" |
112 | 182 | ],
|
113 | 183 | "text/plain": [
|
114 | 184 | "<IPython.core.display.HTML object>"
|
|
122 | 192 | "output_type": "stream",
|
123 | 193 | "text": [
|
124 | 194 | " index int_col float_col string_col\n",
|
125 |
| - "0 2 3 0.2500 c\n", |
126 |
| - "1 4 5 0.0625 e\n", |
| 195 | + "0 3 4 -0.1250 d\n", |
| 196 | + "1 1 2 -0.5000 b\n", |
127 | 197 | "2 0 1 1.0000 a\n",
|
128 |
| - "3 1 2 -0.5000 b\n", |
129 |
| - "4 3 4 -0.1250 d\n" |
| 198 | + "3 4 5 0.0625 e\n", |
| 199 | + "4 2 3 0.2500 c\n" |
130 | 200 | ]
|
131 | 201 | }
|
132 | 202 | ],
|
|
168 | 238 | },
|
169 | 239 | {
|
170 | 240 | "cell_type": "code",
|
171 |
| - "execution_count": 39, |
| 241 | + "execution_count": 8, |
172 | 242 | "metadata": {},
|
173 | 243 | "outputs": [
|
174 | 244 | {
|
175 | 245 | "data": {
|
176 | 246 | "text/html": [
|
177 |
| - "Query job ad53c7f2-e3bd-4667-b60b-b700c24b7a81 is DONE. 0 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:ad53c7f2-e3bd-4667-b60b-b700c24b7a81&page=queryresults\">Open Job</a>" |
| 247 | + "Query job 62db313e-7632-4dbb-8eff-5035d0e6c27e is DONE. 0 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:62db313e-7632-4dbb-8eff-5035d0e6c27e&page=queryresults\">Open Job</a>" |
178 | 248 | ],
|
179 | 249 | "text/plain": [
|
180 | 250 | "<IPython.core.display.HTML object>"
|
|
188 | 258 | "output_type": "stream",
|
189 | 259 | "text": [
|
190 | 260 | " index int_col float_col string_col\n",
|
191 |
| - "0 4 5 0.0625 e\n", |
192 |
| - "1 0 1 1.0000 a\n", |
193 |
| - "2 2 3 0.2500 c\n", |
194 |
| - "3 3 4 -0.1250 d\n", |
195 |
| - "4 1 2 -0.5000 b\n" |
| 261 | + "0 1 2 -0.5000 b\n", |
| 262 | + "1 3 4 -0.1250 d\n", |
| 263 | + "2 0 1 1.0000 a\n", |
| 264 | + "3 4 5 0.0625 e\n", |
| 265 | + "4 2 3 0.2500 c\n" |
196 | 266 | ]
|
197 | 267 | }
|
198 | 268 | ],
|
|
265 | 335 | },
|
266 | 336 | {
|
267 | 337 | "cell_type": "code",
|
268 |
| - "execution_count": 40, |
| 338 | + "execution_count": 9, |
269 | 339 | "metadata": {},
|
270 | 340 | "outputs": [
|
271 | 341 | {
|
272 | 342 | "data": {
|
273 | 343 | "text/html": [
|
274 |
| - "Query job 2aa7033c-c547-4ae2-a9aa-33272be82b9c is DONE. 0 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:2aa7033c-c547-4ae2-a9aa-33272be82b9c&page=queryresults\">Open Job</a>" |
| 344 | + "Query job 1cbd8898-97c7-419e-87af-b72a9432afb6 is DONE. 0 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:1cbd8898-97c7-419e-87af-b72a9432afb6&page=queryresults\">Open Job</a>" |
275 | 345 | ],
|
276 | 346 | "text/plain": [
|
277 | 347 | "<IPython.core.display.HTML object>"
|
|
283 | 353 | {
|
284 | 354 | "data": {
|
285 | 355 | "text/plain": [
|
286 |
| - "'swast-scratch._63cfa399614a54153cc386c27d6c0c6fdb249f9e.bqdf20240327_b484a3967fba4a41850f4eb21b4b3bd8'" |
| 356 | + "'swast-scratch._63cfa399614a54153cc386c27d6c0c6fdb249f9e.bqdf20240710_sessionf75568_58b9b6fc0c3349bf8d3dd6fb29ab5322'" |
287 | 357 | ]
|
288 | 358 | },
|
289 |
| - "execution_count": 40, |
| 359 | + "execution_count": 9, |
290 | 360 | "metadata": {},
|
291 | 361 | "output_type": "execute_result"
|
292 | 362 | }
|
|
308 | 378 | },
|
309 | 379 | {
|
310 | 380 | "cell_type": "code",
|
311 |
| - "execution_count": 41, |
| 381 | + "execution_count": 10, |
312 | 382 | "metadata": {},
|
313 | 383 | "outputs": [
|
314 | 384 | {
|
315 | 385 | "data": {
|
316 | 386 | "text/html": [
|
317 |
| - "Query job 1d489f94-2840-405e-9114-d439dcfcf7aa is DONE. 0 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:1d489f94-2840-405e-9114-d439dcfcf7aa&page=queryresults\">Open Job</a>" |
| 387 | + "Query job 40e54aa9-fad7-47c3-9bec-144f6c7106d8 is DONE. 0 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:40e54aa9-fad7-47c3-9bec-144f6c7106d8&page=queryresults\">Open Job</a>" |
318 | 388 | ],
|
319 | 389 | "text/plain": [
|
320 | 390 | "<IPython.core.display.HTML object>"
|
|
326 | 396 | {
|
327 | 397 | "data": {
|
328 | 398 | "text/plain": [
|
329 |
| - "'swast-scratch._63cfa399614a54153cc386c27d6c0c6fdb249f9e.bqdf20240327_d00699eeeed743b487c870dca5bcf23b'" |
| 399 | + "'swast-scratch._63cfa399614a54153cc386c27d6c0c6fdb249f9e.bqdf20240710_sessionf75568_cdb4f54063b0417a8309c462b70239fa'" |
330 | 400 | ]
|
331 | 401 | },
|
332 |
| - "execution_count": 41, |
| 402 | + "execution_count": 10, |
333 | 403 | "metadata": {},
|
334 | 404 | "output_type": "execute_result"
|
335 | 405 | }
|
|
357 | 427 | },
|
358 | 428 | {
|
359 | 429 | "cell_type": "code",
|
360 |
| - "execution_count": 42, |
| 430 | + "execution_count": 11, |
361 | 431 | "metadata": {},
|
362 | 432 | "outputs": [
|
363 | 433 | {
|
|
366 | 436 | "Dataset(DatasetReference('swast-scratch', 'my_dataset'))"
|
367 | 437 | ]
|
368 | 438 | },
|
369 |
| - "execution_count": 42, |
| 439 | + "execution_count": 11, |
370 | 440 | "metadata": {},
|
371 | 441 | "output_type": "execute_result"
|
372 | 442 | }
|
|
381 | 451 | },
|
382 | 452 | {
|
383 | 453 | "cell_type": "code",
|
384 |
| - "execution_count": 43, |
| 454 | + "execution_count": 12, |
385 | 455 | "metadata": {},
|
386 | 456 | "outputs": [
|
387 | 457 | {
|
388 | 458 | "data": {
|
389 | 459 | "text/html": [
|
390 |
| - "Query job 40977e60-97c3-4c93-89e2-d7334e5af71d is DONE. 0 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:40977e60-97c3-4c93-89e2-d7334e5af71d&page=queryresults\">Open Job</a>" |
| 460 | + "Query job 73cf9e04-d5fa-4765-827c-665f0e6b9e00 is DONE. 0 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:73cf9e04-d5fa-4765-827c-665f0e6b9e00&page=queryresults\">Open Job</a>" |
391 | 461 | ],
|
392 | 462 | "text/plain": [
|
393 | 463 | "<IPython.core.display.HTML object>"
|
|
399 | 469 | {
|
400 | 470 | "data": {
|
401 | 471 | "text/html": [
|
402 |
| - "Query job 81e35bb8-2e27-4a18-b596-15a7805331f0 is DONE. 270 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:81e35bb8-2e27-4a18-b596-15a7805331f0&page=queryresults\">Open Job</a>" |
| 472 | + "Query job b177eb37-197f-4732-8978-c74cccb36e01 is DONE. 270 Bytes processed. <a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=swast-scratch&j=bq:US:b177eb37-197f-4732-8978-c74cccb36e01&page=queryresults\">Open Job</a>" |
403 | 473 | ],
|
404 | 474 | "text/plain": [
|
405 | 475 | "<IPython.core.display.HTML object>"
|
|
523 | 593 | "[10 rows x 3 columns]"
|
524 | 594 | ]
|
525 | 595 | },
|
526 |
| - "execution_count": 43, |
| 596 | + "execution_count": 12, |
527 | 597 | "metadata": {},
|
528 | 598 | "output_type": "execute_result"
|
529 | 599 | }
|
|
627 | 697 | "name": "python",
|
628 | 698 | "nbconvert_exporter": "python",
|
629 | 699 | "pygments_lexer": "ipython3",
|
630 |
| - "version": "3.11.1" |
| 700 | + "version": "3.10.9" |
631 | 701 | }
|
632 | 702 | },
|
633 | 703 | "nbformat": 4,
|
|
0 commit comments