Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/bigquery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Simple workflow for deploying static content to GitHub Pages
name: Run BigQuery snippets as a test

on:
push:
paths-ignore:
- ".gitignore"
branches:
- main
pull_request_target:
types:
- labeled

jobs:
build:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.label.name == 'ci-run-cloud'

# Add "id-token" with the intended permissions.
permissions:
contents: 'read'
# required for GCP workload identity federation
id-token: 'write'

steps:
- name: checkout
uses: actions/checkout@v4
if: github.event.label.name != 'ci-run-cloud'

- name: checkout
if: github.event.label.name == 'ci-run-cloud'
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Python
# This is the version of the action for setting up Python, not the Python version.
uses: actions/setup-python@v5
with:
# Semantic version range syntax or exact version of a Python version
python-version: '3.12'
# Optional - x64 or x86 architecture, defaults to x64
architecture: 'x64'

- uses: 'google-github-actions/auth@v2'
with:
project_id: 'friendliness-dev-demo'
workload_identity_provider: 'projects/368174856750/locations/global/workloadIdentityPools/github/providers/code-snippets'

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install packages
run: python -m pip install -r requirements.txt

- name: Test the notebook
run: python -m jupyter nbconvert --to html --execute 2024/12-bigquery-utils/bigquery-utils.ipynb
42 changes: 17 additions & 25 deletions 2017/acl-weather/acl-weather.ipynb

Large diffs are not rendered by default.

243 changes: 243 additions & 0 deletions 2024/12-bigquery-utils/bigquery-utils.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"%load_ext bigquery_magics"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Try a query that doesn't require any additional libraries."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e44fc98d1439478482520de48f1e4b6c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Query is running: 0%| |"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "aa559ce9c11540af9b8a7f9c94138063",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading: 0%| |"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>x</th>\n",
" <th>hex</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>0000000000000001</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>123456</td>\n",
" <td>000000000001e240</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>9876543210</td>\n",
" <td>000000024cb016ea</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>-1001</td>\n",
" <td>fffffffffffffc17</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" x hex\n",
"0 1 0000000000000001\n",
"1 123456 000000000001e240\n",
"2 9876543210 000000024cb016ea\n",
"3 -1001 fffffffffffffc17"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%bigquery\n",
"SELECT\n",
" x,\n",
" bqutil.fn.to_hex(x) AS hex\n",
"FROM\n",
" UNNEST([1, 123456, 9876543210, -1001]) AS x;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9a7df3ece0584d909681ec621cdbbfd6",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Query is running: 0%| |"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "38ff038524e84cc39d7c6adf5ae33807",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading: 0%| |"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>output_json</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>{\"xml\":{\"_attributes\":{\"foo\":\"FOO\"},\"bar\":{\"ba...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" output_json\n",
"0 {\"xml\":{\"_attributes\":{\"foo\":\"FOO\"},\"bar\":{\"ba..."
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%bigquery\n",
"SELECT bqutil.fn.xml_to_json(\n",
" '<xml foo=\"FOO\"><bar><baz>BAZ</baz></bar></xml>'\n",
") AS output_json"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "scratch",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
26 changes: 0 additions & 26 deletions bigquery-dataframes-iowa-liquor-sales/codelab.json

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading