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

オープン
#149 コメント 0 件 リアクション 5 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
20/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
json
領域
data

調査の方向性

まず、提案されている JEP 11 の let 関数と、issue に記載されているスコープの動作を確認します。その提案を現在の JMESPath 式の機能と比較し、要求されている join のような検索が新しい言語機能なしで可能かどうかを判断します。完了条件は、現時点での回答を文書化するか、十分に範囲を限定した機能提案を作成することです。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
2.5k
フォーク
231
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

jmespath/jmespath.py のほかの issue

jmespath/jmespath.py の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。