granthenke commented on a change in pull request #3387: NIFI-6009 ScanKudu 
Processor & KuduPut Processor Delete Operation
URL: https://github.com/apache/nifi/pull/3387#discussion_r273576141
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-kudu-bundle/nifi-kudu-processors/src/main/java/org/apache/nifi/kudu/io/JsonFullRowSerializer.java
 ##########
 @@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.kudu.io;
+
+import org.apache.kudu.ColumnSchema;
+import org.apache.kudu.client.RowResult;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Iterator;
+
+/**
+ * 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",
+ *      }
+ *    ]
+ * }
+ */
+public class JsonFullRowSerializer implements RowSerializer {
+
+    @Override
+    public String serialize(Iterator<RowResult> rows) {
+        final StringBuilder jsonBuilder = new StringBuilder();
+        jsonBuilder.append("{");
+
+        jsonBuilder.append("\"rows\":[");
+        while (rows.hasNext()) {
+            RowResult result = rows.next();
+            jsonBuilder.append("{");
+
+            Iterator<ColumnSchema> columns = 
result.getSchema().getColumns().iterator();
+            while (columns.hasNext()) {
+                ColumnSchema col = columns.next();
+                jsonBuilder.append("\"" + col.getName() + "\":");
+                switch (col.getType()) {
 
 Review comment:
   Note in the next release of Kudu, if you don't care about the type returned 
you can use `result.getObject`.
   
https://github.com/apache/kudu/commit/562b5f12f721b533cc2cb868c15a2f85d9e0114b#diff-d622d57293d3d23f774030d3c5916b09

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