我正在ADFv2中创建一个管道,该管道调用输出JSON的Azure函数。然后,我将该JSON传递到存储过程Activity中,但是该存储过程没有获取JSON文本,而是获取了对象类型。我已经能够成功传递单个JSON值。
以下是一些尝试及其结果:
@activity('AzureFunction').output - Dictionary Error
@activity('AzureFunction').output.FileList - List Error
@activity('AzureFunction').output.fileList[0].FileName - Sent name of file (Hospital_Overview.csv)
@activity('AzureFunction').output.firstRow - Cannot be evaluated becauase property firstRow doesn't exist
@activity('AzureFunction').output.fileList - List Error
@activity('AzureFunction').output.production - Sent value of production JSON node (False)
@activity('AzureFunction').output() - Invalid Template
@activity('AzureFunction').output.response - activity('AzureFunction').output.response' cannot be evaluated because property 'response' doesn't exist, available properties are 'fileList, production, effectiveIntegrationRuntime, executionDuration, durationInQueue, billingReference'
@activity('AzureFunction').output.ToString() - unable to parse
@activity('AzureFunction').output.value - The expression 'activity('AzureFunction').output.value' cannot be evaluated because property 'value' doesn't exist, available properties are 'fileList, production, effectiveIntegrationRuntime, executionDuration, durationInQueue, billingReference'
发送到存储过程的JSON如下:
{
"fileList": [
{
"FileName": "File1.csv",
"FileDate": "2019-12-13T11:26:54Z",
"Downloaded": false,
},
{
"FileName": "File2",
"FileDate": "2019-12-13T11:29:26Z",
"Downloaded": false,
}
],
"production": false,
"effectiveIntegrationRuntime": "DefaultIntegrationRuntime (East US 2)",
"executionDuration": 6,
"durationInQueue": {
"integrationRuntimeQueue": 0
},
"billingReference": {
"activityType": "ExternalActivity",
"billableDuration": {
"Managed": 0.016666666666666666
}
}
}
我希望以下选项起作用:
@activity('AzureFunction').output
存储过程给我以下错误消息:
错误号:13609。严重性:16.状态:3.步骤:dbo.Control_Insert_FromAzureFunction。线:76。消息:JSON文本格式不正确。在位置0找到意外的字符'S'。
我将传入的JSON定义为NVARCHAR(MAX)
并记录下来,这样我就可以看到得到的内容:
System.Collections.Generic.Dictionary`2[System.String,System.Object]
因此,在Azure SQL数据库中未传递文本,而是传递了对象。我或者需要知道如何将Azure SQL数据库中的对象转换为字符串,或者只是通过存储过程活动传递JSON文本。
这是我正在使用的存储过程:
CREATE PROCEDURE [dbo].[Control_Insert_FromAzureFunction]
@json NVARCHAR(MAX)
AS
BEGIN
DECLARE @RC INT = 0,
@StatusMessage VARCHAR(MAX) = 'Pending...',
@ErrorDescription VARCHAR(MAX) = '',
@ProcedureName VARCHAR(MAX) = object_name(@@PROCID),
@LogId INT = 0,
@ProcessQueueId INT = 0;
BEGIN TRY
IF object_id('tempdb..#File') IS NOT NULL
BEGIN
DROP TABLE #File;
END;
CREATE TABLE #File
(
[FileName] VARCHAR(512) NOT NULL,
[FileDate] DATETIME2 NOT NULL,
[Downloaded] BIT NOT NULL
);
INSERT INTO #File ([FileName], [OutputFileName], [FileDate], [Downloaded],
[SFTPElapsedTime], [SFTPStartTime], [SFTPEndTime])
SELECT
json_value(files.[Value], '$.FileName') AS [FileName],
CAST(json_value(files.[Value], '$.FileDate') AS DATETIME2) AS [FileDate],
CAST(json_value(files.[Value], '$.Downloaded') AS BIT) AS [Downloaded]
FROM
OPENJSON(@json, '$.fileStatus') AS files;
END TRY
BEGIN CATCH
SET @RC = -1;
SET @StatusMessage = @json;
EXEC [dbo].[Log_Merge] @LogId = @LogId OUT
, @ProcessQueueId = @ProcessQueueId
, @ProcedureName = @ProcedureName
, @StatusMessage = @StatusMessage
, @ErrorDescription = @ErrorDescription
, @ReturnCode = @RC;
END CATCH;
END
我需要将对象包装在字符串函数中。它看起来像原始类型,例如string和int发送其值,但是Dictionary会发送对象类型,除非您特别要求输入字符串值。希望这可以在将来帮助其他为此奋斗的人。
@string(activity('GetDefinitiveDataFunction').output)