tpalfy commented on a change in pull request #3611: NIFI-6009 ScanKudu Processor
URL: https://github.com/apache/nifi/pull/3611#discussion_r331472511
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-kudu-bundle/nifi-kudu-processors/src/main/java/org/apache/nifi/processors/kudu/AbstractKuduProcessor.java
 ##########
 @@ -260,4 +285,123 @@ 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) {
+        final StringBuilder jsonBuilder = new StringBuilder();
+        jsonBuilder.append("{");
+        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())) + "\"");
 
 Review comment:
   I thought the binary format through again and I think for consistency's sake 
(see below) and for simplicity we should omit the "0x" at the beginning after 
all.
   
   So it should be just `jsonBuilder.append("\"" + 
Hex.encodeHexString(row.getBinaryCopy(col.getName())) + "\"");`
   
   (Need to change `0x3759` to `3759` in 
`TestScanKudu.testScanKuduWithMultipleTypes` as well.)

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


With regards,
Apache Git Services

Reply via email to