英文:
Generate a .tab file by creating a pipeline in Azure Data factory and upload to FTP
问题
我需要创建一个流程,其中我必须执行一些SQL查询,然后将查询的输出写入一个.tab文件(模板已存在)。创建完成这个.tab文件后,我需要将它上传到FTP。
由于我对此不太熟悉,有人可以帮助我,告诉我如何实现这个情景吗?
编辑[原始范围之外]
在我的.tab文件中,我需要前四行包含一些静态文本。第五行应该保持空白。SQL数据应该从第6行开始添加。有什么建议吗?
英文:
I need to create a pipeline where I have to exceute some SQL query, the output of which I have to write to a .tab file(template already have) . After creating this.tab file, I need to upload this file to FTP.
As I am new to this anyone please help me , how I can implement this scenario.
EDIT [not in original scope]
In my .tab file, I need to have first 4 line some static text. 5 th row should be kept empty.The sql data should be added from line 6 onwards. Any leads for this?
答案1
得分: 0
如果我理解你的问题正确,你正在尝试将一个.tab文件从Azure ADLS移动到某个SFTP服务器。
为了实现这个目标,
- 你可以创建一个连接到你的SFTP服务器的链接服务,然后创建一个数据集。
- 创建一个复制活动,使用一个数据集作为源,该数据集指向.tab文件,以及上面提到的SFTP数据集作为目的地。
这应该可以完成从ADLS/Blob复制文件到SFTP文件夹的任务。
英文:
If I get your question correctly, you are trying to move a .tab file from Azure ADLS to some SFTP server.
In order to achieve this,
- You can create a linked service which can connect to your SFTP server and then create a dataset.
- Create a copy activity and use a dataset which points to the .tab file as source and the above SFTP dataset as Sink
This should do the job of copying files from ADLS/Blob to SFTP folders
答案2
得分: 0
让我们将其分解为其组成部分:
执行SQL查询并将结果保存为TAB文件:
- 创建一个没有表的SQL数据集:
- 在您的管道中,添加一个复制活动。在源选项卡下,选择此SQL数据集。对于“使用查询”,选择“查询”选项并插入您的SELECT语句:
- 为TAB文件创建另一个数据集。在此示例中,我使用ADLS,但对其他存储类型来说,概念是相同的:
此示例旨在尽可能通用,因此它使用数据集参数来在运行时配置选项:
注意:
如果您愿意,可以硬编码这些值中的任何一个。在数据集中选择Tab分隔符更容易:以这种方式提供它需要您复制并粘贴Tab(例如从记事本中),而您在UI中看不到。
最重要的一步是不定义架构:
- 在复制活动下的接收选项卡中,选择此数据集并提供相应的值:
现在当此活动运行时,它将复制查询的结果到存储中的文本文件中。
上传TAB文件到FTP站点:
同样,使用复制活动进行此数据传输。对于纯数据传输,应该使用二进制数据集。
- 为您的存储帐户创建一个二进制数据集:
同样,此数据集使用参数,以使其可在各种情况下重复使用。
- 为您的FTP帐户创建一个二进制数据集:
此示例也使用参数。
- 在管道中添加一个复制活动,使用存储数据集作为源和FTP数据集作为接收。在每个数据集中填入适当的参数值,然后您应该有一个完成的管道,类似于这样:
注意:
-
正如您所看到的,参数化数据集非常强大。这是我写的一篇文章,详细介绍了参数化数据集。
-
如果您不需要保留TAB文件,您可以尝试将SQL用作源并将FTP用作接收,但FTP数据集可能不再是二进制的,这可能会影响性能。我认为这里概述的方法更好。如果需要,您可以在FTP上传后添加一个删除活动,以从存储中删除TAB文件。
-
如果您想要在传输过程中将文件压缩为ZIP文件,请在FTP数据集中选择ZipDeflate压缩类型。这将自动将文件压缩(但您需要自行将“.zip”扩展名添加到文件名中)。
英文:
Let's break this down into its component parts:
Execute a SQL query and save results as TAB file:
- Create a SQL Dataset with no table:
- In your pipeline, add a Copy activity. Under the Source tab, to this SQL dataset. For "Use Query", select the "Query" option and insert your SELECT statement:
- Create another Dataset for the TAB file. I'm using ADLS in this example, but the concept is the same for other storage types:
This example is built to be as generic as possible, so it uses Dataset parameters to configure the options at runtime:
NOTE:
Feel free to hard code any of these values if you prefer. It is easier to select the Tab delimiter in the Dataset: supplying it in this manner requires you to copy and paste a Tab (like from Notepad) which you cannot see in the UI.
The most important step is to NOT define a Schema:
- In the Copy activity, under the Sink tab, select this Dataset and supply the appropriate values:
Now when this activity runs, it will copy the results of the query to the text file in storage.
Upload TAB file to FTP site:
Use Copy activity for this as well. For pure data transfer, you should use Binary Datasets.
- Create a Binary Dataset for your storage account:
Again, this Dataset uses parameters to make it reusable across a wide array of situations.
- Create a Binary Dataset for your FTP account:
This example also uses parameters.
- Add a Copy activity in your pipeline using the storage Dataset as your Source and the FTP Dataset as your Sink. Fill in the appropriate parameter values in each and you should have a finished pipeline something like this:
NOTES:
-
As you can tell, parameterized Datasets are very powerful. Here is an article I wrote that goes into more detail.
-
If you don't need to retain the TAB file, you can try to use SQL as the source and FTP as the Sink, but the FTP Dataset could no longer be Binary which may hinder performance. I think the approach outlined here is better. If you want, you can add a Delete activity after the FTP upload to remove the TAB file from storage.
-
If you want to ZIP the file in flight to the FTP, select the ZipDeflate compression type in the FTP Dataset. This will automatically zip the file (but you will need to add the ".zip" extension to the filename yourself).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论