Files
fn_registry/python/functions/bigquery/bq_create_routine.md
egutierrez 690e68a542 feat: add BigQuery Python functions and BQClient type
Funciones CRUD completas para BigQuery: auth, datasets, tables, queries,
jobs, routines, load/export. Tipo BQClient como wrapper del SDK oficial.
2026-04-07 18:45:02 +02:00

3.0 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports params output tested tests test_file_path file_path
bq_create_routine function py infra 1.0.0 impure def bq_create_routine(client: BQClient, dataset_id: str, routine_id: str, body: str, routine_type: str = 'SCALAR_FUNCTION', language: str = 'SQL', arguments: list[dict] | None = None, return_type: str = '', description: str = '') -> dict Crea una routine (UDF scalar, tabla o stored procedure) en BigQuery. Soporta SQL, JavaScript y Python.
bigquery
gcp
routine
udf
create
google-cloud
python
false error_go_core
google-cloud-bigquery
name desc
client instancia autenticada de BQClient
name desc
dataset_id nombre del dataset donde se crea la routine
name desc
routine_id nombre/identificador de la routine dentro del dataset
name desc
body cuerpo de la routine: expresion SQL, bloque JavaScript o codigo Python segun el lenguaje
name desc
routine_type tipo de routine: SCALAR_FUNCTION para UDFs escalares, TABLE_VALUED_FUNCTION para UDFs de tabla, PROCEDURE para stored procedures
name desc
language lenguaje de implementacion: SQL, JAVASCRIPT o PYTHON
name desc
arguments lista de argumentos, cada uno como dict con claves 'name' y 'data_type' (ej: INT64, STRING, FLOAT64)
name desc
return_type tipo de dato que retorna la funcion (ej: INT64, STRING); ignorado para PROCEDURE
name desc
description descripcion opcional de la routine
dict con routine_id, dataset_id, project, routine_type, language, body, description, created y modified (ISO 8601) false
python/functions/bigquery/routines.py

Ejemplo

from bigquery.client import bq_auth
from bigquery.routines import bq_create_routine

client = bq_auth("my-project")

# UDF escalar SQL
fn = bq_create_routine(
    client,
    dataset_id="analytics",
    routine_id="double_value",
    body="x * 2",
    arguments=[{"name": "x", "data_type": "INT64"}],
    return_type="INT64",
    description="Duplica un entero",
)
print(fn["routine_id"], fn["routine_type"], fn["language"])
# double_value SCALAR_FUNCTION SQL

# Stored procedure SQL
bq_create_routine(
    client,
    dataset_id="analytics",
    routine_id="refresh_summary",
    body="INSERT INTO summary SELECT * FROM raw WHERE date = CURRENT_DATE();",
    routine_type="PROCEDURE",
)

Notas

Lanza google.api_core.exceptions.Conflict (409) si la routine ya existe. Para actualizar una routine existente, eliminarla primero con bq_delete_routine y recrearla, o usar client._client.update_routine() directamente.

Los data_type de los argumentos deben ser constantes de bigquery.StandardSqlTypeNames: INT64, FLOAT64, STRING, BOOL, BYTES, DATE, DATETIME, TIMESTAMP, TIME, NUMERIC, BIGNUMERIC, JSON, ARRAY, STRUCT.

Las routines JavaScript permiten librerias externas via imported_libraries (no expuesto en este wrapper).