Argument splitting is cluttered with trimming the whitespaces around the whole argument list and also for each individual argument.
This causes wrong behavior when DataFlow Manager needs to put empty string as an argument for command using ExecuteStreamCommand and ExecuteProcess.
Lets start by what DataFlow Manager needs to achieve (steps to reproduce):
1. Create a file "test.tsv" with TAB separated content:
2. Put GetFile Prrocessor to obtain this file into DataFlow
3. Connect GetFile to ExecuteStreamCommand.
4. ExecuteStreamCommand configuration:
- Command Path: cut
- Command Arguments:
- auto terminate: original
5. Put LogAttribute (Log Payload: true, autoterminate: success) and connect ExecuteStreamCommand to LogAttribute to see the output.
6. Run this Flow.
As the --output-delimiter argument to cut command is empty string (notice the last semicolon in argument list), cut command effectively joins columns.
This output can be obtained by issuing this command from within bash:
Those are apostrophes (to tell bash it is an empty argument).
ExecuteStreamCommand informs Bulletin of cut command error:
This is due org.apache.nifi.processors.standard.util.ArgumentUtils:
1. Line 41: unwanted string trimming - imagine we have used ' ' (spacebar) as argument separator in previous example, then property would look like this: Command Arguments:
(there is a space at the end of the string - the last separator as it was with semicolon). Then, trimming on this line, would ruin our last argument even before we come to splitting the argument string to list.
2. Line 52: if our output delimiter would look like " = " (space equals space), for example to create some kind of .ini file, this trimming would kill our attempts by providing the cut command only the "=" as argument.
3. Line 53: if our attempt is to provide cut command with empty string as argument (to join columns), we are neglected by this line.
There is a also JUnit test org.apache.nifi.processors.standard.TestExecuteProcess:testSplitArgs which just tests this wrong behavior.
4. Lines 69, 71- trimming once again.
And as I am trying to fix this bug, I do see that there is also obscure QUOTE system, which, is not for quoting the delimiter character (which would otherwise be treated as a delimiter), but QUOTES are remove also when they do not enclose the delimiter. This quoting should be rethinked and documented. Lets fix at least this first bug reported here.