nifi-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [nifi] tpalfy commented on a change in pull request #3611: NIFI-6009 ScanKudu Processor
Date Wed, 02 Oct 2019 14:56:07 GMT
tpalfy commented on a change in pull request #3611: NIFI-6009 ScanKudu Processor
URL: https://github.com/apache/nifi/pull/3611#discussion_r330597920
 
 

 ##########
 File path: nifi-nar-bundles/nifi-kudu-bundle/nifi-kudu-processors/src/main/java/org/apache/nifi/processors/kudu/AbstractKuduProcessor.java
 ##########
 @@ -260,4 +284,72 @@ protected Update updateRecordToKudu(KuduTable kuduTable, Record record,
List<Str
         return update;
     }
 
-}
\ No newline at end of file
+
+    /**
+     * Serializes a row from Kudu to a JSON document of the form:
+     *
+     * {
+     *    "rows": [
+     *      {
+     *          "columnname-1" : "value1",
+     *          "columnname-2" : "value2",
+     *          "columnname-3" : "value3",
+     *          "columnname-4" : "value4",
+     *      },
+     *      {
+     *          "columnname-1" : "value1",
+     *          "columnname-2" : "value2",
+     *          "columnname-3" : "value3",
+     *          "columnname-4" : "value4",
+     *      }
+     *    ]
+     * }
+     */
+    protected String convertToJson(RowResult row) {
 
 Review comment:
   This method has some issues that needs to be fixed:
   1. `INT8` should be retrieved via `getByte`
   2. `INT16` should be retrieved via `getShort`
   3. `DOUBLE` is not handled
   4. `BINARY` now returns a toString of a `ByteBuffer`
   
   Here are my suggested fixes, although how BINARY should be handled may be up for debate:
   ```java
       protected String convertToJson(RowResult row) {
           final StringBuilder jsonBuilder = new StringBuilder();
           jsonBuilder.append("{\"rows\":[{");
           Iterator<ColumnSchema> columns = row.getSchema().getColumns().iterator();
           while (columns.hasNext()) {
               ColumnSchema col = columns.next();
               jsonBuilder.append("\"" + col.getName() + "\":");
               switch (col.getType()) {
                   case STRING:
                       jsonBuilder.append("\"" + row.getString(col.getName()) + "\"");
                       break;
                   case INT8:
                       jsonBuilder.append("\"" + row.getByte(col.getName()) + "\"");
                       break;
                   case INT16:
                       jsonBuilder.append("\"" + row.getShort(col.getName()) + "\"");
                       break;
                   case INT32:
                       jsonBuilder.append("\"" + row.getInt(col.getName()) + "\"");
                       break;
                   case INT64:
                       jsonBuilder.append("\"" + row.getLong(col.getName()) + "\"");
                       break;
                   case BOOL:
                       jsonBuilder.append("\"" + row.getBoolean(col.getName()) + "\"");
                       break;
                   case DECIMAL:
                       jsonBuilder.append("\"" + row.getDecimal(col.getName()) + "\"");
                       break;
                   case FLOAT:
                       jsonBuilder.append("\"" + row.getFloat(col.getName()) + "\"");
                       break;
                   case DOUBLE:
                       jsonBuilder.append("\"" + row.getDouble(col.getName()) + "\"");
                       break;
                   case UNIXTIME_MICROS:
                       jsonBuilder.append("\"" + row.getLong(col.getName()) + "\"");
                       break;
                   case BINARY:
                       jsonBuilder.append("\"0x" + Hex.encodeHexString(row.getBinaryCopy(col.getName()))
+ "\"");
                       break;
                   default:
                       break;
               }
               if(columns.hasNext())
                   jsonBuilder.append(",");
           }
           jsonBuilder.append("}]}");
           return jsonBuilder.toString();
       }
   ```

----------------------------------------------------------------
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

Mime
View raw message