首页 > 解决方案 > Azure 数据工厂无法将字符串列值转换为日期时间

问题描述

我正在使用现有的 ADF 管道将数据从 blob 复制到 sql。我的源数据有一个像“20000101”这样的列值。当 ADF 尝试将其从字符串转换为 dateTime 格式时出现错误。我正在使用像“dateTimeFormat”这样的json翻译器:“yyyy-MM-dd HH:mm:ss.fff”。但最终还是会出现错误,因为“转换值 '20000101' 时发生异常无法将字符串转换为日期时间类型。

有什么建议吗?

注意:我只能通过 json 映射来处理这个问题。无法编辑现有管道。这里有什么可能吗?

标签: azureazure-data-factory

解决方案


无论 blob 中的数据还是本地 NFS 中的数据,数据工厂副本活动都无法将“20000101”转换为日期时间。即使我们将其设置为 DateTime 列。

"errorCode": "2200",
    "message": "ErrorCode=TypeConversionFailure,Exception occurred when converting value '20000101' for column name 'dd' from type 'String' (precision:, scale:) to type 'DateTime' (precision:, scale:). Additional info: String was not recognized as a valid DateTime."

为此,我们必须在数据流中使用DerivedColumn进行一些数据转换:

在此处输入图像描述

表达:

toTimestamp(toDate(concat(substring(dd,0, 4), '-',substring(dd,5, 2),'-',substring(dd,7, 2))))

在此处输入图像描述

然后它可能会映射到您的水槽表。


推荐阅读