File Operation
In this article
Overview
You can use this Snap to perform a file operation (move/copy/rename) for a file from a source to a target in the same server. The supported file protocols are: local file (file:///), FTP, SFTP, S3, WASB, and WASBS. The File Operation Snap performs extract and load operations on the input file or folder.
Snap Type
File Operation Snap is a WRITE-type Snap that writes files to the target.
Prerequisites
The provided account must have 'write' access to the specified directory and file in order to perform the file operation successfully.
IAM Roles for Amazon EC2
Support for Ultra Pipelines
Works in Ultra Task Pipelines.
Limitations
The Snap can move, rename, or copy a file within the same file server, but not across file servers.
The Snap can move or copy S3 files across buckets within the same region, but not across regions.
Known Issues
This Snap does not support using the ABFS protocol with a Windows-based Snaplex.
When you use special characters, such asðø©¢¾A²½µ®÷¶þ~ for Source and Target directory and filenames, this Snap fails and results in the following error as the special characters are not supported.
Error: Illegal character in fragment at index 71:
abfs://bigdataqa@bigdataqassl.dfs.core.windows.net/simplechar/owner!@#$^&()_¢äâêîôûñç¡¿ÉÙËǨ°¸ðø©¢¾A²½µ®§÷¶þ~.json
The format:
abfs(s)://filesystem@accountname.endpoint/<path>
for file path for Source and Target fields does not work as this URL syntax is not supported. The file protocol must begin withabfs(s):///,
else the container, account name, and endpoint are interpolated into the URL at runtime, which results in the following error.Error: Unsupported protocol or URL syntax error in abfs(s)://filesystem@accountname.endpoint/<path>
,
Workaround: Use the supported file protocol and correct URL syntax.
Snap Views
Type | Format | Number of Views | Examples of Upstream and Downstream Snaps | Description |
---|---|---|---|---|
Input | Document | Min: 0 Max: 1 |
| Any document with key-value pairs to evaluate expression properties in the File Operator Snap can be used, where each input document will cause one complete execution of the Snap. |
Output | Document | Min: 0 Max: 1 |
| A typical output from this Snap is a document with column headers, such as Source, Target, and Status (Moved or Copied). |
Error | Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter while running the Pipeline by choosing one of the following options from the When errors occur list under the Views tab. The available options are:
Learn more about Error handling in Pipelines. |
Snap Settings
Asterisk (*): Indicates a mandatory field.
Suggestion icon (): Indicates a list that is dynamically populated based on the configuration.
Expression icon ( ): Indicates whether the value is an expression (if enabled) or a static value (if disabled). Learn more about Using Expressions in SnapLogic.
Add icon ( ): Indicates that you can add fields in the fieldset.
Remove icon (): Indicates that you can remove fields from the fieldset.
Field Name | Field Type | Description | |
---|---|---|---|
Label*
Default Value: File Operation | String | Specify the name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your Pipeline. | |
Source* Default Value: [None]
| String/Expression | Specify the URL for the source, where the binary data is read from. This Snap also supports S3 Virtual Private Cloud (VPC) endpoint. For example, s3://my-bucket@bucket.vpce-028b7814794578709-vu0vvauy.s3.us-west-2.vpce.amazonaws.com Example of Source as an expression: This property should have the syntax: You can also copy or move the file from your local system to Azure blob container for better performance. When using expressions to build a file name, ensure that the resulting file name does not contain characters that are not supported by the target platform. Amazon AWS S3 SDK Limitation - File operations
| |
Target* Default Value: [None]
| String/Expression | This property specifies the URL of the destination where the selected file operation must be performed. This Snap also supports S3 Virtual Private Cloud (VPC) endpoint. For example, s3://my-bucket@bucket.vpce-028b7814794578709-vu0vvauy.s3.us-west-2.vpce.amazonaws.com | |
File Operation Default Value: Move
| String/Expression | Enter or select the operation you want the Snap to perform on the file. Available options are:
| |
Error if exists Default Value: Selected | Checkbox | If enabled, the Snap displays an error when the target exists. If disabled, the Snap replaces or overwrites the target with the source. | |
Advanced Properties | Use this field set to customize or control the Snap's validation and execution mechanism. | ||
Properties Default Value: SAS URI | Dropdown list | The available options are:
You can also copy or move the file from your local system to Azure blob container for better performance. | |
Values Default Value: None | String/Expression | Specify a value for the above property. | |
Snap Execution | Dropdown list |
Snap Behavior for Key Operations
Source | Target | Error if exists | |||
---|---|---|---|---|---|
-- | -- | x | State does not affect outcome | x | State does not affect outcome |
00 | Does not exist | 00 | Does not exist | 0 | Not selected |
01 | Regular file | 01 | Regular file | 1 | Selected |
10 | Directory | 10 | Empty directory | -- | -- |
-- | -- | 11 | Non-empty directory | -- | -- |
FTP, SFTP, and File Protocols
S3, WASB, and WASBS Protocols
Examples
Moving File from Local System to Azure Blob Container
This example Pipeline demonstrates how to move files from your local system to the Azure blob for improved performance.
Configure the File Reader Snap that reads airlines.csv file from the local machine.
Next, we configure the File Writer Snap to write the airlines.csv file.
Next, we configure the File Operation Snap to move the file from Source (local directory) to Target (Azure Blob container).
SAS URI: https://blobbatchingdev.blob.core.windows.net/?sv=2020-08-04&ss=bfqt&srt=sco&sp=rwdlacupitfx&se=2022-05-20T02:51:39Z&st=2022-05-19T18:51:39Z&spr=https&sig=ey9YraJOEsokwBz4GsvT4p%2FCb4eoAuMIVwrf3zymeeI%3D
AzCopy absolute path: /Users/vkshirsagar/Downloads/azcopy_darwin_amd64_10.12.2/azcopy
Copying and Moving of File from One Folder to Another Folder
This example Pipeline demonstrates copying and moving of files with ABFS protocol from one folder to another folder.
First, we configure the JSON Generator Snap to pass the following sample data. After validation we see the following output.
Next, we format the data using the JSON Formatter Snap and then, use the HDFS Writer Snap to write the sample file (that uses ABFS protocol and ADLS Gen 2) to the target location.
Next, we configure two File Operation Snaps to copy and move files from one folder to another folder. We use the first File Operation Snap to copy the sample file from abfss:///bigdataqa/Samplefile/ to abfss:///bigdataqa/samplefile_diff/).
We add the second File Operation Snap to move the same sample file (uni_code.json) to another file (uni_code_move.json).
The target location of the copied and moved file can be viewed in the output preview of the Snap.
Finally, we connect the HDFS Reader Snap to read the target file.
Basic Use Case
The following Pipeline describes how the Snap functions as a standalone Snap in a Pipeline:
Download the Pipeline here or from the Downloads section below.
In the Pipeline shown above, a copy of the file Emp_Data_03032020.json is created in the specified target location. The Snap's configuration is as below:
A preview of the output from executing this Pipeline:
The exported Pipeline is available in the Downloads section below. More examples of operations are also available in the Downloads section - variousCasesOfFileOperations.pdf.
Typical Snap Configurations
Key configuration of the Snap lies in how the values are passed. The values can be passed:
Without Expressions: Values are passed in the Snap directly:
With Expressions:
Using Pipeline parameters: Values are passed as Pipeline parameters:
Downloads
Have feedback? Email documentation@snaplogic.com | Ask a question in the SnapLogic Community
© 2017-2024 SnapLogic, Inc.