File Rename Function in Siddhi (WSO2 Streaming Integrator)

Umesha Guruge
2 min readDec 18, 2023

--

https://en.wikipedia.org/wiki/Rename_%28computing%29#/media/File:Renaming_a_file_in_Ubuntu_18.04.png

If you have already used WSO2 Streaming Integrator(SI) , you already know that the SI logics are created using Siddhi Query Language.

If you are not familiar with any of what I just said, you can refer to WSO2 SI and Siddhi and see all the incredible Streaming use-cases you can develop using them.

If we move on a bit further, in Siddhi we have several extensions to get our applications developed with ease, we have;

In Input/output extensions, we have the siddhi-io-file extension, which is basically used to receive/publish event data from/to file.

Based on several use-cases we have encoutered, WSO2 introduced a new feature; a function to rename the files

And the syntax is as follows

file:rename(source, destination, file.system.options)

Here is a sample siddhi code for reference

from RecordStream#file:rename('/Users/Documents/target/duplicate.csv','/Users/Documents/target/newrenamedfile.csv')
select *
insert into completestream;

As per this when the RecordStream is populated, the duplicate.csv file in the target directory will be renamed to newrenamedfile.csv.

In here the file.system.options are optional, only the source and the target are the mandatory parameters.

The file.system.options can be given in key:value pairs separated by commas.

eg:'USER_DIR_IS_ROOT:false,PASSIVE_MODE:true,AVOID_PERMISSION_CHECK:true,IDENTITY:file://demo/.ssh/id_rsa,IDENTITY_PASS_PHRASE:wso2carbon'
Note: when IDENTITY is used, use a RSA PRIVATE KEY

And that’s it. That is the file rename function newly introduced to the siddhi IO file extension.

Hope this will help you when developing your file based streaming use-cases.

See you in the next blog…..

--

--