提问人:BM4291 提问时间:11/2/2023 最后编辑:Thom ABM4291 更新时间:11/2/2023 访问量:77
未找到映射 JSON 列
Mapping JSON column not found
问:
我在 ADF 中有一个管道,由于找不到列而突然失败:“Prop_1”
ErrorCode=MappingColumnNameNotFound,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=在源表中找不到列名“Prop_1”。请检查“映射”中的列,Source=Microsoft.DataTransfer.ClientLibrary,'
这是一个 Excel 到 SQL 的复制任务,我正在使用的 Excel 文档没有列标题,因此在我的映射 JSON 中传递Prop_X(摘录如下):
{
"type": "TabularTranslator",
"typeConversion": true,
"typeConversionSettings": {
"culture": "en-gb"
},
"mappings": [
{
"source": {
"name": "Prop_0"
},
"sink": {
"name": "EmployeeID"
}
},
{
"source": {
"name": "Prop_1"
},
"sink": {
"name": "Forename"
}
}
]
}
我已通过 UI 手动检查了文件,在尝试导入映射时,ADF 返回序号值,而不是像以前那样返回Prop_X值。显示序数映射的 ADF
但是,当我单击预览数据时,Prop_X清晰可见:显示道具列的预览源
从 ~3 个月前开始,已经有一篇关于此的未回复帖子(上一篇文章)。我在 Microsoft 上看不到任何其他内容,文档表明我设置的内容是正确的。
有什么建议吗?
答:
根据文档,
对于带分隔符的文本文件和不带标题的 excel 文件,在映射中将列视为序号而不是名称。
如果文件没有任何标头,则映射应带有序号,否则会出现上述错误。即使您不在映射中导入架构,它也会给出相同的错误。
为了避免此错误,您的映射需要使用序号,这意味着您需要在复制活动中导入此类文件的架构。
如果要在复制活动映射中动态设置架构,而不是手动导入架构,请按照以下步骤操作。
使用“获取元数据”活动从目标 SQL 表中获取结构数组。
使用字符串启动动态映射,如下所示。{"type": "TabularTranslator","mappings":
现在,使用 Foreach 活动生成映射数组。在 Foreach 活动中给出此表达式,并检查 Sequential.
@range(0,activity('Get Metadata1').output.columnCount)
在 ForEach 中,使用将变量 activity 附加到空并给出以下表达式。
@json(concat('{"source": {"ordinal":"',string(add(item(),1)),'","type": "String"},"sink": {"name": "',activity('Get Metadata1').output.structure[item()].name,'","type": "',activity('Get Metadata1').output.structure[item()].logicalType,'"}}'))
在 ForEach 之后,采用另一个集合变量活动,并使用以下表达式连接总映射。
@concat(variables('schema'),string(variables('mapping')),',"typeConversion": true,"typeConversionSettings":{"allowDataTruncation": false,"treatBooleanAsNumber": false}}')
这将生成如下示例的架构 JSON。
在复制活动映射动态内容中提供此变量。final_schema
@json(variables('final_schema'))
现在,调试管道,您的 excel 数据将复制到 SQL 表中。
结果:
我的管道 JSON:
{
"name": "pipeline2",
"properties": {
"activities": [
{
"name": "Copy data1",
"type": "Copy",
"dependsOn": [
{
"activity": "final_schema",
"dependencyConditions": [
"Succeeded"
]
}
],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "ExcelSource",
"storeSettings": {
"type": "AzureBlobFSReadSettings",
"recursive": true,
"enablePartitionDiscovery": false
}
},
"sink": {
"type": "AzureSqlSink",
"writeBehavior": "insert",
"sqlWriterUseTableLock": false
},
"enableStaging": false,
"translator": {
"value": "@json(variables('final_schema'))",
"type": "Expression"
}
},
"inputs": [
{
"referenceName": "Excel1",
"type": "DatasetReference"
}
],
"outputs": [
{
"referenceName": "AzureSqlTable1",
"type": "DatasetReference"
}
]
},
{
"name": "Get Metadata1",
"type": "GetMetadata",
"dependsOn": [],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"dataset": {
"referenceName": "AzureSqlTable1",
"type": "DatasetReference"
},
"fieldList": [
"structure",
"columnCount"
]
}
},
{
"name": "ForEach1",
"type": "ForEach",
"dependsOn": [
{
"activity": "Start schema",
"dependencyConditions": [
"Succeeded"
]
}
],
"userProperties": [],
"typeProperties": {
"items": {
"value": "@range(0,activity('Get Metadata1').output.columnCount)",
"type": "Expression"
},
"isSequential": true,
"activities": [
{
"name": "Append variable1",
"type": "AppendVariable",
"dependsOn": [],
"userProperties": [],
"typeProperties": {
"variableName": "mapping",
"value": {
"value": "@json(concat('{\"source\": {\"ordinal\":\"',string(add(item(),1)),'\",\"type\": \"String\"},\"sink\": {\"name\": \"',activity('Get Metadata1').output.structure[item()].name,'\",\"type\": \"',activity('Get Metadata1').output.structure[item()].logicalType,'\"}}'))",
"type": "Expression"
}
}
}
]
}
},
{
"name": "Start schema",
"type": "SetVariable",
"dependsOn": [
{
"activity": "Get Metadata1",
"dependencyConditions": [
"Succeeded"
]
}
],
"policy": {
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"variableName": "schema",
"value": "{\"type\": \"TabularTranslator\",\"mappings\":"
}
},
{
"name": "final_schema",
"type": "SetVariable",
"dependsOn": [
{
"activity": "ForEach1",
"dependencyConditions": [
"Succeeded"
]
}
],
"policy": {
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"variableName": "final_schema",
"value": {
"value": "@concat(variables('schema'),string(variables('mapping')),',\"typeConversion\": true,\"typeConversionSettings\":{\"allowDataTruncation\": false,\"treatBooleanAsNumber\": false}}')",
"type": "Expression"
}
}
}
],
"variables": {
"schema": {
"type": "String"
},
"mapping": {
"type": "Array"
},
"final_schema": {
"type": "String"
}
},
"annotations": []
}
}
评论