Skip to content

Commit 91f0171

Browse files
committed
NIFI-14615 - Only quote string values
1 parent 10cdfe5 commit 91f0171

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

nifi-extension-bundles/nifi-parquet-bundle/nifi-parquet-content-viewer/src/main/java/org/apache/parquet/web/controller/ParquetContentViewerController.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
113113
for (Schema.Field field : fields) {
114114
outputStream.write((indent + indent).getBytes());
115115
outputStream.write(("\"" + field.name() + "\": ").getBytes());
116-
outputStream.write(("\"" + record.get(field.name()) + "\" \n").getBytes());
116+
outputStream.write(formatValue(field, record.get(field.name())).getBytes());
117+
outputStream.write("\n".getBytes());
117118
}
118119
outputStream.write((indent + "}").getBytes());
119120
}
@@ -125,6 +126,23 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
125126
}
126127
}
127128

129+
private String formatValue(Schema.Field field, Object value) {
130+
if (value == null) {
131+
return "";
132+
}
133+
134+
Schema schema = field.schema();
135+
Schema.Type type = schema.getType();
136+
137+
if (type == Schema.Type.STRING
138+
|| (type == Schema.Type.UNION
139+
&& schema.getTypes().stream().anyMatch(s -> s.getType() == Schema.Type.STRING))) {
140+
return "\"" + value + "\"";
141+
}
142+
143+
return value.toString();
144+
}
145+
128146
private byte[] getInputStreamBytes(final InputStream inputStream) throws IOException {
129147
ByteArrayOutputStream baos = new ByteArrayOutputStream();
130148
byte[] buffer = new byte[BUFFER_SIZE];

0 commit comments

Comments
 (0)