如何将字典列表数据转换为字典字典,其中键是 Snowflake 中内部字典的值之一

发布于 2025-01-12 14:30:24 字数 578 浏览 4 评论 0原文

如何将字典列表数据转换为字典字典,其中键是 Snowflake 中内部字典的值之一。

上下文:我想要转换的值位于表格的单元格中,我试图用转换后的格式替换该单元格。

我试图通过两种方式找到完成上述任务的方法。 1.SnowflakeSQL 2.Javascript UDF 这是表中某个单元格中的值。

[
{
  "Vehicle_type": "P",
  "Vehicle_year": "2022",
  "KEY": "key_98765"
},

{
  "Vehicle_type": "Q",
  "Vehicle_year": "2019",
  "KEY": "key_12345"
}
]

我希望将其转换为

  {
'key_98765':
{
  "Vehicle_type": "P",
  "Vehicle_year": "2022",
  "KEY": "key_98765"
},
'key_12345':
{
  "Vehicle_type": "Q",
  "Vehicle_year": "2019",
  "KEY": "key_12345"
}

}

How to transform a data which is list of dictionaries to a dictionary of dictionaries with key being one of the value in inner dicts in Snowflake.

Context: The values I want to transform are in a cell of a table, i am trying to replace that cell with a transformed format.

I am trying to find ways to the task above in two ways. 1. SnowflakeSQL 2. Javascript UDF
This is a value in one of the cells in a table.

[
{
  "Vehicle_type": "P",
  "Vehicle_year": "2022",
  "KEY": "key_98765"
},

{
  "Vehicle_type": "Q",
  "Vehicle_year": "2019",
  "KEY": "key_12345"
}
]

I want this to be transformed to

  {
'key_98765':
{
  "Vehicle_type": "P",
  "Vehicle_year": "2022",
  "KEY": "key_98765"
},
'key_12345':
{
  "Vehicle_type": "Q",
  "Vehicle_year": "2019",
  "KEY": "key_12345"
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国际总奸 2025-01-19 14:30:24

你可以这样做:

脚本

let arr = [
  {
    "Vehicle_type": "P",
    "Vehicle_year": "2022",
    "KEY": "key_98765"
  },
  {
    "Vehicle_type": "Q",
    "Vehicle_year": "2019",
    "KEY": "key_12345"
  },
];

let arrWithKeys = [];

arr.forEach((value => {
  arrWithKeys.push({ [value["KEY"]]: value });
}))

console.log(arrWithKeys);

You can do it like this:

script

let arr = [
  {
    "Vehicle_type": "P",
    "Vehicle_year": "2022",
    "KEY": "key_98765"
  },
  {
    "Vehicle_type": "Q",
    "Vehicle_year": "2019",
    "KEY": "key_12345"
  },
];

let arrWithKeys = [];

arr.forEach((value => {
  arrWithKeys.push({ [value["KEY"]]: value });
}))

console.log(arrWithKeys);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文