You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@knox.apache.org by GitBox <gi...@apache.org> on 2020/03/23 08:20:20 UTC

[GitHub] [knox] smolnar82 commented on a change in pull request #296: KNOX-2240 - KnoxShell Custom Command for WEBHDFS Use

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:
users@infra.apache.org


With regards,
Apache Git Services