Skip to content

Commit d7b333f

Browse files
authored
docs: add partner attribution steps to integrations sample notebook (#835)
1 parent 0d24f73 commit d7b333f

File tree

1 file changed

+104
-34
lines changed

1 file changed

+104
-34
lines changed

notebooks/dataframes/integrations.ipynb

+104-34
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 35,
5+
"execution_count": 1,
66
"metadata": {},
77
"outputs": [],
88
"source": [
@@ -30,11 +30,47 @@
3030
"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."
3131
]
3232
},
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+
},
3346
{
3447
"cell_type": "code",
35-
"execution_count": 36,
48+
"execution_count": 2,
3649
"metadata": {},
3750
"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+
],
3874
"source": [
3975
"import bigframes.pandas as bpd\n",
4076
"\n",
@@ -47,6 +83,40 @@
4783
"}).set_index(\"index\")"
4884
]
4985
},
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+
},
50120
{
51121
"cell_type": "markdown",
52122
"metadata": {},
@@ -58,13 +128,13 @@
58128
},
59129
{
60130
"cell_type": "code",
61-
"execution_count": 37,
131+
"execution_count": 7,
62132
"metadata": {},
63133
"outputs": [
64134
{
65135
"data": {
66136
"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>"
68138
],
69139
"text/plain": [
70140
"<IPython.core.display.HTML object>"
@@ -76,10 +146,10 @@
76146
{
77147
"data": {
78148
"text/plain": [
79-
"'swast-scratch._63cfa399614a54153cc386c27d6c0c6fdb249f9e.bqdf20240327_43bbc4c64fb947f7b69db570a5641506'"
149+
"'swast-scratch._63cfa399614a54153cc386c27d6c0c6fdb249f9e.bqdf20240710_sessionf75568_9a045ff143db4f8ab2018994287020f3'"
80150
]
81151
},
82-
"execution_count": 37,
152+
"execution_count": 7,
83153
"metadata": {},
84154
"output_type": "execute_result"
85155
}
@@ -102,13 +172,13 @@
102172
},
103173
{
104174
"cell_type": "code",
105-
"execution_count": 38,
175+
"execution_count": null,
106176
"metadata": {},
107177
"outputs": [
108178
{
109179
"data": {
110180
"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>"
112182
],
113183
"text/plain": [
114184
"<IPython.core.display.HTML object>"
@@ -122,11 +192,11 @@
122192
"output_type": "stream",
123193
"text": [
124194
" 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",
127197
"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"
130200
]
131201
}
132202
],
@@ -168,13 +238,13 @@
168238
},
169239
{
170240
"cell_type": "code",
171-
"execution_count": 39,
241+
"execution_count": 8,
172242
"metadata": {},
173243
"outputs": [
174244
{
175245
"data": {
176246
"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>"
178248
],
179249
"text/plain": [
180250
"<IPython.core.display.HTML object>"
@@ -188,11 +258,11 @@
188258
"output_type": "stream",
189259
"text": [
190260
" 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"
196266
]
197267
}
198268
],
@@ -265,13 +335,13 @@
265335
},
266336
{
267337
"cell_type": "code",
268-
"execution_count": 40,
338+
"execution_count": 9,
269339
"metadata": {},
270340
"outputs": [
271341
{
272342
"data": {
273343
"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>"
275345
],
276346
"text/plain": [
277347
"<IPython.core.display.HTML object>"
@@ -283,10 +353,10 @@
283353
{
284354
"data": {
285355
"text/plain": [
286-
"'swast-scratch._63cfa399614a54153cc386c27d6c0c6fdb249f9e.bqdf20240327_b484a3967fba4a41850f4eb21b4b3bd8'"
356+
"'swast-scratch._63cfa399614a54153cc386c27d6c0c6fdb249f9e.bqdf20240710_sessionf75568_58b9b6fc0c3349bf8d3dd6fb29ab5322'"
287357
]
288358
},
289-
"execution_count": 40,
359+
"execution_count": 9,
290360
"metadata": {},
291361
"output_type": "execute_result"
292362
}
@@ -308,13 +378,13 @@
308378
},
309379
{
310380
"cell_type": "code",
311-
"execution_count": 41,
381+
"execution_count": 10,
312382
"metadata": {},
313383
"outputs": [
314384
{
315385
"data": {
316386
"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>"
318388
],
319389
"text/plain": [
320390
"<IPython.core.display.HTML object>"
@@ -326,10 +396,10 @@
326396
{
327397
"data": {
328398
"text/plain": [
329-
"'swast-scratch._63cfa399614a54153cc386c27d6c0c6fdb249f9e.bqdf20240327_d00699eeeed743b487c870dca5bcf23b'"
399+
"'swast-scratch._63cfa399614a54153cc386c27d6c0c6fdb249f9e.bqdf20240710_sessionf75568_cdb4f54063b0417a8309c462b70239fa'"
330400
]
331401
},
332-
"execution_count": 41,
402+
"execution_count": 10,
333403
"metadata": {},
334404
"output_type": "execute_result"
335405
}
@@ -357,7 +427,7 @@
357427
},
358428
{
359429
"cell_type": "code",
360-
"execution_count": 42,
430+
"execution_count": 11,
361431
"metadata": {},
362432
"outputs": [
363433
{
@@ -366,7 +436,7 @@
366436
"Dataset(DatasetReference('swast-scratch', 'my_dataset'))"
367437
]
368438
},
369-
"execution_count": 42,
439+
"execution_count": 11,
370440
"metadata": {},
371441
"output_type": "execute_result"
372442
}
@@ -381,13 +451,13 @@
381451
},
382452
{
383453
"cell_type": "code",
384-
"execution_count": 43,
454+
"execution_count": 12,
385455
"metadata": {},
386456
"outputs": [
387457
{
388458
"data": {
389459
"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>"
391461
],
392462
"text/plain": [
393463
"<IPython.core.display.HTML object>"
@@ -399,7 +469,7 @@
399469
{
400470
"data": {
401471
"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>"
403473
],
404474
"text/plain": [
405475
"<IPython.core.display.HTML object>"
@@ -523,7 +593,7 @@
523593
"[10 rows x 3 columns]"
524594
]
525595
},
526-
"execution_count": 43,
596+
"execution_count": 12,
527597
"metadata": {},
528598
"output_type": "execute_result"
529599
}
@@ -627,7 +697,7 @@
627697
"name": "python",
628698
"nbconvert_exporter": "python",
629699
"pygments_lexer": "ipython3",
630-
"version": "3.11.1"
700+
"version": "3.10.9"
631701
}
632702
},
633703
"nbformat": 4,

0 commit comments

Comments
 (0)