Looking for a "join-like" or "lookup-like" expression.

Aperta
#149 0 commenti 5 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
20/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
json
Ambito
data

Direzione di ricerca

Inizia esaminando la funzione let proposta in JEP 11 e il comportamento dello scope descritto nell’issue. Confronta questa proposta con le capacità attuali delle espressioni JMESPath e determina se la ricerca richiesta, simile a una join, sia possibile senza una nuova funzionalità del linguaggio. Il lavoro è completato quando viene documentata la risposta attuale oppure viene prodotta una proposta di funzionalità con un ambito sufficientemente definito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hello,

First and foremost, thanks in advance for sharing JMESPath which I find very elegant and powerful.

I have recently been faced with a challenge for which I could not build a single JMESPath expression that solves it for me. Consider the case of a JSON document like:

{
    "things": [{
        "id": 1,
        "name": "Thing #1",
        "owner_id": 1
    }, {
        "id": 2,
        "name": "Thing #2",
        "owner_id": 2
    }, {
        "id": 3,
        "name": "Thing #3",
        "owner_id": 1
    }],
    "users": [{
        "id": 1,
        "name": "User #1"
    }, {                                                                                  
        "id": 2,
        "name": "User #2"
    }]
}

The objective would be to return a the list of things where each owner_id wold be "resolved", so to speak, from the entries in the users array. To put it In SQL-ish terms, I'm looking to join things and users on things[*].owner_id and users[*].id.

After trying multiple things, the best and cleanest (albeit non-working!) solution I came up with was something like:

things[*].{id: id, owner_id:owner_id, owner:users[?id == owner_id]}

Unfortunatelly, within the multiselect hash, the expression for owner can't resolve users. It's clearly a matter of scope. Having investigated furter, I found out about JEP 11 https://github.com/jmespath/jmespath.site/pull/6 and it seems like the let function could be a possible solution.

Facts:

  • I could create a custom function to handle my particular need.
  • With JEP 11 in place, I could build an expression to solve this particular challenge.

Other than those two options, am I missing something that could be used currently?

Thanks in advance.
Regards.

Lingua principale
Python
Stelle
2.5k
Fork
231
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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jmespath/jmespath.py

Tutte le issue di jmespath/jmespath.py

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.