Github user joshelser commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1349#discussion_r93823487
--- Diff:
nifi-nar-bundles/nifi-hbase-bundle/nifi-hbase-processors/src/main/java/org/apache/nifi/hbase/io/JsonQualifierAndValueRowSerializer.java
---
@@ -0,0 +1,82 @@
+/*
+ * 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.hbase.io;
+
+import org.apache.commons.lang3.StringEscapeUtils;
+import org.apache.nifi.hbase.scan.ResultCell;
+import org.apache.nifi.hbase.util.ResultCellUtil;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+
+public class JsonQualifierAndValueRowSerializer implements RowSerializer {
+
+ private final Charset charset;
+ private final boolean base64encodeValues;
+
+ public JsonQualifierAndValueRowSerializer(final Charset charset) {
+ this(charset, false);
+ }
+
+ public JsonQualifierAndValueRowSerializer(final Charset charset, final
boolean base64encodeValues) {
+ this.charset = charset;
+ this.base64encodeValues = base64encodeValues;
+ }
+
+ @Override
+ public void serialize(final byte[] rowKey, final ResultCell[] cells,
final OutputStream out) throws IOException {
+ final StringBuilder jsonBuilder = new StringBuilder();
+ jsonBuilder.append("{");
+
+ int i = 0;
+ for (final ResultCell cell : cells) {
+ final String cellQualifier = new
String(cell.getQualifierArray(), cell.getQualifierOffset(),
cell.getQualifierLength(), charset);
+ final String cellValue = ResultCellUtil.getCellValue(cell,
charset, base64encodeValues);
+
+ if (i > 0) {
+ jsonBuilder.append(", ");
+ }
+
jsonBuilder.append("\"").append(StringEscapeUtils.escapeJson(cellQualifier)).append("\":");
--- End diff --
Might want to apply the same base64 encoding logic to the qualifier as you
would to the value.
I would think that if you base64 encode the value, you'd do all of the
other components as well. However, maybe I'm just being overly cautious. It's
probably fine to only do the value as a first-stab :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---