|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 2, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "%load_ext bigquery_magics" |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "markdown", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "Try a query that doesn't require any additional libraries." |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "code", |
| 21 | + "execution_count": 4, |
| 22 | + "metadata": {}, |
| 23 | + "outputs": [ |
| 24 | + { |
| 25 | + "data": { |
| 26 | + "application/vnd.jupyter.widget-view+json": { |
| 27 | + "model_id": "e44fc98d1439478482520de48f1e4b6c", |
| 28 | + "version_major": 2, |
| 29 | + "version_minor": 0 |
| 30 | + }, |
| 31 | + "text/plain": [ |
| 32 | + "Query is running: 0%| |" |
| 33 | + ] |
| 34 | + }, |
| 35 | + "metadata": {}, |
| 36 | + "output_type": "display_data" |
| 37 | + }, |
| 38 | + { |
| 39 | + "data": { |
| 40 | + "application/vnd.jupyter.widget-view+json": { |
| 41 | + "model_id": "aa559ce9c11540af9b8a7f9c94138063", |
| 42 | + "version_major": 2, |
| 43 | + "version_minor": 0 |
| 44 | + }, |
| 45 | + "text/plain": [ |
| 46 | + "Downloading: 0%| |" |
| 47 | + ] |
| 48 | + }, |
| 49 | + "metadata": {}, |
| 50 | + "output_type": "display_data" |
| 51 | + }, |
| 52 | + { |
| 53 | + "data": { |
| 54 | + "text/html": [ |
| 55 | + "<div>\n", |
| 56 | + "<style scoped>\n", |
| 57 | + " .dataframe tbody tr th:only-of-type {\n", |
| 58 | + " vertical-align: middle;\n", |
| 59 | + " }\n", |
| 60 | + "\n", |
| 61 | + " .dataframe tbody tr th {\n", |
| 62 | + " vertical-align: top;\n", |
| 63 | + " }\n", |
| 64 | + "\n", |
| 65 | + " .dataframe thead th {\n", |
| 66 | + " text-align: right;\n", |
| 67 | + " }\n", |
| 68 | + "</style>\n", |
| 69 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 70 | + " <thead>\n", |
| 71 | + " <tr style=\"text-align: right;\">\n", |
| 72 | + " <th></th>\n", |
| 73 | + " <th>x</th>\n", |
| 74 | + " <th>hex</th>\n", |
| 75 | + " </tr>\n", |
| 76 | + " </thead>\n", |
| 77 | + " <tbody>\n", |
| 78 | + " <tr>\n", |
| 79 | + " <th>0</th>\n", |
| 80 | + " <td>1</td>\n", |
| 81 | + " <td>0000000000000001</td>\n", |
| 82 | + " </tr>\n", |
| 83 | + " <tr>\n", |
| 84 | + " <th>1</th>\n", |
| 85 | + " <td>123456</td>\n", |
| 86 | + " <td>000000000001e240</td>\n", |
| 87 | + " </tr>\n", |
| 88 | + " <tr>\n", |
| 89 | + " <th>2</th>\n", |
| 90 | + " <td>9876543210</td>\n", |
| 91 | + " <td>000000024cb016ea</td>\n", |
| 92 | + " </tr>\n", |
| 93 | + " <tr>\n", |
| 94 | + " <th>3</th>\n", |
| 95 | + " <td>-1001</td>\n", |
| 96 | + " <td>fffffffffffffc17</td>\n", |
| 97 | + " </tr>\n", |
| 98 | + " </tbody>\n", |
| 99 | + "</table>\n", |
| 100 | + "</div>" |
| 101 | + ], |
| 102 | + "text/plain": [ |
| 103 | + " x hex\n", |
| 104 | + "0 1 0000000000000001\n", |
| 105 | + "1 123456 000000000001e240\n", |
| 106 | + "2 9876543210 000000024cb016ea\n", |
| 107 | + "3 -1001 fffffffffffffc17" |
| 108 | + ] |
| 109 | + }, |
| 110 | + "execution_count": 4, |
| 111 | + "metadata": {}, |
| 112 | + "output_type": "execute_result" |
| 113 | + } |
| 114 | + ], |
| 115 | + "source": [ |
| 116 | + "%%bigquery\n", |
| 117 | + "SELECT\n", |
| 118 | + " x,\n", |
| 119 | + " bqutil.fn.to_hex(x) AS hex\n", |
| 120 | + "FROM\n", |
| 121 | + " UNNEST([1, 123456, 9876543210, -1001]) AS x;" |
| 122 | + ] |
| 123 | + }, |
| 124 | + { |
| 125 | + "cell_type": "markdown", |
| 126 | + "metadata": {}, |
| 127 | + "source": [ |
| 128 | + "Try a function that uses a JS library hosted in GCS. See: https://github.com/GoogleCloudPlatform/bigquery-utils/pull/434 and https://github.com/GoogleCloudPlatform/bigquery-utils/blob/master/udfs/community/README.md#xml_to_jsonxml-string\n" |
| 129 | + ] |
| 130 | + }, |
| 131 | + { |
| 132 | + "cell_type": "code", |
| 133 | + "execution_count": 3, |
| 134 | + "metadata": {}, |
| 135 | + "outputs": [ |
| 136 | + { |
| 137 | + "data": { |
| 138 | + "application/vnd.jupyter.widget-view+json": { |
| 139 | + "model_id": "9a7df3ece0584d909681ec621cdbbfd6", |
| 140 | + "version_major": 2, |
| 141 | + "version_minor": 0 |
| 142 | + }, |
| 143 | + "text/plain": [ |
| 144 | + "Query is running: 0%| |" |
| 145 | + ] |
| 146 | + }, |
| 147 | + "metadata": {}, |
| 148 | + "output_type": "display_data" |
| 149 | + }, |
| 150 | + { |
| 151 | + "data": { |
| 152 | + "application/vnd.jupyter.widget-view+json": { |
| 153 | + "model_id": "38ff038524e84cc39d7c6adf5ae33807", |
| 154 | + "version_major": 2, |
| 155 | + "version_minor": 0 |
| 156 | + }, |
| 157 | + "text/plain": [ |
| 158 | + "Downloading: 0%| |" |
| 159 | + ] |
| 160 | + }, |
| 161 | + "metadata": {}, |
| 162 | + "output_type": "display_data" |
| 163 | + }, |
| 164 | + { |
| 165 | + "data": { |
| 166 | + "text/html": [ |
| 167 | + "<div>\n", |
| 168 | + "<style scoped>\n", |
| 169 | + " .dataframe tbody tr th:only-of-type {\n", |
| 170 | + " vertical-align: middle;\n", |
| 171 | + " }\n", |
| 172 | + "\n", |
| 173 | + " .dataframe tbody tr th {\n", |
| 174 | + " vertical-align: top;\n", |
| 175 | + " }\n", |
| 176 | + "\n", |
| 177 | + " .dataframe thead th {\n", |
| 178 | + " text-align: right;\n", |
| 179 | + " }\n", |
| 180 | + "</style>\n", |
| 181 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 182 | + " <thead>\n", |
| 183 | + " <tr style=\"text-align: right;\">\n", |
| 184 | + " <th></th>\n", |
| 185 | + " <th>output_json</th>\n", |
| 186 | + " </tr>\n", |
| 187 | + " </thead>\n", |
| 188 | + " <tbody>\n", |
| 189 | + " <tr>\n", |
| 190 | + " <th>0</th>\n", |
| 191 | + " <td>{\"xml\":{\"_attributes\":{\"foo\":\"FOO\"},\"bar\":{\"ba...</td>\n", |
| 192 | + " </tr>\n", |
| 193 | + " </tbody>\n", |
| 194 | + "</table>\n", |
| 195 | + "</div>" |
| 196 | + ], |
| 197 | + "text/plain": [ |
| 198 | + " output_json\n", |
| 199 | + "0 {\"xml\":{\"_attributes\":{\"foo\":\"FOO\"},\"bar\":{\"ba..." |
| 200 | + ] |
| 201 | + }, |
| 202 | + "execution_count": 3, |
| 203 | + "metadata": {}, |
| 204 | + "output_type": "execute_result" |
| 205 | + } |
| 206 | + ], |
| 207 | + "source": [ |
| 208 | + "%%bigquery\n", |
| 209 | + "SELECT bqutil.fn.xml_to_json(\n", |
| 210 | + " '<xml foo=\"FOO\"><bar><baz>BAZ</baz></bar></xml>'\n", |
| 211 | + ") AS output_json" |
| 212 | + ] |
| 213 | + }, |
| 214 | + { |
| 215 | + "cell_type": "code", |
| 216 | + "execution_count": null, |
| 217 | + "metadata": {}, |
| 218 | + "outputs": [], |
| 219 | + "source": [] |
| 220 | + } |
| 221 | + ], |
| 222 | + "metadata": { |
| 223 | + "kernelspec": { |
| 224 | + "display_name": "scratch", |
| 225 | + "language": "python", |
| 226 | + "name": "python3" |
| 227 | + }, |
| 228 | + "language_info": { |
| 229 | + "codemirror_mode": { |
| 230 | + "name": "ipython", |
| 231 | + "version": 3 |
| 232 | + }, |
| 233 | + "file_extension": ".py", |
| 234 | + "mimetype": "text/x-python", |
| 235 | + "name": "python", |
| 236 | + "nbconvert_exporter": "python", |
| 237 | + "pygments_lexer": "ipython3", |
| 238 | + "version": "3.12.6" |
| 239 | + } |
| 240 | + }, |
| 241 | + "nbformat": 4, |
| 242 | + "nbformat_minor": 2 |
| 243 | +} |
0 commit comments