feat: funciones Go — core (cron, join_by_key, validate_struct), datascience (pivot, diff_entities), infra (http, cache, cron_ticker)
Nuevas funciones Go con tests en tres dominios: - core: parse_cron_expr, next_cron_time, join_by_key, validate_struct_fields + tipo CronSchedule - datascience: pivot (tabla dinámica), diff_entities (comparación de entidades) - infra: http_get_json, http_post_json, http_download_file, cache_to_sqlite, cron_ticker Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
---
|
||||
name: diff_entities
|
||||
kind: function
|
||||
lang: go
|
||||
domain: datascience
|
||||
version: "1.0.0"
|
||||
purity: pure
|
||||
signature: "func DiffEntities(before, after []map[string]any, key string, ignoreFields []string) map[string]any"
|
||||
description: "Compara dos snapshots de entities y devuelve diferencias campo a campo. Detecta añadidas, eliminadas, modificadas e inalteradas. Ignora created_at y updated_at por defecto (pasar nil para usar defaults)."
|
||||
tags: [datascience, diff, entities, operations, snapshot, comparison]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: ""
|
||||
imports: ["fmt"]
|
||||
tested: true
|
||||
tests:
|
||||
- "entity añadida"
|
||||
- "entity eliminada"
|
||||
- "entity modificada con detalle de campos"
|
||||
- "entities identicas → unchanged"
|
||||
- "ignore_fields funciona"
|
||||
- "lista vacia vs lista con datos"
|
||||
- "summary format correcto"
|
||||
test_file_path: "functions/datascience/diff_entities_test.go"
|
||||
file_path: "functions/datascience/diff_entities.go"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```go
|
||||
before := []map[string]any{
|
||||
{"id": "1", "name": "Alice", "status": "active"},
|
||||
{"id": "2", "name": "Bob"},
|
||||
}
|
||||
after := []map[string]any{
|
||||
{"id": "1", "name": "Alice", "status": "inactive"},
|
||||
{"id": "3", "name": "Carol"},
|
||||
}
|
||||
result := DiffEntities(before, after, "id", nil)
|
||||
// result["summary"] = "1 added, 1 removed, 1 modified, 0 unchanged"
|
||||
// result["added"] = [{"id": "3", "name": "Carol"}]
|
||||
// result["removed"] = [{"id": "2", "name": "Bob"}]
|
||||
// result["modified"] = [{"key": "1", "changes": {"status": {"old": "active", "new": "inactive"}}}]
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Funcion pura. Compara valores con fmt.Sprintf("%v", ...) para manejar tipos heterogeneos en map[string]any.
|
||||
ignoreFields nil usa los defaults ["created_at", "updated_at"]. Para no ignorar ningun campo, pasar []string{}.
|
||||
Semantica identica a diff_entities_py_datascience, permite comparar resultados entre ejecuciones del mismo pipeline.
|
||||
Reference in New Issue
Block a user