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.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
---
|
||||
name: bq_update_dataset
|
||||
kind: function
|
||||
lang: py
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "def bq_update_dataset(client: BQClient, dataset_id: str, description: str | None = None, labels: dict[str, str] | None = None, default_table_expiration_ms: int | None = None) -> dict"
|
||||
description: "Actualiza campos de un dataset de Google BigQuery. Solo modifica los campos pasados explicitamente (no-None). Usa client._client.update_dataset() del SDK oficial."
|
||||
tags: [bigquery, gcp, dataset, update, google-cloud, python]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: [google-cloud-bigquery]
|
||||
params:
|
||||
- name: client
|
||||
desc: "instancia autenticada de BQClient"
|
||||
- name: dataset_id
|
||||
desc: "nombre del dataset a actualizar (sin prefijo de proyecto)"
|
||||
- name: description
|
||||
desc: "nueva descripcion del dataset; None = no modificar"
|
||||
- name: labels
|
||||
desc: "nuevos labels key-value; None = no modificar; dict vacio {} = eliminar todos los labels"
|
||||
- name: default_table_expiration_ms
|
||||
desc: "nueva expiracion por defecto de tablas en ms; None = no modificar; 0 = eliminar expiracion"
|
||||
output: "dict con el dataset actualizado: dataset_id, project, full_id, location, description, labels, created, modified, default_table_expiration_ms"
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "python/functions/bigquery/datasets.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
from bigquery.client import bq_auth
|
||||
from bigquery.datasets import bq_update_dataset
|
||||
|
||||
client = bq_auth("my-project")
|
||||
|
||||
# Actualizar solo la descripcion
|
||||
ds = bq_update_dataset(client, "analytics", description="Data warehouse actualizado")
|
||||
|
||||
# Actualizar labels
|
||||
ds = bq_update_dataset(client, "analytics", labels={"env": "prod", "version": "2"})
|
||||
|
||||
# Eliminar expiracion de tablas
|
||||
ds = bq_update_dataset(client, "analytics", default_table_expiration_ms=0)
|
||||
print(ds["description"])
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Lanza `google.api_core.exceptions.NotFound` (404) si el dataset no existe.
|
||||
Si no se pasa ningun campo (todos None), retorna el dataset sin modificar (no llama a update_dataset).
|
||||
Para eliminar todos los labels pasar `labels={}`. Para eliminar la expiracion de tablas pasar `default_table_expiration_ms=0`.
|
||||
El SDK hace un GET interno antes del PATCH para obtener el estado actual; esta funcion replica ese patron explicitamente.
|
||||
Reference in New Issue
Block a user