[
https://issues.apache.org/jira/browse/NIFI-3873?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16013371#comment-16013371
]
ASF GitHub Bot commented on NIFI-3873:
--------------------------------------
Github user ijokarumawak commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1788#discussion_r116895091
--- Diff:
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/java/org/apache/nifi/web/StandardContentViewerController.java
---
@@ -103,11 +108,27 @@ protected void doGet(HttpServletRequest request,
HttpServletResponse response) t
} else if ("application/avro-binary".equals(contentType)
|| "avro/binary".equals(contentType) ||
"application/avro+binary".equals(contentType)) {
final StringBuilder sb = new StringBuilder();
sb.append("[");
- final DatumReader<GenericData.Record> datumReader =
new GenericDatumReader<>();
+ // Use Avro conversions to display logical type values
in human readable way.
+ final GenericData genericData = new GenericData(){
+ @Override
+ protected void toString(Object datum,
StringBuilder buffer) {
+ // Since these types are not quoted and
produce a malformed JSON string, quote it here.
+ if (datum instanceof LocalDate || datum
instanceof LocalTime || datum instanceof DateTime) {
+
buffer.append("\"").append(datum).append("\"");
+ return;
+ }
+ super.toString(datum, buffer);
+ }
+ };
+ genericData.addLogicalTypeConversion(new
Conversions.DecimalConversion());
+ genericData.addLogicalTypeConversion(new
TimeConversions.DateConversion());
+ genericData.addLogicalTypeConversion(new
TimeConversions.TimeConversion());
+ genericData.addLogicalTypeConversion(new
TimeConversions.TimestampConversion());
+ final DatumReader<GenericData.Record> datumReader =
new GenericDatumReader<>(null, null, genericData);
try (final DataFileStream<GenericData.Record>
dataFileReader = new DataFileStream<>(content.getContentStream(), datumReader))
{
while (dataFileReader.hasNext()) {
final GenericData.Record record =
dataFileReader.next();
- final String formattedRecord =
record.toString();
+ final String formattedRecord =
genericData.toString(record);
--- End diff --
Thanks for your suggestion. I took a look at #1179 and customized
[StandardJsonEncoder](https://github.com/mattyb149/nifi/blob/879efb7572888cf4bd863e1938a3a798bd87ff0c/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/main/java/org/apache/avro/io/StandardJsonEncoder.java).
However, it's not clear to me what benefit it provides. GenericData.toString
doesn't add extra layer for union objects as described in NIFI-969. Even with a
union value, GenericData.toString seems to be working as expected (at least for
me).
Since I don't know what should be fixed by applying the
StandardJsonEncoder, I prefer keep using `.toString` unless there is a clear
reason.
> Content viewer to display Avro logical types more human readable way
> --------------------------------------------------------------------
>
> Key: NIFI-3873
> URL: https://issues.apache.org/jira/browse/NIFI-3873
> Project: Apache NiFi
> Issue Type: Improvement
> Components: Extensions
> Affects Versions: 1.2.0
> Reporter: Koji Kawamura
> Assignee: Koji Kawamura
>
> Avro logical types such as decimal and date are stored with its underlying
> type, for example, a logical 'decimal' is stored with bytes, while a logical
> 'date' with int.
> Currently, those logical values are displayed with its underlying type and
> value. It can be more user friendly if we can display it as logically
> converted human readable values.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)