Diferencia entre revisiones de «Nifi»
Ir a la navegación
Ir a la búsqueda
Sin resumen de edición |
|||
(No se muestra una edición intermedia del mismo usuario) | |||
Línea 33: | Línea 33: | ||
* Aplicar un valor per defecte si el valor és un altre o cadena buida. (Millor un processador ReplaceText) | * Aplicar un valor per defecte si el valor és un altre o cadena buida. (Millor un processador ReplaceText) | ||
=== Exemples === | |||
<syntaxhighlight lang="javascript" style="font-family:monospace"> | |||
[ | |||
{ | |||
"operation": "modify-overwrite-beta", | |||
"spec": { | |||
"age": "=intSum(-2022,@(1,player_age))" | |||
} | |||
}, | |||
{ | |||
"operation": "modify-overwrite-beta", | |||
"spec": { | |||
"player_age": "=abs(@(1,age))" | |||
} | |||
}, | |||
{ | |||
"operation": "shift", | |||
"spec": { | |||
"player_age": "player_age", | |||
"player_assists": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_assists" | |||
} | |||
}, | |||
"player_blocks": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_blocks" | |||
} | |||
}, | |||
"player_clearances": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_clearances" | |||
} | |||
}, | |||
"player_country": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_country" | |||
} | |||
}, | |||
"player_crosses_total": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_crosses_total" | |||
} | |||
}, | |||
"player_dispossesed": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_dispossesed" | |||
} | |||
}, | |||
"player_dribble_attempts": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_dribble_attempts" | |||
} | |||
}, | |||
"player_dribble_succ": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_dribble_succ" | |||
} | |||
}, | |||
"player_duels_total": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_duels_total" | |||
} | |||
}, | |||
"player_duels_won": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_duels_won" | |||
} | |||
}, | |||
"player_fouls_committed": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_fouls_committed" | |||
} | |||
}, | |||
"player_goals": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_goals" | |||
} | |||
}, | |||
"player_goals_conceded": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_goals_conceded" | |||
} | |||
}, | |||
"player_id": "player_id", | |||
"player_image": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_image" | |||
} | |||
}, | |||
"player_injured": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_injured" | |||
} | |||
}, | |||
"player_inside_box_saves": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_inside_box_saves" | |||
} | |||
}, | |||
"player_interceptions": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_interceptions" | |||
} | |||
}, | |||
"player_is_captain": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_is_captain" | |||
} | |||
}, | |||
"player_key": "player_key", | |||
"player_key_passes": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_key_passes" | |||
} | |||
}, | |||
"player_match_played": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_match_played" | |||
} | |||
}, | |||
"player_name": "player_name", | |||
"player_number": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_number" | |||
} | |||
}, | |||
"player_passes": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_passes" | |||
} | |||
}, | |||
"player_passes_accuracy": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_passes_accuracy" | |||
} | |||
}, | |||
"player_pen_comm": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_pen_comm" | |||
} | |||
}, | |||
"player_pen_missed": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_pen_missed" | |||
} | |||
}, | |||
"player_pen_scored": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_pen_scored" | |||
} | |||
}, | |||
"player_pen_won": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_pen_won" | |||
} | |||
}, | |||
"player_rating": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_rating" | |||
} | |||
}, | |||
"player_red_cards": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_red_cards" | |||
} | |||
}, | |||
"player_saves": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_saves" | |||
} | |||
}, | |||
"player_shots_total": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_shots_total" | |||
} | |||
}, | |||
"player_substitute_out": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_substitute_out" | |||
} | |||
}, | |||
"player_substitutes_on_bench": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_substitutes_on_bench" | |||
} | |||
}, | |||
"player_tackles": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_tackles" | |||
} | |||
}, | |||
"player_type": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_type" | |||
} | |||
}, | |||
"player_woordworks": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_woordworks" | |||
} | |||
}, | |||
"player_yellow_cards": { | |||
"": "TRASH", | |||
"*": { | |||
"$": "player_yellow_cards" | |||
} | |||
} | |||
} | |||
}, | |||
{ | |||
"operation": "remove", | |||
"spec": { | |||
"TRASH": "" | |||
} | |||
}, | |||
{ | |||
"operation": "default", | |||
"spec": { | |||
"player_age": 1800, | |||
"player_assists": "0", | |||
"player_blocks": "0", | |||
"player_clearances": "0", | |||
"player_country": "0", | |||
"player_crosses_total": "0", | |||
"player_dispossesed": "0", | |||
"player_dribble_attempts": "0", | |||
"player_dribble_succ": "0", | |||
"player_duels_total": "0", | |||
"player_duels_won": "0", | |||
"player_fouls_committed": "0", | |||
"player_goals": "0", | |||
"player_goals_conceded": "0", | |||
"player_image": "", | |||
"player_injured": "No", | |||
"player_inside_box_saves": "0", | |||
"player_interceptions": "0", | |||
"player_is_captain": "No", | |||
"player_key_passes": "0", | |||
"player_match_played": "0", | |||
"player_number": "0", | |||
"player_passes": "0", | |||
"player_passes_accuracy": "0", | |||
"player_pen_comm": "0", | |||
"player_pen_missed": "0", | |||
"player_pen_scored": "0", | |||
"player_pen_won": "0", | |||
"player_rating": "0", | |||
"player_red_cards": "0", | |||
"player_saves": "0", | |||
"player_shots_total": "0", | |||
"player_substitute_out": "0", | |||
"player_substitutes_on_bench": "0", | |||
"player_tackles": "0", | |||
"player_type": "No type", | |||
"player_woordworks": "0", | |||
"player_yellow_cards": "0" | |||
} | |||
} | |||
] | |||
[{ | |||
"operation": "shift", | |||
"spec": { | |||
"player_age": "player_age", | |||
"player_assists": ["player_assists", "player_stats[0]"], | |||
"player_blocks": ["player_blocks", "player_stats[1]"], | |||
"player_clearances": ["player_clearances", "player_stats[2]"], | |||
"player_country": "player_country", | |||
"player_crosses_total": "player_crosses_total", | |||
"player_dispossesed": "player_dispossesed", | |||
"player_dribble_attempts": "player_dribble_attempts", | |||
"player_dribble_succ": ["player_dribble_succ", "player_stats[3]"], | |||
"player_duels_total": "player_duels_total", | |||
"player_duels_won": ["player_duels_won", "player_stats[4]"], | |||
"player_fouls_committed": "player_fouls_committed", | |||
"player_goals": ["player_goals", "player_stats[5]"], | |||
"player_goals_conceded": "player_goals_conceded", | |||
"player_image": "player_image", | |||
"player_injured": "player_injured", | |||
"player_inside_box_saves": "player_inside_box_saves", | |||
"player_interceptions": "player_interceptions", | |||
"player_is_captain": "player_is_captain", | |||
"player_key_passes": "player_key_passes", | |||
"player_match_played": "player_match_played", | |||
"player_number": "player_number", | |||
"player_passes": "player_passes", | |||
"player_passes_accuracy": "player_passes_accuracy", | |||
"player_pen_comm": "player_pen_comm", | |||
"player_pen_missed": "player_pen_missed", | |||
"player_pen_scored": "player_pen_scored", | |||
"player_pen_won": "player_pen_won", | |||
"player_rating": "player_rating", | |||
"player_red_cards": "player_red_cards", | |||
"player_saves": "player_saves", | |||
"player_shots_total": "player_shots_total", | |||
"player_substitute_out": "player_substitute_out", | |||
"player_substitutes_on_bench": "player_substitutes_on_bench", | |||
"player_tackles": "player_tackles", | |||
"player_type": "player_type", | |||
"player_woordworks": "player_woordworks", | |||
"player_yellow_cards": "player_yellow_cards" | |||
} | |||
}, | |||
{ | |||
"operation": "modify-overwrite-beta", | |||
"spec": { | |||
"player_points": "=intSum(@(1,player_stats))" | |||
} | |||
} | |||
] | |||
</syntaxhighlight> | |||
= Enllaços = | = Enllaços = |
Revisión actual - 19:47 2 nov 2022
Introducció
Processadors
JOLT
Biblioteca de transformació JSON a JSON escrita en Java on l'"especificació" per a la transformació és en si mateix un document JSON.
Útil per:
- Transformar les dades JSON d'ElasticSearch, MongoDb, Cassandra, etc. abans d'enviar-les al món
- Extracció de dades d'un gran document JSON per al vostre propi consum
Tenin en compte que un JSON és una estructura jeràrquica en forma d'arbre, JOLT permet una serie de transformacions:
- shift: Copiar dades de l'entrada i posar-les en l'eixida, possiblement en un altre lloc.
- default: Aplicar els valors per defecte.
- remove: Llevar dades del l'arbre.
- sort: Ordenar alfabèticament.
- cardinality: Arreglar la cardinalitat de les dades d'entrada (per exemple, convertir un array d'un element en una string)
- modify-overwrite-beta: Aplicar transformacions a les dades. Transformacions que poden ser matemàtiques, de strings, tipus o d'arrays
És molt útil per a transformacions com:
- Llevar "dimensions" a un JSON transformant dades internes en prefixes o similar.
- Afegir "dimensions".
- Transformar objectes en arrays i viceversa.
- Tranformar mapes en listes i viceversa.
- Aplicar valors per defecte.
- Transposar un objecte
- Operacions matemàtiques bàsiques en valors i arrays.
- Concatenació de cadenes.
- Operacions en Arrays.
No obstant, es complica fer algunes coses simples com:
- Aplicar un valor per defecte si el valor és un altre o cadena buida. (Millor un processador ReplaceText)
Exemples
[
{
"operation": "modify-overwrite-beta",
"spec": {
"age": "=intSum(-2022,@(1,player_age))"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"player_age": "=abs(@(1,age))"
}
},
{
"operation": "shift",
"spec": {
"player_age": "player_age",
"player_assists": {
"": "TRASH",
"*": {
"$": "player_assists"
}
},
"player_blocks": {
"": "TRASH",
"*": {
"$": "player_blocks"
}
},
"player_clearances": {
"": "TRASH",
"*": {
"$": "player_clearances"
}
},
"player_country": {
"": "TRASH",
"*": {
"$": "player_country"
}
},
"player_crosses_total": {
"": "TRASH",
"*": {
"$": "player_crosses_total"
}
},
"player_dispossesed": {
"": "TRASH",
"*": {
"$": "player_dispossesed"
}
},
"player_dribble_attempts": {
"": "TRASH",
"*": {
"$": "player_dribble_attempts"
}
},
"player_dribble_succ": {
"": "TRASH",
"*": {
"$": "player_dribble_succ"
}
},
"player_duels_total": {
"": "TRASH",
"*": {
"$": "player_duels_total"
}
},
"player_duels_won": {
"": "TRASH",
"*": {
"$": "player_duels_won"
}
},
"player_fouls_committed": {
"": "TRASH",
"*": {
"$": "player_fouls_committed"
}
},
"player_goals": {
"": "TRASH",
"*": {
"$": "player_goals"
}
},
"player_goals_conceded": {
"": "TRASH",
"*": {
"$": "player_goals_conceded"
}
},
"player_id": "player_id",
"player_image": {
"": "TRASH",
"*": {
"$": "player_image"
}
},
"player_injured": {
"": "TRASH",
"*": {
"$": "player_injured"
}
},
"player_inside_box_saves": {
"": "TRASH",
"*": {
"$": "player_inside_box_saves"
}
},
"player_interceptions": {
"": "TRASH",
"*": {
"$": "player_interceptions"
}
},
"player_is_captain": {
"": "TRASH",
"*": {
"$": "player_is_captain"
}
},
"player_key": "player_key",
"player_key_passes": {
"": "TRASH",
"*": {
"$": "player_key_passes"
}
},
"player_match_played": {
"": "TRASH",
"*": {
"$": "player_match_played"
}
},
"player_name": "player_name",
"player_number": {
"": "TRASH",
"*": {
"$": "player_number"
}
},
"player_passes": {
"": "TRASH",
"*": {
"$": "player_passes"
}
},
"player_passes_accuracy": {
"": "TRASH",
"*": {
"$": "player_passes_accuracy"
}
},
"player_pen_comm": {
"": "TRASH",
"*": {
"$": "player_pen_comm"
}
},
"player_pen_missed": {
"": "TRASH",
"*": {
"$": "player_pen_missed"
}
},
"player_pen_scored": {
"": "TRASH",
"*": {
"$": "player_pen_scored"
}
},
"player_pen_won": {
"": "TRASH",
"*": {
"$": "player_pen_won"
}
},
"player_rating": {
"": "TRASH",
"*": {
"$": "player_rating"
}
},
"player_red_cards": {
"": "TRASH",
"*": {
"$": "player_red_cards"
}
},
"player_saves": {
"": "TRASH",
"*": {
"$": "player_saves"
}
},
"player_shots_total": {
"": "TRASH",
"*": {
"$": "player_shots_total"
}
},
"player_substitute_out": {
"": "TRASH",
"*": {
"$": "player_substitute_out"
}
},
"player_substitutes_on_bench": {
"": "TRASH",
"*": {
"$": "player_substitutes_on_bench"
}
},
"player_tackles": {
"": "TRASH",
"*": {
"$": "player_tackles"
}
},
"player_type": {
"": "TRASH",
"*": {
"$": "player_type"
}
},
"player_woordworks": {
"": "TRASH",
"*": {
"$": "player_woordworks"
}
},
"player_yellow_cards": {
"": "TRASH",
"*": {
"$": "player_yellow_cards"
}
}
}
},
{
"operation": "remove",
"spec": {
"TRASH": ""
}
},
{
"operation": "default",
"spec": {
"player_age": 1800,
"player_assists": "0",
"player_blocks": "0",
"player_clearances": "0",
"player_country": "0",
"player_crosses_total": "0",
"player_dispossesed": "0",
"player_dribble_attempts": "0",
"player_dribble_succ": "0",
"player_duels_total": "0",
"player_duels_won": "0",
"player_fouls_committed": "0",
"player_goals": "0",
"player_goals_conceded": "0",
"player_image": "",
"player_injured": "No",
"player_inside_box_saves": "0",
"player_interceptions": "0",
"player_is_captain": "No",
"player_key_passes": "0",
"player_match_played": "0",
"player_number": "0",
"player_passes": "0",
"player_passes_accuracy": "0",
"player_pen_comm": "0",
"player_pen_missed": "0",
"player_pen_scored": "0",
"player_pen_won": "0",
"player_rating": "0",
"player_red_cards": "0",
"player_saves": "0",
"player_shots_total": "0",
"player_substitute_out": "0",
"player_substitutes_on_bench": "0",
"player_tackles": "0",
"player_type": "No type",
"player_woordworks": "0",
"player_yellow_cards": "0"
}
}
]
[{
"operation": "shift",
"spec": {
"player_age": "player_age",
"player_assists": ["player_assists", "player_stats[0]"],
"player_blocks": ["player_blocks", "player_stats[1]"],
"player_clearances": ["player_clearances", "player_stats[2]"],
"player_country": "player_country",
"player_crosses_total": "player_crosses_total",
"player_dispossesed": "player_dispossesed",
"player_dribble_attempts": "player_dribble_attempts",
"player_dribble_succ": ["player_dribble_succ", "player_stats[3]"],
"player_duels_total": "player_duels_total",
"player_duels_won": ["player_duels_won", "player_stats[4]"],
"player_fouls_committed": "player_fouls_committed",
"player_goals": ["player_goals", "player_stats[5]"],
"player_goals_conceded": "player_goals_conceded",
"player_image": "player_image",
"player_injured": "player_injured",
"player_inside_box_saves": "player_inside_box_saves",
"player_interceptions": "player_interceptions",
"player_is_captain": "player_is_captain",
"player_key_passes": "player_key_passes",
"player_match_played": "player_match_played",
"player_number": "player_number",
"player_passes": "player_passes",
"player_passes_accuracy": "player_passes_accuracy",
"player_pen_comm": "player_pen_comm",
"player_pen_missed": "player_pen_missed",
"player_pen_scored": "player_pen_scored",
"player_pen_won": "player_pen_won",
"player_rating": "player_rating",
"player_red_cards": "player_red_cards",
"player_saves": "player_saves",
"player_shots_total": "player_shots_total",
"player_substitute_out": "player_substitute_out",
"player_substitutes_on_bench": "player_substitutes_on_bench",
"player_tackles": "player_tackles",
"player_type": "player_type",
"player_woordworks": "player_woordworks",
"player_yellow_cards": "player_yellow_cards"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"player_points": "=intSum(@(1,player_stats))"
}
}
]
Enllaços
Usuari de Youtube que ho explica bé. Demo de JOLT Repositori de JOLT Diapositives introducció a Shift