通过C#.NET Framework管理的数据工厂将数据从Blob复制到Azure SQL时,忽略错误的行

时间:2020-04-04 18:58:54

标签: c# azure azure-sql-database azure-data-factory-2

我正在按照this tutorial从Blob中的平面文件加载Azure SQL中的数据。

此方法需要C#.NET Framework控制台应用程序来创建/管理Blob数据集,Azure SQL接收器和数据工厂。

唯一的问题是,对于大而凌乱的数据文件,我不可避免地会遇到一些包含额外定界符的行,或者以其他方式畸形的行。数据太大,无法在上传到Blob之前在本地清除。

通常的解决方案是忽略不良行,即忽略allow fault tolerance

有一个使用JSON的示例:

"typeProperties": {
    "source": {
        "type": "BlobSource"
    },
    "sink": {
        "type": "SqlSink",
    },
    "enableSkipIncompatibleRow": true,
    "redirectIncompatibleRowSettings": {
         "linkedServiceName": {
              "referenceName": "<Azure Storage or Data Lake Store linked service>",
              "type": "LinkedServiceReference"
            },
            "path": "redirectcontainer/erroroutput"
     }
}

但是,我无法确定C#中是否存在与此等效的功能。我尝试通过以下方法修改Azure SQL接收器的原始连接字符串:

    // Specify the sink Azure SQL Database information
    string azureSqlConnString =
        "Server=tcp:mydb.database.windows.net,1433;" +
        "Database=mydb;" +
        "User ID=myuser;" + 
        "Password=mypassword;" + 
        "Trusted_Connection=False;Encrypt=True;Connection Timeout=30";
    string azureSqlTableName = "dbo.mytable";

    string storageLinkedServiceName = "AzureStorageLinkedService";
    string sqlDbLinkedServiceName = "AzureSqlDbLinkedService";
    string blobDatasetName = "BlobDataset";
    string sqlDatasetName = "SqlDataset";
    string pipelineName = "Adfv2TutorialBlobToSqlCopy";

对此:

    // Specify the sink Azure SQL Database information
    string azureSqlConnString =
        "Server=tcp:mydb.database.windows.net,1433;" +
        "Database=mydb;" +
        "User ID=myuser;" + 
        "Password=mypassword;" + 
        "enableSkipIncompatibleRow= true;" + 
        "Trusted_Connection=False;Encrypt=True;Connection Timeout=30";
    string azureSqlTableName = "dbo.mytable";

    string storageLinkedServiceName = "AzureStorageLinkedService";
    string sqlDbLinkedServiceName = "AzureSqlDbLinkedService";
    string blobDatasetName = "BlobDataset";
    string sqlDatasetName = "SqlDataset";
    string pipelineName = "Adfv2TutorialBlobToSqlCopy";

作为猜测,但是没有用:

“消息”: “ ErrorCode = UserErrorInvalidDbConnectionString,'Type = Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message =无效 提供的数据库连接字符串。在以下位置检查连接字符串 '水槽' 端。,Source = Microsoft.DataTransfer.ClientLibrary,''Type = System.ArgumentException,Message =关键字 不支持:'enableskipincompatiblerow'。,Source = System.Data,'“,

有没有办法做到这一点?

SkipErrorFile类的CopyActivity property说,它获得或设置了容错能力。我得到了CopyActivity实现,可以使用SkipErrorFile = new SkipErrorFile { }接受该属性,但是它似乎并没有以期望的方式更改行为。

1 个答案:

答案 0 :(得分:0)

我有一种解决方法,但不是真正的解决方案,因此我将进行自我回答,但不选择答案作为解决方案。

解决方法是创建一个伪造的分隔符(在数据中不存在,例如\t\t)和一个只有1列的Azure SQL接收器表。

从那里我可以将数据加载到单个列中,并在使用Azure SQL后,可以使用SQL或Databricks中的任何语言(Python,R,Scala或SQL)解析它,以便可以使用HPC云大规模清理和解析数据的环境。