首页 文章

Azure数据工厂复制活动无法将字符串(从csv)映射到Azure SQL表sink uniqueidentifier字段

提问于
浏览
1

我有一个Azure数据工厂(DF)管道,它包含一个Copy活动 . Copy活动使用HTTP连接器作为源来调用REST endpoints ,并返回与Azure SQL数据库表一起汇总的csv流 .

CSV包含字符串(例如 40f52caf-e616-4321-8ea3-12ea3cbc54e9 )时复制失败,这些字符串映射到目标表中的uniqueIdentifier字段,错误消息为 The given value of type String from the data source cannot be converted to type uniqueidentifier of the specified target column .

我试图用 {} 包装源字符串,如 {40f52caf-e616-4321-8ea3-12ea3cbc54e9} 但没有成功 .

如果我将目标表字段从 uniqueIdentifier 修改为 nvarchar(100) ,则复制活动将起作用 .

1 回答

  • 0

    我在你身边重现你的问题 .

    enter image description here

    原因是源和接收器的数据类型不匹配 . 您可以检查Data type mapping for SQL server .

    enter image description here

    您的源数据类型是 string ,它映射到nvarchar或varchar,而sql数据库中的 uniqueidentifier 需要在azure数据工厂中输入 GUID .

    因此,请在您的sql server sink中配置sql server stored procedure 作为解决方法 .

    请按照doc中的步骤操作:

    第1步:配置Sink数据集:

    enter image description here

    步骤2:在复制活动中配置接收部分,如下所示:

    enter image description here

    步骤3:在您的数据库中,定义与sqlWriterTableType同名的表类型 . 请注意,表类型的模式应与输入数据返回的模式相同 .

    CREATE TYPE [dbo].[CsvType] AS TABLE(
        [ID] [varchar](256) NOT NULL
    )
    

    步骤4:在您的数据库中,定义与SqlWriterStoredProcedureName同名的存储过程 . 它处理来自指定源的输入数据,并合并到输出表中 . 请注意,存储过程的参数名称应与dataset中定义的“tableName”相同 .

    Create PROCEDURE convertCsv @ctest [dbo].[CsvType] READONLY
    AS
    BEGIN
      MERGE [dbo].[adf] AS target
      USING @ctest AS source
      ON (1=1)
      WHEN NOT MATCHED THEN
          INSERT (id)
          VALUES (convert(uniqueidentifier,source.ID));
    END
    

    Output:

    enter image description here

    希望它可以帮助你 . 任何关注,请自由的感觉让我知道 .

相关问题