Spec change - merge() function
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
Direzione di ricerca
Inizia con la sezione merge() della specifica e con l'implementazione proposta in jmespath.ts. Determina se merge() debba accettare oggetti, array o un tipo ristretto di array-of-objects, incluso il comportamento documentato dei membri dell'array. Il lavoro è completo quando gli esempi della specifica e la firma e l'implementazione a runtime in jmespath.ts concordano con la semantica accettata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Background
In all the example given in the spec page for the merge() functionLITERAL types are provided as arguments to the function. While this demonstrates the behaviour it is not at all useful in practical terms. Literals can only be explicitly defined by the editor of an expression. Much more useful would be to merge on results of expressions or on projections.
Examples:
search([{a: "AY", x: "EX"}, {a: "EY", b: "BEE"}], 'merge(@)')
// OUTPUTS: {"a": "EY", "b": "BEE", "x": "EX"}
search([{a: "AY", x: "EX"}, {a: "EY", b: "BEE"}], 'merge([{FED: @[0].x}, {BAR: @[1].b}])')
// OUTPUTS: {"BAR": "BEE", "FED": "EX"}
In order to do this merge would have to accept either TYPE_OBJECT or TYPE_ARRAY to work and the function would need to be able to switch on either type to handle this.
Discussion
Array can contain any value and ideally we may want to restrict it to a new TYPE_ARRAY_OBJECT type so that we can guarantee only objects can be used in the merge. One interesting side effect of this in javascript is that merging arrays results in array members being keyed in their index. This means we can do the following with very little code change:
search([{"A": "ONE"}, "TWO", {"C": "THREE"}], 'merge(@)')
// OUTPUTS: {"0": "ZERO", "A": "ONE", "C": "THREE"}
// With all JSON array member types:
search([{"A": "ONE"}, true, null, "BAR", ["ZERO"], 666], 'merge(@)')
// OUTPUTS: {"0": "ZERO", "1": "A", "2": "R", "A": "ONE"}
Implementation in jmespath.ts
// Runtime
private functionMerge: RuntimeFunction<JSONObject[], JSONObject> = resolvedArgs => {
let merged = {};
for (let i = 0; i < resolvedArgs.length; i += 1) {
const current = resolvedArgs[i];
if (Array.isArray(current)) {
merged = Object.assign(merged, ...current);
} else {
merged = Object.assign(merged, current);
}
}
return merged;
};
// and in the function table
merge: {
_func: this.functionMerge,
_signature: [
{
types: [InputArgument.TYPE_OBJECT, InputArgument.TYPE_ARRAY],
variadic: true,
},
],
},
- Lingua principale
- Python
- Stelle
- 10
- Fork
- 3
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di jmespath/jmespath.jep
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
jmespath/jmespath.jep#36 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
jmespath/jmespath.jep#35 ·
-
Root node accessAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
jmespath/jmespath.jep#34 · 1 commento ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
jmespath/jmespath.jep#33 ·
-
Allow string comparisonAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
jmespath/jmespath.jep#32 ·
Tutte le issue di jmespath/jmespath.jep
Issue simili
-
test_real_pandoc_failure_is_one_path_free_line fails on macOS CI with current Homebrew pandocApertabug TAG: unit tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
learningequality/ricecooker#898 ·
-
task
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
freelawproject/litigant-portal#1285 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
jmespath/jmespath.py#401 ·
-
least_squares returns a nonfinite objective for an invalid initial residualForse già presa @sylvesterkaczmarek l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
google-deepmind/mujoco#4023 ·
I maintainer di solito rispondono entro 11 giorni
-
Five Australian birds: Red-capped Parrot, Red-winged Fairywren, Gilbert’s Honeyeater, Western Spinebill, Western WattlebirdForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
arnegiacomo/fugleramme#427 ·
I maintainer di solito rispondono entro 1 giorno