用于从 SQL 到 FTP 获取数据的 Azure 逻辑
Azure Logic for getting data from SQL to FTP
我的任务是从 SQL 获取数据并将数据作为 CSV 文件上传到 FTP 服务器。
现在我已经为单个 SQL 行完成了这项工作,效果很好。 我遇到的问题是遍历所有行(foreach 循环)并将这些行作为 CSV 文件的内容插入。我已经尝试了 FTP 创建文件任务在 foreach 循环中,但我一次只能访问一行以设置为文件的内容 - 我需要所有行!
还要记住,这些文件将有 20 万多行。
我当然可以为此编写一个 C# 控制台应用程序,但我在没有编写任何代码的情况下轻松地做到了这一点,这似乎是一项值得的努力。
我们最近为此场景添加了 "Table" 原语,设计器中的支持仍在进行中,但您可以在代码视图中使用它。
在下面的场景中,我从 SQL Azure 中的 table 获取行,使用 SQL 查询中的数据生成一个包含两列的 CSV(名字,姓氏姓名),然后通过 e-mail.
发送
"Get_rows": {
"inputs": {
"host": {
"api": {
"runtimeUrl": "https://logic-apis-southcentralus.azure-apim.net/apim/sql"
},
"connection": {
"name": "@parameters('$connections')['sql']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/tables/@{encodeURIComponent(encodeURIComponent('[SalesLT].[Customer]'))}/items",
"queries": {
"$top": 10
}
},
"runAfter": {},
"type": "ApiConnection"
},
"tableCsv0": {
"inputs": {
"columns": [
{
"header": "First Name",
"value": "@item()?['FirstName']"
},
{
"header": "Last Name",
"value": "@item()?['LastName']"
}
],
"format": "csv",
"from": "@body('Get_rows')?['value']"
},
"runAfter": {
"Get_rows": [
"Succeeded"
]
},
"type": "Table"
},
"Send_an_email": {
"inputs": {
"body": {
"Body": "@body('tableCsv0')",
"Subject": "Subject",
"To": "deli@microsoft.com"
},
"host": {
"api": {
"runtimeUrl": "https://logic-apis-southcentralus.azure-apim.net/apim/office365"
},
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/Mail"
},
"runAfter": {
"tableCsv0": [
"Succeeded"
]
},
"type": "ApiConnection"
}
因此,只是跟进以显示 Derek 的回答如何帮助我解决我的问题,即在 FTP 服务器上获取大量行到一个文件。我最终使用了 Execute Stored Procedure 操作的输出主体,因为 GetRows 操作被限制为 512 行。
注意:由于 Table 操作在设计器中不可用,但是,在代码查看器中执行所有操作,打开设计器导致问题并一次性删除了我的所有代码。
"actions": {
"Create_file": {
"inputs": {
"body": "@body('tableCsv0')",
"host": {
"api": {
"runtimeUrl": "https://logic-apis-northeurope.azure-apim.net/apim/ftp"
},
"connection": {
"name": "@parameters('$connections')['ftp']['connectionId']"
}
},
"method": "post",
"path": "/datasets/default/files",
"queries": {
"folderPath": "transactions/ready/ecommerce/tickets_test/",
"name": "grma_tickets_@{formatDateTime(utcNow(),'yyyyMMdd_hhmmss')}.csv"
}
},
"runAfter": {
"tableCsv0": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Execute_stored_procedure": {
"inputs": {
"host": {
"api": {
"runtimeUrl": "https://logic-apis-northeurope.azure-apim.net/apim/sql"
},
"connection": {
"name": "@parameters('$connections')['sql']['connectionId']"
}
},
"method": "post",
"path": "/datasets/default/procedures/@{encodeURIComponent(encodeURIComponent('[Scheduledjob].[GetBArcodesForGRMA]'))}"
},
"runAfter": {},
"type": "ApiConnection"
},
"tableCsv0": {
"inputs": {
"columns": [
{
"header": "EventDateTime",
"value": "@item()?['EventDateTime']"
},
{
"header": "EventName",
"value": "@item()?['EventName']"
}
],
"format": "csv",
"from": "@body('Execute_stored_procedure')['ResultSets']['Table1']"
},
"runAfter": {
"Execute_stored_procedure": [
"Succeeded"
]
},
"type": "Table"
}
我的任务是从 SQL 获取数据并将数据作为 CSV 文件上传到 FTP 服务器。
现在我已经为单个 SQL 行完成了这项工作,效果很好。 我遇到的问题是遍历所有行(foreach 循环)并将这些行作为 CSV 文件的内容插入。我已经尝试了 FTP 创建文件任务在 foreach 循环中,但我一次只能访问一行以设置为文件的内容 - 我需要所有行!
还要记住,这些文件将有 20 万多行。
我当然可以为此编写一个 C# 控制台应用程序,但我在没有编写任何代码的情况下轻松地做到了这一点,这似乎是一项值得的努力。
我们最近为此场景添加了 "Table" 原语,设计器中的支持仍在进行中,但您可以在代码视图中使用它。
在下面的场景中,我从 SQL Azure 中的 table 获取行,使用 SQL 查询中的数据生成一个包含两列的 CSV(名字,姓氏姓名),然后通过 e-mail.
发送"Get_rows": {
"inputs": {
"host": {
"api": {
"runtimeUrl": "https://logic-apis-southcentralus.azure-apim.net/apim/sql"
},
"connection": {
"name": "@parameters('$connections')['sql']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/tables/@{encodeURIComponent(encodeURIComponent('[SalesLT].[Customer]'))}/items",
"queries": {
"$top": 10
}
},
"runAfter": {},
"type": "ApiConnection"
},
"tableCsv0": {
"inputs": {
"columns": [
{
"header": "First Name",
"value": "@item()?['FirstName']"
},
{
"header": "Last Name",
"value": "@item()?['LastName']"
}
],
"format": "csv",
"from": "@body('Get_rows')?['value']"
},
"runAfter": {
"Get_rows": [
"Succeeded"
]
},
"type": "Table"
},
"Send_an_email": {
"inputs": {
"body": {
"Body": "@body('tableCsv0')",
"Subject": "Subject",
"To": "deli@microsoft.com"
},
"host": {
"api": {
"runtimeUrl": "https://logic-apis-southcentralus.azure-apim.net/apim/office365"
},
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/Mail"
},
"runAfter": {
"tableCsv0": [
"Succeeded"
]
},
"type": "ApiConnection"
}
因此,只是跟进以显示 Derek 的回答如何帮助我解决我的问题,即在 FTP 服务器上获取大量行到一个文件。我最终使用了 Execute Stored Procedure 操作的输出主体,因为 GetRows 操作被限制为 512 行。
注意:由于 Table 操作在设计器中不可用,但是,在代码查看器中执行所有操作,打开设计器导致问题并一次性删除了我的所有代码。
"actions": {
"Create_file": {
"inputs": {
"body": "@body('tableCsv0')",
"host": {
"api": {
"runtimeUrl": "https://logic-apis-northeurope.azure-apim.net/apim/ftp"
},
"connection": {
"name": "@parameters('$connections')['ftp']['connectionId']"
}
},
"method": "post",
"path": "/datasets/default/files",
"queries": {
"folderPath": "transactions/ready/ecommerce/tickets_test/",
"name": "grma_tickets_@{formatDateTime(utcNow(),'yyyyMMdd_hhmmss')}.csv"
}
},
"runAfter": {
"tableCsv0": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Execute_stored_procedure": {
"inputs": {
"host": {
"api": {
"runtimeUrl": "https://logic-apis-northeurope.azure-apim.net/apim/sql"
},
"connection": {
"name": "@parameters('$connections')['sql']['connectionId']"
}
},
"method": "post",
"path": "/datasets/default/procedures/@{encodeURIComponent(encodeURIComponent('[Scheduledjob].[GetBArcodesForGRMA]'))}"
},
"runAfter": {},
"type": "ApiConnection"
},
"tableCsv0": {
"inputs": {
"columns": [
{
"header": "EventDateTime",
"value": "@item()?['EventDateTime']"
},
{
"header": "EventName",
"value": "@item()?['EventName']"
}
],
"format": "csv",
"from": "@body('Execute_stored_procedure')['ResultSets']['Table1']"
},
"runAfter": {
"Execute_stored_procedure": [
"Succeeded"
]
},
"type": "Table"
}