1

我有一个带有 txt 文件的天蓝色 blob。有些列有空值,所以当它们保存到数据库表中时,它们是 NULL。我可以让它与直接的 SQL 和 SSIS ETL 包一起工作。

行示例:
1002,100,Butter,whipped with salt BUTTER,WHIPPED W SALT,Y,0,6.38,,,

最后三个假设为空。

当我尝试使用 ADF 时,出现此错误:

复制活动遇到用户错误:ErrorCode=UserErrorInvalidDataValue,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=Column 'CarbohydratesFactor'包含无效值''。无法将 ' ' 转换为类型 'Decimal'。,Source=Microsoft.DataTransfer.Common,''Type=System.FormatException,Message=输入字符串的格式不正确。,Source=mscorlib,'。

食物描述AzureBlob:

{
    "name": "FoodDescriptionsAzureBlob",
    "properties": {
        "structure": [
            {
                "name": "NutrientDatabankNumber",
                "type": "Int32"
            },
            {
                "name": "FoodGroupCode",
                "type": "Int32"
            },
            {
                "name": "LongDescription",
                "type": "String"
            },
            {
                "name": "ShortDescription",
                "type": "String"
            },
            {
                "name": "CommonName",
                "type": "String"
            },
            {
                "name": "ManufacturerName",
                "type": "String"
            },
            {
                "name": "Survey",
                "type": "String"
            },
            {
                "name": "ReferenceDescription",
                "type": "String"
            },
            {
                "name": "RefusePercentage",
                "type": "Int32"
            },
            {
                "name": "ScientificName",
                "type": "String"
            },
            {
                "name": "NitrogenFactor",
                "type": "Decimal"
            },
            {
                "name": "ProteinFactor",
                "type": "Decimal"
            },
            {
                "name": "FatFactor",
                "type": "Decimal"
            },
            {
                "name": "CarbohydratesFactor",
                "type": "Decimal"
            }
        ],
        "published": false,
        "type": "AzureBlob",
        "linkedServiceName": "AzureStorageLinkedService",
        "typeProperties": {
            "fileName": "FOOD_DES.txt",
            "folderPath": "gym-nutrition-data/NutrientData/",
            "format": {
                "type": "TextFormat",
                "rowDelimiter": "\n",
                "columnDelimiter": "^",
                "nullValue": "",
                "quoteChar": "~"
            }
        },
        "availability": {
            "frequency": "Minute",
            "interval": 15
        },
        "external": true,
        "policy": {}
    }
}

FoodDescriptionsSQLAzure:

{
    "name": "FoodDescriptionsSQLAzure",
    "properties": {
        "structure": [
            {
                "name": "NutrientDatabankNumber",
                "type": "Int32"
            },
            {
                "name": "FoodGroupCode",
                "type": "Int32"
            },
            {
                "name": "LongDescription",
                "type": "String"
            },
            {
                "name": "ShortDescription",
                "type": "String"
            },
            {
                "name": "CommonName",
                "type": "String"
            },
            {
                "name": "ManufacturerName",
                "type": "String"
            },
            {
                "name": "Survey",
                "type": "String"
            },
            {
                "name": "ReferenceDescription",
                "type": "String"
            },
            {
                "name": "RefusePercentage",
                "type": "Int32"
            },
            {
                "name": "ScientificName",
                "type": "String"
            },
            {
                "name": "NitrogenFactor",
                "type": "Decimal"
            },
            {
                "name": "ProteinFactor",
                "type": "Decimal"
            },
            {
                "name": "FatFactor",
                "type": "Decimal"
            },
            {
                "name": "CarbohydratesFactor",
                "type": "Decimal"
            }
        ],
        "published": false,
        "type": "AzureSqlTable",
        "linkedServiceName": "AzureSqlLinkedService",
        "typeProperties": {
            "tableName": "FoodDescriptions"
        },
        "availability": {
            "frequency": "Minute",
            "interval": 15
        }
    }
}

管道:

{
    "name": "NutrientDataBlobToAzureSqlPipeline",
    "properties": {
        "description": "Copy nutrient data from Azure BLOB to Azure SQL",
        "activities": [
            {
                "type": "Copy",
                "typeProperties": {
                    "source": {
                        "type": "BlobSource",
                        "treatEmptyAsNull": true
                    },
                    "sink": {
                        "type": "SqlSink",
                        "writeBatchSize": 10000,
                        "writeBatchTimeout": "60.00:00:00"
                    }
                },
                "inputs": [
                    {
                        "name": "FoodGroupDescriptionsAzureBlob"
                    }
                ],
                "outputs": [
                    {
                        "name": "FoodGroupDescriptionsSQLAzure"
                    }
                ],
                "policy": {
                    "timeout": "01:00:00",
                    "concurrency": 1,
                    "executionPriorityOrder": "NewestFirst"
                },
                "scheduler": {
                    "frequency": "Minute",
                    "interval": 15
                },
                "name": "FoodGroupDescriptions",
                "description": "#1 Bulk Import FoodGroupDescriptions"
            },
            {
                "type": "Copy",
                "typeProperties": {
                    "source": {
                        "type": "BlobSource",
                        "treatEmptyAsNull": true
                    },
                    "sink": {
                        "type": "SqlSink",
                        "writeBatchSize": 10000,
                        "writeBatchTimeout": "60.00:00:00"
                    }
                },
                "inputs": [
                    {
                        "name": "FoodDescriptionsAzureBlob"
                    }
                ],
                "outputs": [
                    {
                        "name": "FoodDescriptionsSQLAzure"
                    }
                ],
                "policy": {
                    "timeout": "01:00:00",
                    "concurrency": 1,
                    "executionPriorityOrder": "NewestFirst"
                },
                "scheduler": {
                    "frequency": "Minute",
                    "interval": 15
                },
                "name": "FoodDescriptions",
                "description": "#2 Bulk Import FoodDescriptions"
            }
        ],
        "start": "2015-07-14T00:00:00Z",
        "end": "2015-07-14T00:00:00Z",
        "isPaused": false,
        "hubName": "gymappdatafactory_hub",
        "pipelineMode": "Scheduled"
    }
}

我试图在管道中设置 "treatEmptyAsNull": true ,但没​​有运气。

4

2 回答 2

3

我不得不"rowDelimiter": "\n",从 blob 数据集中删除。

于 2016-03-14T20:19:06.007 回答
2

大多数源文本文件都有行分隔符“\r\n”。使用行分隔符设置“\n”,最后一列的数据值“\r”不是空字符串,不会被视为空值。如果没有行分隔符设置,ADF Copy 默认使用行分隔符“\r\n”,最后一列将有空字符串,可以视为 null。

于 2016-03-16T12:18:31.907 回答