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

Abierto
#149 0 comentarios 5 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
20/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
json
Área
data

Línea de trabajo

Comienza revisando la función let propuesta en JEP 11 y el comportamiento de ámbito descrito en el issue. Compara esa propuesta con las capacidades actuales de las expresiones JMESPath y determina si la búsqueda solicitada, similar a un join, es posible sin una nueva funcionalidad del lenguaje. Se considera terminado documentar la respuesta actual o elaborar una propuesta de funcionalidad con un alcance suficientemente definido.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
2.5k
Forks
231
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de jmespath/jmespath.py

Todos los issues de jmespath/jmespath.py

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.