bigquery-udfs
它能做什么
这个技能帮你在内置函数不够用时,为 BigQuery 编写自定义函数。它适用于需要特殊逻辑,或需要在查询中调用外部服务的开发者。
适用场景
- ✓当你想用 SQL、JavaScript 或 Python 为 BigQuery 编写自定义函数的时候。
- ✓当 BigQuery 中的 Python 或 JavaScript 函数需要 PyPI 包或 Cloud Storage 库的时候。
- ✓当你想让 BigQuery 查询通过远程函数调用外部 API 或 Cloud Run 服务的时候。
技能链接
https://github.com/google/skills/blob/main/skills/cloud/bigquery-udfs/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为 BigQuery 写一个函数,对每一行调用外部 API,并返回结果。”
每周 5 个新技能,1 分钟读完。
工作原理
它会选择最适合任务的最轻量函数类型,然后编写并部署该函数。函数出错时,它也会帮你排查。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
BigQuery User-Defined Functions (UDFs)
BigQuery User-Defined Functions (UDFs) extend GoogleSQL with custom logic
written in SQL, JavaScript, managed Python (python-3.11), or hosted externally
as Remote Functions on Cloud Run and Cloud Run functions.
Usage Attribution
MUST READ: Before executing any gcloud, REST API, or MCP command, you
MUST read and follow the instructions in
Usage Attribution.
Choosing the Right UDF Type
Always select the lightest-weight runtime that satisfies the requirement, because BigQuery optimizes native SQL expressions inline while external runtimes incur serialization and container startup overhead:
| UDF Type | Connection Required? | When to Use | Key Constraints |
|---|---|---|---|
| SQL UDF (Default) | No | Composable expressions, regex, struct/array manipulation, aggregate functions (CREATE AGGREGATE FUNCTION), or polymorphic ANY TYPE parameters. |
Lowest latency; zero external dependencies; supports TEMP or persistent functions. |
| JavaScript UDF | No | Custom string/JSON logic or bundling .js libraries from Cloud Storage (gs://). |
Runs in V8 sandbox; INT64 unsupported as input (pass as FLOAT64 or STRING). Max 32 KB inline code, 1 MB per external resource. Supports TEMP or persistent functions. |
| Managed Python UDF (Offline) | No | Pure compute using Python 3.11, PyPI wheels (packages=[...]), Cloud Storage .py modules (library=[...]), or vectorized Pandas/PyArrow batches. |
Persistent functions only (CREATE TEMP FUNCTION unsupported). Outbound network blocked. Max container size: 4 vCPU / 16 GiB. JSON, RANGE, INTERVAL, GEOGRAPHY unsupported. |
Managed Python UDF (WITH CONNECTION) |
Yes (CLOUD_RESOURCE) |
Invoking Google Cloud APIs (e.g., Cloud Translation, Gemini Enterprise Agent Platform) or online HTTP endpoints directly from Python inside BigQuery containers. | Requires WITH CONNECTION. Outbound traffic restricted to restricted.googleapis.com in VPC-SC perimeters (VPC networks unsupported). Max container size: 4 vCPU / 16 GiB. |
Remote Function (REMOTE WITH CONNECTION) |
Yes (CLOUD_RESOURCE) |
Calling external APIs or microservices when you need non-Python runtimes (Go, Java, Node.js), private VPC network access, GPUs, or custom Cloud Run scaling. | Requires Cloud Run HTTPS endpoint implementing BigQuery JSON batch contract and roles/run.invoker. Max input 5 MB per row; response limit 15 MB (Cloud Run) / 10 MB (1st gen). |
Prerequisites & Setup
Ensure the Google Cloud project has an active billing account attached (see BigQuery Pricing):
Install and Authenticate Google Cloud SDK: Install the Google Cloud SDK and authenticate:
gcloud auth loginPass
--project={project_id}and--region={region}(or--locationforbq) explicitly on each command instead of runninggcloud config set, which persists beyond the task. Default tous-central1when the user has not specified a region (see BigQuery Locations).Enable Required APIs:
- For SQL, JavaScript, and offline Python UDFs:
bigquery.googleapis.com - Additionally for Python UDFs calling APIs (
WITH CONNECTION) and Remote Functions:bigqueryconnection.googleapis.com(andrun.googleapis.comfor Remote Functions)
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:bigquery-udfs)" \ gcloud services enable bigquery.googleapis.com \ bigqueryconne- For SQL, JavaScript, and offline Python UDFs:
常见问题
我应该选哪种函数?
SQL 函数是默认选择,因为运行最快。外部选项适用于 SQL 不够用的情况。
Python 函数可以调用 Google Cloud API 吗?
可以。只要使用连接,Python 函数就可以调用 Google Cloud 和外部 API。
什么是远程函数?
它是运行在你自己的 Cloud Run 或 Cloud Run functions 端点上、由 BigQuery 调用的函数。
详情
作者的原始描述
Creates, deploys, and troubleshoots BigQuery User-Defined Functions (UDFs) and Remote Functions across SQL, JavaScript, Python, and Cloud Run endpoints. Use when writing custom scalar or aggregate functions in BigQuery, installing PyPI packages or Cloud Storage libraries in a Python or JavaScript UDF, or calling Google Cloud and external APIs from a Python UDF (WITH CONNECTION) or Remote Function. Don't use for standard BigQuery table/dataset CRUD (use bigquery-basics), DataFrames client workflows (use bigquery-bigframes), or BigQuery ML models (use bigquery-ai-ml).
repo: google/skills
热度
- GitHub 星标
- 22k
- 排名
- #10231
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
finding-google-skills
22k帮你的智能体为某项设置任务找到合适的 Google 指南,例如托管、数据库、存储、登录或 AI 模型服务。
gcloud
22k帮你的智能体编写并检查 Google Cloud gcloud 命令,在运行任何内容之前查阅准确的语法,避免猜测参数。
google-cloud-recipe-auth
22k引导你的智能体了解 Google Cloud 的身份与访问管理,包括人员和服务如何登录,以及它们各自获得哪些权限。
google-cloud-recipe-onboarding
22k带领新开发者完成在 Google Cloud 上的第一步,包括选择项目、关联计费,以及部署第一个资源。