[英]Mapping error in Azure Data Factory (connecting JSON in Blob storage to Azure SQL table)
[英]Azure Data Factory Get Metadata to get blob filenames and transfer them to Azure SQL database table part 2
我正在尝试在 Azure 数据工厂中使用获取元数据活动来获取 blob 文件名并将它们复制到 Azure SQL 数据库表。 我在 Get Metadata 活动之后添加了存储过程活动。 这是我的新活动存储过程,我按照建议添加了参数,但是我将名称更改为 JsonData,因为我的存储过程需要此参数。
这是我的存储过程。
/****** Object: StoredProcedure [dbo].[InsertDataJSON] Script Date: 10/14/2020 11:01:30 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*USE datafactorypoc1*/
ALTER PROCEDURE [dbo].[InsertDataJSON] (
@JsonData NVARCHAR (MAX)
)
AS
BEGIN
DECLARE @err int
INSERT INTO extractFileNameTest1 (ItemName, ItemType, EffIntegrationRunTieme, ExecutionDuration, DurationInQueue)
SELECT ItemName, ItemType, EffIntegrationRunTieme, ExecutionDuration, DurationInQueue
FROM OPENJSON (@JsonData, N'$') WITH (
ItemName VARCHAR(255) N'$.ItemName',
ItemType VARCHAR(255) N'$.ItemType',
EffIntegrationRunTieme VARCHAR(255) N'$.EffIntegrationRunTieme',
ExecutionDuration INT N'$.ExecutionDuration',
DurationInQueue INT N'$.DurationInQueue'
)
SELECT @err = @@ERROR
RETURN (@err)
END
我在存储过程中收到此错误:
{
"errorCode": "2402",
"message": "Execution fail against sql server. Sql error number: 13609. Error Message: JSON text is not properly formatted. Unexpected character 'S' is found at position 0.",
"failureType": "UserError",
"target": "Stored procedure1",
"details": []
}
但是当我检查输入时,它似乎已经成功读取了 json 字符串 itemName。
但是,当我检查输出时,它不存在。
你能帮我检查一下我在这里做错了什么吗? 是我的存储过程吗? 非常感谢您提前。
2020 年 10 月 15 日更新我创建了一个新管道并将 ForEach 活动中的存储过程移动到连接到 Get_Filename_2 而不是第一个广告跟随:
在这里,我将参数的值更改为 Get_Filename_2 并输出为 itemName 而不是 childitems(因为我在使用 childitems 时出错,因为 childitems 来自 Get_Filename_1 而不是 2)。
执行管道(失败)后,最后一个存储过程的输入是:
{
"storedProcedureName": "[dbo].[InsertDataJSON]",
"storedProcedureParameters": {
"JsonData": {
"value": "FRRNSC84FIN1_A2276801_20200103-152534.json",
"type": "String"
}
}
}
输出是:
{
"effectiveIntegrationRuntime": "DefaultIntegrationRuntime (West Europe)",
"executionDuration": 0,
"durationInQueue": {
"integrationRuntimeQueue": 0
},
"billingReference": {
"activityType": "ExternalActivity",
"billableDuration": [
{
"meterType": "AzureIR",
"duration": 0.016666666666666666,
"unit": "Hours"
}
]
}
}
对于此管道,它失败并显示以下错误消息。
{
"errorCode": "2402",
"message": "Execution fail against sql server. Sql error number: 13609. Error Message: JSON text is not properly formatted. Unexpected character 'F' is found at position 0.\r\nFRRNSC84FIN1_A2276801_20200103-152534.json",
"failureType": "UserError",
"target": "Stored procedure1",
"details": []
}
在我的旧管道上,我在 ForEach 循环之外存储了过程。 管道没有失败:
这是最后一个存储过程活动的输入:
{
"storedProcedureName": "[dbo].[InsertDataJSON]",
"storedProcedureParameters": {
"JsonData": {
"value": "[{\"name\":\"FRRNSC84FIN1_A2274001_20200103-143748_back_camera_0.jpeg\",\"type\":\"File\"},{\"name\":\"FRRNSC84FIN1_A2274001_20200103-143748_right_camera_0.jpeg\",\"type\":\"File\"},{\"name\":\"FRRNSC84FIN1_A2274801_20200103-144811_right_camera_0.jpeg\",\"type\":\"File\"},{\"name\":\"FRRNSC84FIN1_A2275201_20200103-145229_right_camera_0.jpeg\",\"type\":\"File\"},{\"name\":\"FRRNSC84FIN1_A2276801_20200103-152534.json\",\"type\":\"File\"}]"
}
}
}
这是输出:
{
"effectiveIntegrationRuntime": "DefaultIntegrationRuntime (West Europe)",
"executionDuration": 0,
"durationInQueue": {
"integrationRuntimeQueue": 0
},
"billingReference": {
"activityType": "ExternalActivity",
"billableDuration": [
{
"meterType": "AzureIR",
"duration": 0.016666666666666666,
"unit": "Hours"
}
]
}
}
该管道成功运行,但是 SQL 中的结果并不是我真正期望的,在第一个 json 字符串之前还有许多 NULL 值,但它将所有 itemName 插入到同一位置。 这是因为我认为它在 ForEach 循环之外。 但是为什么要插入这么多NULL呢?
这是我修改的存储过程:
/****** Object: StoredProcedure [dbo].[InsertDataJSON] Script Date: 15/10/2020 10:31:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*USE datafactorypoc1*/
ALTER PROCEDURE [dbo].[InsertDataJSON] (
@JsonData NVARCHAR (MAX)
)
AS
BEGIN
PRINT @JsonData
/*INSERT INTO Logs values (DEFAULT, @JsonData)*/
INSERT INTO extractFileNameTest1 values (@JsonData, DEFAULT)
SELECT * FROM
OPENJSON (@JsonData)
WITH (
ItemName VARCHAR(255) N'$.ItemName',
ItemType VARCHAR(255) N'$.ItemType'
)
END
我尝试删除测试 SQL 表中的所有数据以查看第二个失败管道的输出。 我注意到它确实正确解析了我的表中的 json 字符串文件名以及所有这些文件名(我在 blob 存储中只有 5 个文件)。 但其他数据为NULL。
总而言之,新管道的 SQL 表中的结果要好得多,表的不同单元格上的每个文件名但我的管道运行失败。 你能帮我检查一下我在这里做错了什么吗? 它是存储过程还是 ForEach 循环中最后一个存储过程活动中的表达式?
非常感谢您提前。
对于这个场景,我只使用 1 个获取元数据活动:获取元数据活动的数据集 = 来自 Blob 存储的二进制文件获取元数据的字段列表 = 子项
此获取元数据活动具有连接到 ForEach 活动的输出:ForEach 活动设置 => Items => @activity('Get_FileName_1').output.childItems
在 ForEach 活动中,有 1 个活动是存储过程:存储过程设置已链接服务 = Azure SQL 数据库与选定的存储过程。 在我编写的存储过程中,我定义了将从 blob 文件名中读取的列。 然后,对于存储过程活动的参数,我在存储过程中定义了完全相同的参数数字 = @JsonData 的所有列。 然后,对于参数的每个值,我使用 Azure 数据工厂函数 @substring 来提取 blob 文件名的不同部分。 然后将这些插入到 Azure SQL 表中的正确列。
Substring 函数的来源: https : //docs.microsoft.com/en-us/azure/data-factory/control-flow-expression-language-functions#substring
在sp
帮助下加载get_metadata
活动的输出时,我也遇到了同样的问题。
简单的答案是在将get_metadata
活动的输出提供给SP
参数时,您需要将其转换为字符串。 像下面这样:
@string(activity('get_metadata').output.childitems)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.