|
73 | 73 | "id": "f289d250", |
74 | 74 | "metadata": {}, |
75 | 75 | "outputs": [ |
76 | | - { |
77 | | - "data": { |
78 | | - "application/vnd.jupyter.widget-view+json": { |
79 | | - "model_id": "071c0a905297406ba6c990cbbb8fc28d", |
80 | | - "version_major": 2, |
81 | | - "version_minor": 0 |
82 | | - }, |
83 | | - "text/plain": [ |
84 | | - "TableWidget(page_size=10, row_count=5552452, table_html='<table border=\"1\" class=\"dataframe table table-stripe…" |
85 | | - ] |
86 | | - }, |
87 | | - "metadata": {}, |
88 | | - "output_type": "display_data" |
89 | | - }, |
90 | 76 | { |
91 | 77 | "name": "stdout", |
92 | 78 | "output_type": "stream", |
93 | 79 | "text": [ |
94 | | - "\n" |
| 80 | + "Computation deferred. Computation will process 171.4 MB\n" |
95 | 81 | ] |
96 | 82 | } |
97 | 83 | ], |
|
143 | 129 | "outputs": [ |
144 | 130 | { |
145 | 131 | "data": { |
146 | | - "application/vnd.jupyter.widget-view+json": { |
147 | | - "model_id": "042a3d55c51b4a3192cf1a942c6797e8", |
148 | | - "version_major": 2, |
149 | | - "version_minor": 0 |
150 | | - }, |
| 132 | + "text/html": [ |
| 133 | + "✅ Completed. " |
| 134 | + ], |
151 | 135 | "text/plain": [ |
152 | | - "TableWidget(page_size=10, row_count=5552452, table_html='<table border=\"1\" class=\"dataframe table table-stripe…" |
| 136 | + "<IPython.core.display.HTML object>" |
153 | 137 | ] |
154 | 138 | }, |
155 | 139 | "metadata": {}, |
|
158 | 142 | { |
159 | 143 | "data": { |
160 | 144 | "application/vnd.jupyter.widget-view+json": { |
161 | | - "model_id": "06e46087ecbe4e6d8bdc2ed7c9284a7d", |
| 145 | + "model_id": "25b38c1408434091865f4bf9525dd069", |
162 | 146 | "version_major": 2, |
163 | 147 | "version_minor": 0 |
164 | 148 | }, |
|
172 | 156 | { |
173 | 157 | "data": { |
174 | 158 | "text/html": [], |
175 | | - "text/plain": [] |
| 159 | + "text/plain": [ |
| 160 | + "Computation deferred. Computation will process 171.4 MB" |
| 161 | + ] |
176 | 162 | }, |
177 | 163 | "execution_count": 6, |
178 | 164 | "metadata": {}, |
|
197 | 183 | "id": "6920d49b", |
198 | 184 | "metadata": {}, |
199 | 185 | "outputs": [ |
| 186 | + { |
| 187 | + "data": { |
| 188 | + "text/html": [ |
| 189 | + "✅ Completed. " |
| 190 | + ], |
| 191 | + "text/plain": [ |
| 192 | + "<IPython.core.display.HTML object>" |
| 193 | + ] |
| 194 | + }, |
| 195 | + "metadata": {}, |
| 196 | + "output_type": "display_data" |
| 197 | + }, |
200 | 198 | { |
201 | 199 | "name": "stdout", |
202 | 200 | "output_type": "stream", |
|
207 | 205 | { |
208 | 206 | "data": { |
209 | 207 | "application/vnd.jupyter.widget-view+json": { |
210 | | - "model_id": "4da2aaa13f074229b022c7256ba7510b", |
| 208 | + "model_id": "cb4f246802a1407cb966321d8724ea27", |
211 | 209 | "version_major": 2, |
212 | 210 | "version_minor": 0 |
213 | 211 | }, |
|
282 | 280 | "id": "a9d5d13a", |
283 | 281 | "metadata": {}, |
284 | 282 | "outputs": [ |
| 283 | + { |
| 284 | + "data": { |
| 285 | + "text/html": [ |
| 286 | + "✅ Completed. \n", |
| 287 | + " Query processed 171.4 MB in a moment of slot time.\n", |
| 288 | + " " |
| 289 | + ], |
| 290 | + "text/plain": [ |
| 291 | + "<IPython.core.display.HTML object>" |
| 292 | + ] |
| 293 | + }, |
| 294 | + "metadata": {}, |
| 295 | + "output_type": "display_data" |
| 296 | + }, |
285 | 297 | { |
286 | 298 | "name": "stdout", |
287 | 299 | "output_type": "stream", |
|
292 | 304 | { |
293 | 305 | "data": { |
294 | 306 | "application/vnd.jupyter.widget-view+json": { |
295 | | - "model_id": "d2739b180f7d40b1b52ebab121ab7a8a", |
| 307 | + "model_id": "5b48c05254224c4dbce56f2793d6b661", |
296 | 308 | "version_major": 2, |
297 | 309 | "version_minor": 0 |
298 | 310 | }, |
|
311 | 323 | "print(f\"Small dataset pages: {math.ceil(small_widget.row_count / small_widget.page_size)}\")\n", |
312 | 324 | "small_widget" |
313 | 325 | ] |
| 326 | + }, |
| 327 | + { |
| 328 | + "cell_type": "markdown", |
| 329 | + "id": "added-cell-2", |
| 330 | + "metadata": {}, |
| 331 | + "source": [ |
| 332 | + "### Displaying Generative AI results containing JSON\n", |
| 333 | + "The `AI.GENERATE` function in BigQuery returns results in a JSON column. While BigQuery's JSON type is not natively supported by the underlying Arrow `to_pandas_batches()` method used in anywidget mode ([Apache Arrow issue #45262](https://github.com/apache/arrow/issues/45262)), BigQuery Dataframes automatically converts JSON columns to strings for display. This allows you to view the results of generative AI functions seamlessly." |
| 334 | + ] |
| 335 | + }, |
| 336 | + { |
| 337 | + "cell_type": "code", |
| 338 | + "execution_count": 10, |
| 339 | + "id": "added-cell-1", |
| 340 | + "metadata": {}, |
| 341 | + "outputs": [ |
| 342 | + { |
| 343 | + "data": { |
| 344 | + "text/html": [ |
| 345 | + "✅ Completed. \n", |
| 346 | + " Query processed 85.9 kB in 14 seconds of slot time.\n", |
| 347 | + " " |
| 348 | + ], |
| 349 | + "text/plain": [ |
| 350 | + "<IPython.core.display.HTML object>" |
| 351 | + ] |
| 352 | + }, |
| 353 | + "metadata": {}, |
| 354 | + "output_type": "display_data" |
| 355 | + }, |
| 356 | + { |
| 357 | + "name": "stderr", |
| 358 | + "output_type": "stream", |
| 359 | + "text": [ |
| 360 | + "/usr/local/google/home/shuowei/src/github.com/googleapis/python-bigquery-dataframes/bigframes/dtypes.py:959: JSONDtypeWarning: JSON columns will be represented as pandas.ArrowDtype(pyarrow.json_())\n", |
| 361 | + "instead of using `db_dtypes` in the future when available in pandas\n", |
| 362 | + "(https://github.com/pandas-dev/pandas/issues/60958) and pyarrow.\n", |
| 363 | + " warnings.warn(msg, bigframes.exceptions.JSONDtypeWarning)\n", |
| 364 | + "/usr/local/google/home/shuowei/src/github.com/googleapis/python-bigquery-dataframes/bigframes/dataframe.py:869: UserWarning: Converting JSON columns to strings for display. This is temporary and will be removed when the frontend supports JSON types.\n", |
| 365 | + " warnings.warn(\n" |
| 366 | + ] |
| 367 | + }, |
| 368 | + { |
| 369 | + "data": { |
| 370 | + "text/html": [ |
| 371 | + "✅ Completed. \n", |
| 372 | + " Query processed 0 Bytes in a moment of slot time.\n", |
| 373 | + " " |
| 374 | + ], |
| 375 | + "text/plain": [ |
| 376 | + "<IPython.core.display.HTML object>" |
| 377 | + ] |
| 378 | + }, |
| 379 | + "metadata": {}, |
| 380 | + "output_type": "display_data" |
| 381 | + }, |
| 382 | + { |
| 383 | + "data": { |
| 384 | + "application/vnd.jupyter.widget-view+json": { |
| 385 | + "model_id": "ab607cc7263f4a159ecfe63682c5e651", |
| 386 | + "version_major": 2, |
| 387 | + "version_minor": 0 |
| 388 | + }, |
| 389 | + "text/plain": [ |
| 390 | + "TableWidget(page_size=10, row_count=5, table_html='<table border=\"1\" class=\"dataframe table table-striped tabl…" |
| 391 | + ] |
| 392 | + }, |
| 393 | + "metadata": {}, |
| 394 | + "output_type": "display_data" |
| 395 | + }, |
| 396 | + { |
| 397 | + "data": { |
| 398 | + "text/html": [], |
| 399 | + "text/plain": [ |
| 400 | + "Computation deferred. Computation will process 0 Bytes" |
| 401 | + ] |
| 402 | + }, |
| 403 | + "execution_count": 10, |
| 404 | + "metadata": {}, |
| 405 | + "output_type": "execute_result" |
| 406 | + } |
| 407 | + ], |
| 408 | + "source": [ |
| 409 | + "bpd._read_gbq_colab(\"\"\"\\n\n", |
| 410 | + "SELECT\\n\n", |
| 411 | + " AI.GENERATE(\\n\n", |
| 412 | + " prompt=>(\\\"Extract the values.\\\", OBJ.GET_ACCESS_URL(OBJ.FETCH_METADATA(OBJ.MAKE_REF(gcs_path, \\\"us.conn\\\")), \\\"r\\\")),\\n\n", |
| 413 | + " connection_id=>\\\"bigframes-dev.us.bigframes-default-connection\\\",\\n\n", |
| 414 | + " output_schema=>\\\"publication_date string, class_international string, application_number string, filing_date string\\\") AS result,\\n\n", |
| 415 | + " *\\n\n", |
| 416 | + "FROM `bigquery-public-data.labeled_patents.extracted_data`\\n\n", |
| 417 | + "LIMIT 5;\\n\n", |
| 418 | + "\"\"\")" |
| 419 | + ] |
314 | 420 | } |
315 | 421 | ], |
316 | 422 | "metadata": { |
317 | 423 | "kernelspec": { |
318 | | - "display_name": "venv", |
| 424 | + "display_name": "3.10.18", |
319 | 425 | "language": "python", |
320 | 426 | "name": "python3" |
321 | 427 | }, |
|
329 | 435 | "name": "python", |
330 | 436 | "nbconvert_exporter": "python", |
331 | 437 | "pygments_lexer": "ipython3", |
332 | | - "version": "3.10.16" |
| 438 | + "version": "3.10.18" |
333 | 439 | } |
334 | 440 | }, |
335 | 441 | "nbformat": 4, |
|
0 commit comments