smolnar82 commented on a change in pull request #296: KNOX-2240 - KnoxShell 
Custom Command for WEBHDFS Use
URL: https://github.com/apache/knox/pull/296#discussion_r396263931
 
 

 ##########
 File path: 
gateway-shell/src/main/java/org/apache/knox/gateway/shell/commands/CSVCommand.java
 ##########
 @@ -49,10 +49,24 @@ public Object execute(List<String> args) {
 
     try {
       if (withHeaders) {
-        table = KnoxShellTable.builder().csv().withHeaders().url(url);
+        if (url.startsWith("$")) {
+          // a knoxshell variable is a csv file as a string
+          String csvString = (String) getVariables().get(url.substring(1));
+          table = 
KnoxShellTable.builder().csv().withHeaders().string(csvString);
+        }
+        else {
+          table = KnoxShellTable.builder().csv().withHeaders().url(url);
+        }
       }
       else {
-        table = KnoxShellTable.builder().csv().url(url);
+        if (url.startsWith("$")) {
+          // a knoxshell variable is a csv file as a string
+          String csvString = (String) getVariables().get(url.substring(1));
+          table = KnoxShellTable.builder().csv().string(csvString);
+        }
+        else {
+          table = KnoxShellTable.builder().csv().url(url);
+        }
 
 Review comment:
   Thes line can be replaced like:
   ```
       CSVKnoxShellTableBuilder csvTableBuilder = withHeaders ?  
KnoxShellTable.builder().csv() :  KnoxShellTable.builder().csv().withHeaders();
       table = url.startsWith("$") ?  csvTableBuilder.env(url) ?  
csvTableBuilder.url(url);
   ```
   Please note that `env(String variableName)` should be added in 
`CSVKnoxShellTableBuilder`.
   
   IMO the implementation is cleaner this way.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to