Kafka Lenses SQL -如何根据数组中嵌套对象的值进行WHERE过滤

ilmyapht  于 2023-06-05  发布在  Apache
关注(0)|答案(1)|浏览(134)

我试图根据嵌套在数组中的对象的值来过滤Kafka Lenses中的记录。我想查找所有带有工程师“id”的记录:数组中的“555”。这是两个示例记录,我想获得工程师的索引与“id”:“555”在每个记录中可能不同
记录A

{
  "payload": {
    "Data": {
      "project": "A"
    },
    "engineer": [
      {
        "name": "Jerry",
        "id": "111",
        "join_date":"12-10-2020"
      },
      {
        "name": "Fanny",
        "id": "555",
        "join_date":"11-23-2020"
      }
    ]
  }
}

记录B

{
  "payload": {
    "Data": {
      "project": "B"
    },
    "engineer": [
      {
        "name":"Fanny",
        "id": "555",
        "join_date":"10-18-2021"
      },
      {
        "name":"Terry",
        "id": "999",
        "join_date":"10-26-2020"
      }
    ]
  }
}

很明显,我不能执行像ARRAY_CONTAINS或

SELECT * 
FROM topic_name
WHERE payload.engineer[*].id = "555" 
LIMIT 10
olmpazwi

olmpazwi1#

尝试在以下情况下使用LATERAL JOIN

SELECT * 
FROM topic_name LATERAL payload.engineer as engineers
WHERE engineers.id = '555' 
LIMIT 10;

横向连接将每个有效载荷分解为两个,每个工程师一个。
有关详细信息,请参见Work with arrays

相关问题