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


##########
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));

Review Comment:
   Since isNumber is checking up to BigInteger and BigDecimal (arbitrary 
precision) it's possible that a number larger than double precision will be 
retrieved.  Given box only accepts up to double precision this seems 
appropriate.  Just wanted to make sure we're calling out the preference that we 
are opting for being more accepting of numbers being rounded or set to positive 
or negative infinity over throwing an error.  Agree with the approach but 
wanted to call out the design decision.



##########
nifi-extension-bundles/nifi-box-bundle/nifi-box-processors/src/test/java/org/apache/nifi/processors/box/CreateBoxFileMetadataInstanceTest.java:
##########
@@ -82,7 +84,12 @@ void testSuccessfulMetadataCreation() {
                   "documentType": "Q1 plans",
                   "competitiveDocument": "no",
                   "status": "active",
-                  "author": "Jones"
+                  "author": "Jones",
+                  "int": 1,
+                  "double": 1.234,

Review Comment:
   Might be good to add a large number to demonstrate we are preferring 
rounding over erroring when numbers requiring more than 64 bits.



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