创建 ADF 管道时如何从复杂的 json 中获取列的值

问题描述 投票:0回答:1

我有一个来自 cosmos db 的复杂 json,其中包含字符串格式的 fsid 和 fpid 。 我正在将数据移至 sql,其中它是整数。 我无法从 cosmos 中读取该特定列的值并将其转换为 int。

示例 JSON:

{
    "id": "test",
    "documentType": "testing",
    "content": {
        "id": "test1",
       
      
        "current": {
            "fsid": "PP",
            "fpid": "2021",         
            "publishStatus": "Draft"
        },
        "released": null,
        "name": "PPGG"
    },
    "date": "0001-01-01T00:00:00+00:00",
    "_ts": 111
}

目标:

  1. 获取fsid的值并将其转换为整数以根据条件传递SQL接收器。例如如果fsid是PP,则获取int值1,如果fsid是QQ,则获取值2
  2. 将日期转换为sql数据时间格式

尝试过: 我尝试使用派生列

toInteger(content.current.fsid)
但它读取的是空值。 另外,我尝试使用
cast 
但我没有获取列名称本身,只显示顶级列。

请问有什么建议吗?

azure azure-data-factory
1个回答
0
投票

获取fsid的值并将其转换为整数以根据条件传递SQL接收器。例如如果fsid是PP,则获取int值1,如果fsid是QQ,则获取值2

由于您的

fsid
是类似 PP 或任何其他字符的字符串,如果您尝试转换为整数,它会将字符串字符读取为空。

当您根据条件将其转换为整数时,因此您需要使用带有 IIF 条件或 case 语句的派生列,如下所示:

表情:

fsid : iif(content.current.fsid=='PP',1,iif(content.current.fsid=='QQ',2,0))
//if fsid == PP then 1 else check fsid == QQ if it true then 2 if both conditions are not matching then 0

enter image description here

数据预览:

enter image description here

将日期转换为sql数据时间格式

您可以使用强制转换将日期转换为您所需的格式,如下所示:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.