|
92 | 92 | }, |
93 | 93 | { |
94 | 94 | "cell_type": "code", |
95 | | - "execution_count": 9, |
| 95 | + "execution_count": null, |
96 | 96 | "metadata": { |
97 | 97 | "colab": { |
98 | 98 | "base_uri": "https://localhost:8080/" |
|
128 | 128 | "import bigframes.bigquery as bbq" |
129 | 129 | ] |
130 | 130 | }, |
| 131 | + { |
| 132 | + "cell_type": "code", |
| 133 | + "execution_count": null, |
| 134 | + "metadata": {}, |
| 135 | + "outputs": [], |
| 136 | + "source": [ |
| 137 | + "import bigframes.operations as ops\n", |
| 138 | + "\n", |
| 139 | + "def get_runtime_json_str(series, mode=\"R\", with_metadata=False):\n", |
| 140 | + " \"\"\"\n", |
| 141 | + " Get the runtime (contains signed URL to access gcs data) and apply the\n", |
| 142 | + " ToJSONSTring transformation.\n", |
| 143 | + " \n", |
| 144 | + " Args:\n", |
| 145 | + " series: bigframes.series.Series to operate on.\n", |
| 146 | + " mode: \"R\" for read, \"RW\" for read/write.\n", |
| 147 | + " with_metadata: Whether to fetch and include blob metadata.\n", |
| 148 | + " \"\"\"\n", |
| 149 | + " # 1. Optionally fetch metadata\n", |
| 150 | + " s = (\n", |
| 151 | + " series._apply_unary_op(ops.obj_fetch_metadata_op)\n", |
| 152 | + " if with_metadata\n", |
| 153 | + " else series\n", |
| 154 | + " )\n", |
| 155 | + " \n", |
| 156 | + " # 2. Retrieve the access URL runtime object\n", |
| 157 | + " runtime = s._apply_unary_op(ops.ObjGetAccessUrl(mode=mode))\n", |
| 158 | + " \n", |
| 159 | + " # 3. Convert the runtime object to a JSON string\n", |
| 160 | + " return runtime._apply_unary_op(ops.ToJSONString())" |
| 161 | + ] |
| 162 | + }, |
131 | 163 | { |
132 | 164 | "cell_type": "markdown", |
133 | 165 | "metadata": { |
|
1638 | 1670 | "\n", |
1639 | 1671 | "# Generate a JSON string containing the runtime information (including signed read URLs)\n", |
1640 | 1672 | "# This allows the UDF to download the images from Google Cloud Storage\n", |
1641 | | - "access_urls = exif_image_df[\"blob_col\"].blob.get_runtime_json_str(mode=\"R\")\n", |
| 1673 | + "access_urls = get_runtime_json_str(exif_image_df[\"blob_col\"], mode=\"R\")\n", |
1642 | 1674 | "\n", |
1643 | 1675 | "# Apply the BigQuery Python UDF to the runtime JSON strings\n", |
1644 | 1676 | "# We cast to string to ensure the input matches the UDF's signature\n", |
|
1670 | 1702 | "name": "python", |
1671 | 1703 | "nbconvert_exporter": "python", |
1672 | 1704 | "pygments_lexer": "ipython3", |
1673 | | - "version": "3.13.0" |
| 1705 | + "version": "3.10.15" |
1674 | 1706 | } |
1675 | 1707 | }, |
1676 | 1708 | "nbformat": 4, |
|
0 commit comments