简体   繁体   English

Azure 数据工厂创建一个空的 csv 文件

[英]Azure Data Factory to create an empty csv file

I have a requirement where I want to check if file exist in a folder.我有一个要求,我想检查文件夹中是否存在文件。 If file exists then I want to skip else I want to create an empty csv file.如果文件存在,那么我想跳过,否则我想创建一个空的 csv 文件。 One way I have tried using Metadata activity and then using copy activity I am able to move empty file to the destination.我尝试使用元数据活动然后使用复制活动的一种方法可以将空文件移动到目标。 I want to check if there is any better way of creating empty csv file with on the fly without using copy activity?我想检查是否有更好的方法可以在不使用复制活动的情况下即时创建空 csv 文件?

Yes, there is another approach but it includes coding.是的,还有另一种方法,但它包括编码。

You can create a Azure Function in your preferred coding language and trigger it using Azure Data Factory Azure Function activity.可以使用首选编码语言创建 Azure 函数,并使用 Azure 数据工厂Azure Function活动触发它。

The Azure Function activity allows you to run Azure Functions in an Azure Data Factory or Synapse pipeline. Azure Function 活动允许你在 Azure 数据工厂或 Synapse 管道中运行 Azure Functions。 To run an Azure Function, you must create a linked service connection.若要运行 Azure 函数,必须创建链接服务连接。 Then you can use the linked service with an activity that specifies the Azure Function that you plan to execute.然后,您可以将链接服务与指定您计划执行的 Azure 函数的活动一起使用。

Learn more here . 在这里了解更多。

In Azure Function, you can access the directory where you want to check the files availability and can also create/delete/update the csv files with schema based.在 Azure Function 中,您可以访问要检查文件可用性的目录,还可以基于架构创建/删除/更新 csv 文件。

You can use a Copy Activity.您可以使用复制活动。 Source: Write a SQL Query in-line that includes all the columns as NULL and a WHERE clause that will produce no data.来源:编写一个内联 SQL 查询,包括所有列为 NULL 和一个不会产生数据的 WHERE 子句。 Note that no tables are involved, and you can issue the query against any SQL source, including Serverless.请注意,不涉及任何表,您可以针对任何 SQL 源(包括无服务器)发出查询。 Target: the csv file, include headers.目标:csv 文件,包含标题。 Use an IF activity to create the file, if the metadata activity shows the file is absent.如果元数据活动显示文件不存在,则使用 IF 活动创建文件。

Example query--示例查询——

SELECT 
    CAST( NULL AS DATE) AS CreatedDate
    , CAST( NULL AS INT) AS EmployeeId
    , CAST( NULL AS VARCHAR(20)) AS FirstName
    , CAST( NULL AS VARCHAR(50)) AS LastName
    , CAST( NULL AS CHAR(20)) AS PostalCode
WHERE
    1=2; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM