使用 Azure 函数调用的输出 (JSON) 在 ADFv2 中调用存储过程.传递类型,而不是 JSON 字符串?



>我正在 ADFv2 中创建一个管道,用于调用输出 JSON 的 Azure 函数。然后,我将该 JSON 传递到存储过程活动中,但存储过程不会获取 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

我需要将对象包装在字符串函数中。 它看起来像字符串和 int 等基元类型发送其值,但字典会发送对象类型,除非您特别要求字符串值。 希望这可以帮助其他人在未来为此苦苦挣扎。

@string(activity('GetDefinitiveDataFunction').output)

相关内容

  • 没有找到相关文章

最新更新