使用 Azure 函数调用的输出 (JSON) 在 ADFv2 中调用存储过程。传递类型,而不是 JSON 字符串?
Calling a stored procedure in ADFv2 with output (JSON) from an Azure Function call. Passing type, not JSON string?
我正在 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
存储过程给我以下错误信息:
Error number: 13609. Severity: 16. State: 3. Procedure: dbo.Control_Insert_FromAzureFunction. Line: 76.
Message: JSON text is not properly formatted. Unexpected character 'S' is found at position 0..
我将传入的 JSON 定义为 NVARCHAR(MAX)
并记录它,以便我可以看到我得到了什么:
System.Collections.Generic.Dictionary`2[System.String,System.Object]
所以在 Azure SQL 数据库中没有传递文本,而是传递了一个对象。我要么需要知道如何将 Azure SQL 数据库中的对象转换为字符串,要么只需要从存储过程 activity 传递 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)
我正在 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
存储过程给我以下错误信息:
Error number: 13609. Severity: 16. State: 3. Procedure: dbo.Control_Insert_FromAzureFunction. Line: 76.
Message: JSON text is not properly formatted. Unexpected character 'S' is found at position 0..
我将传入的 JSON 定义为 NVARCHAR(MAX)
并记录它,以便我可以看到我得到了什么:
System.Collections.Generic.Dictionary`2[System.String,System.Object]
所以在 Azure SQL 数据库中没有传递文本,而是传递了一个对象。我要么需要知道如何将 Azure SQL 数据库中的对象转换为字符串,要么只需要从存储过程 activity 传递 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)