gpt4 book ai didi

Azure 数据工厂,将 REST GET 响应传递给 Azure SQL 数据库中的存储过程

转载 作者:行者123 更新时间:2023-12-04 04:02:03 25 4
gpt4 key购买 nike

我正在尝试构建一个(我认为)非常简单的管道:

  1. 获取 GET 操作的文本正文。
  2. 将 (json) 输出按原样(= ADF 中不需要转换)传递到 Azure SQL Server 数据库中存储过程的“Json”参数。存储过程处理(复杂的)解析/映射。

我认为这只需 1 个复制事件即可完成,但现在我认为我错了。

在 de Copy 事件中,Sink 配置如下所示:

"sink": {
"type": "AzureSqlSink",
"sqlWriterStoredProcedureName": "[dbo].[spParseJson]",
"sqlWriterTableType": "What to enter here?",
"storedProcedureTableTypeParameterName": "What to enter here?",
"storedProcedureParameters": {
"Json": {
"type": "String",
"value": "<output of Source>"
}
}
}

我确实尝试阅读和理解文档,但恕我直言,文档并没有解释太多,或者解释得很模糊。

“Source 的输出”应该是 Source 的输出。但是要使用什么函数或变量呢?

我应该为“sqlWriterTableType”/“storedProcedureTableTypeParameterName”输入什么?经过一番挖掘,我了解到 ADF 将创建临时表等,但这不是我想要的。

我还尝试了另一种方法:

  1. 使用 Web 事件来下载 Json。
  2. 使用输入执行 SP:@Activity("WebactivityName").output。

但后来我发现Web事件限制为1MB。 Json 约为 1.5 MB。如果没有限制,那么我会有一个解决方案。啊。

仅供引用:Json 的内容具有动态变化的架构,并且结构不佳,因此我实际上无法使用 ADF 中的标准映射功能。

感谢任何帮助或指导。如果您知道一些内容丰富的文档,那么这也会有所帮助。

最佳答案

我更新了这个答案,将其分为两部分。第一部分涉及一个简单的实现,它将 Json 响应大小限制为 ~1MB。第二部分处理更复杂的实现,不对 Json 响应大小施加此限制。

第 1 部分

您想要做的是将 Web 事件与存储过程事件链接起来。 Chain output of Activity 1 to 2

这将允许您将 GetJson Web Activity 的输出传递到存储过程 Activity。

接下来,您需要向存储过程事件添加一个参数,以便它可以动态接收第一步的链接输出。

Add parameter to stored procedure

这应该使您能够成功传递信息。

这是相关管道的 Json 表示形式:

{
"name": "get-request-output-to-mssql-stored-procedure",
"properties": {
"activities": [
{
"name": "GetJson",
"type": "WebActivity",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"url": "https://jsonplaceholder.typicode.com/posts/1",
"method": "GET"
}
},
{
"name": "Exec stored proc",
"type": "SqlServerStoredProcedure",
"dependsOn": [
{
"activity": "GetJson",
"dependencyConditions": [
"Succeeded"
]
}
],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"storedProcedureParameters": {
"Json": {
"value": {
"value": "@activity('GetJson').output",
"type": "Expression"
},
"type": "String"
}
}
},
"linkedServiceName": {
"referenceName": "your-server-def",
"type": "LinkedServiceReference"
}
}
],
"annotations": []
}

}

第 2 部分

我们将结合使用查找事件以及链接服务定义和 Json 数据集定义,而不是创建 Web 事件。

您需要创建 HTTP 类型的链接服务。

Create Linked Service of Type HTTP

并将其配置为使用您想要从中获取 Json 响应的 URL:

Configure Linked Service

然后,您可以创建一个新的数据集(HTTP 类型),它将使用此链接服务来获取数据。

Create a Dataset of type HTTP

并选择 Json 作为其格式类型:

Select Json

然后您可以设置请求 URL,并将架构(除非您需要)设置为 None。

然后,您可以创建一个使用 Json 数据集作为源数据集的 Lookup 事件,并将请求方法设置为 GET。

Use Lookup to get Json response

这是相关管道的 Json 表示形式:

{
"name": "get-request-output-to-mssql-stored-procedure-2",
"properties": {
"activities": [
{
"name": "Exec stored proc",
"type": "SqlServerStoredProcedure",
"dependsOn": [
{
"activity": "RetrieveJson",
"dependencyConditions": [
"Succeeded"
]
}
],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"storedProcedureParameters": {
"Json": {
"value": {
"value": "@activity('RetrieveJson').output",
"type": "Expression"
},
"type": "String"
}
}
},
"linkedServiceName": {
"referenceName": "ASD_SINGLE",
"type": "LinkedServiceReference"
}
},
{
"name": "RetrieveJson",
"type": "Lookup",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "JsonSource",
"storeSettings": {
"type": "HttpReadSettings",
"requestMethod": "GET"
},
"formatSettings": {
"type": "JsonReadSettings"
}
},
"dataset": {
"referenceName": "JsonDataset1",
"type": "DatasetReference"
},
"firstRowOnly": false
}
}
],
"annotations": []
}

}

关于Azure 数据工厂,将 REST GET 响应传递给 Azure SQL 数据库中的存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62935804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com