You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Azure Mapping JSON将CSV空白单元格转换为NULL的技术求助

解决方案:将CSV空白单元格转为NULL

你的问题出在错误使用了physicalType属性——这个字段是用来指定目标列的物理数据类型的,不是用来做值转换的。要实现空白转NULL,应该用transform属性来处理源字段的值转换。

修改后的配置示例如下:

{
  "type": "TabularTranslator",
  "mappings": [
    {
      "source": {
        "type": "String",
        "ordinal": 1
      },
      "sink": {
        "name": "UPRN"
      },
      "transform": "iif(length(rtrim(source)) == 0, null(), source)"
    },
    {
      "source": {
        "type": "String",
        "ordinal": 2
      },
      "sink": {
        "name": "OS_ADDRESS_TOID"
      },
      "transform": "iif(length(rtrim(source)) == 0, null(), source)"
    }
  ],
  "typeConversion": true,
  "typeConversionSettings": {
    "allowDataTruncation": true,
    "treatBooleanAsNumber": false
  }
}

关键说明:

  • transform属性是TabularTranslator中专门用于字段值转换的配置,它会对源字段进行计算后再映射到目标列。
  • 表达式iif(length(rtrim(source)) == 0, null(), source)的逻辑:先去掉源字段的右侧空格,再判断长度是否为0(覆盖空字符串和全空格的情况),如果是则返回NULL,否则返回原字段值。
  • 移除了原来错误使用的physicalType配置,确保类型转换由typeConversion统一处理。

如果CSV中的空白单元格包含制表符或其他左右两侧的空白字符,可以把rtrim换成trim来处理所有空白:

"transform": "iif(length(trim(source)) == 0, null(), source)"

内容的提问来源于stack exchange,提问作者TSdeveloper

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 09:09:57