sfc-gh-ncover commented on code in PR #9891:
URL: https://github.com/apache/nifi/pull/9891#discussion_r2056344220


##########
nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/main/java/org/apache/nifi/processors/box/CreateBoxFileMetadataInstance.java:
##########
@@ -223,20 +229,58 @@ private void processRecord(Record record, Metadata 
metadata, List<String> errors
             return;
         }
 
-        List<String> fieldNames = record.getSchema().getFieldNames();
+        final List<RecordField> fields = record.getSchema().getFields();
 
-        if (fieldNames.isEmpty()) {
+        if (fields.isEmpty()) {
             errors.add("Record has no fields");
             return;
         }
 
-        for (String fieldName : fieldNames) {
-            Object valueObj = record.getValue(fieldName);
-            String value = valueObj != null ? valueObj.toString() : null;
-            metadata.add("/" + fieldName, value);
+        for (final RecordField field : fields) {
+            addValueToMetadata(metadata, record, field);
         }
     }
 
+    private void addValueToMetadata(final Metadata metadata, final Record 
record, final RecordField field) {
+        if (record.getValue(field) == null) {
+            return;
+        }
+
+        final RecordFieldType fieldType = field.getDataType().getFieldType();
+        final String fieldName = field.getFieldName();
+        final String path = "/" + fieldName;
+
+        if (isNumber(fieldType)) {
+            metadata.add(path, record.getAsDouble(fieldName));
+        } else if (isDate(fieldType)) {
+            final LocalDate date = record.getAsLocalDate(fieldName, null);
+            metadata.add(path, BoxDate.of(date).format());
+        } else if (isArray(fieldType)) {
+            final List<String> values = 
Arrays.stream(record.getAsArray(fieldName))
+                    .filter(Objects::nonNull)
+                    .map(Object::toString)
+                    .toList();
+
+            metadata.add(path, values);
+        } else {
+            metadata.add(path, record.getAsString(fieldName));
+        }
+    }
+
+    private boolean isNumber(final RecordFieldType fieldType) {
+        final boolean isInteger = RecordFieldType.BIGINT.equals(fieldType) || 
RecordFieldType.BIGINT.isWiderThan(fieldType);
+        final boolean isFloat = RecordFieldType.DECIMAL.equals(fieldType) || 
RecordFieldType.DECIMAL.isWiderThan(fieldType);
+        return isInteger || isFloat;
+    }
+
+    private boolean isDate(final RecordFieldType fieldType) {
+        return RecordFieldType.DATE.equals(fieldType);

Review Comment:
   ```suggestion
           return RecordFieldType.DATE.equals(fieldType) || 
RecordFieldType.TIMESTAMP.equals(fieldType);
   ```
   There is also a timestamp record type, would this be picked up by date or 
should it be also added in?



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to