Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)22k · #10231

bigquery-udfs

Skill này làm gì

Skill này giúp bạn viết các hàm tùy chỉnh cho BigQuery khi hàm tích hợp sẵn không đủ. Skill dành cho lập trình viên cần logic đặc biệt hoặc cần gọi dịch vụ bên ngoài trong truy vấn.

Khi nào nên dùng

  • ✓Khi bạn muốn viết một hàm tùy chỉnh cho BigQuery bằng SQL, JavaScript hoặc Python.
  • ✓Khi một hàm Python hoặc JavaScript trong BigQuery cần một gói PyPI hoặc thư viện Cloud Storage.
  • ✓Khi bạn muốn một truy vấn BigQuery gọi API bên ngoài hoặc một dịch vụ Cloud Run qua remote function.

Liên kết skill

https://github.com/google/skills/blob/main/skills/cloud/bigquery-udfs/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/google/skills/blob/main/skills/cloud/bigquery-udfs/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Viết một hàm BigQuery gọi một API bên ngoài cho từng dòng và trả về kết quả.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill chọn loại hàm nhẹ nhất phù hợp với công việc, rồi viết và triển khai hàm. Skill cũng giúp xử lý sự cố khi hàm bị lỗi.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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):

  1. Install and Authenticate Google Cloud SDK: Install the Google Cloud SDK and authenticate:

    gcloud auth login
    

    Pass --project={project_id} and --region={region} (or --location for bq) explicitly on each command instead of running gcloud config set, which persists beyond the task. Default to us-central1 when the user has not specified a region (see BigQuery Locations).

  2. 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 (and run.googleapis.com for Remote Functions)
    CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:bigquery-udfs)" \
    gcloud services enable bigquery.googleapis.com \
      bigqueryconne
    
Câu hỏi thường gặp

Nên chọn loại hàm nào?

Hàm SQL là mặc định vì chạy nhanh nhất. Các lựa chọn bên ngoài dành cho khi SQL không đủ.

Hàm Python có gọi được API của Google Cloud không?

Có. Hàm Python có thể gọi API của Google Cloud và API bên ngoài khi dùng một connection.

Remote function là gì?

Đó là một hàm chạy trên endpoint riêng của bạn trong Cloud Run hoặc Cloud Run functions, và BigQuery sẽ gọi nó.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
22k
Vị trí xếp hạng
#10231
Giấy phép
Apache-2.0
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự