This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 7914ec4ef2 NIFI-14511 Added documentation to ExcelReader describing 
number to string coercion behavior (#9915)
7914ec4ef2 is described below

commit 7914ec4ef26018ceee33e79a8bc79c9e4a532b39
Author: dan-s1 <[email protected]>
AuthorDate: Mon May 5 14:49:32 2025 -0400

    NIFI-14511 Added documentation to ExcelReader describing number to string 
coercion behavior (#9915)
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../additionalDetails.md                                |  4 ++--
 .../org/apache/nifi/excel/TestExcelRecordReader.java    | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git 
a/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/main/resources/docs/org.apache.nifi.excel.ExcelReader/additionalDetails.md
 
b/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/main/resources/docs/org.apache.nifi.excel.ExcelReader/additionalDetails.md
index 941d682861..c7c325046d 100644
--- 
a/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/main/resources/docs/org.apache.nifi.excel.ExcelReader/additionalDetails.md
+++ 
b/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/main/resources/docs/org.apache.nifi.excel.ExcelReader/additionalDetails.md
@@ -36,8 +36,8 @@ type, an Exception will be thrown.
 
 The following rules apply when attempting to coerce a field value from one 
data type to another:
 
-* Any data type can be coerced into a String type.
-* Any numeric data type (Byte, Short, Int, Long, Float, Double) can be coerced 
into any other numeric data type.
+* Excel stores all numeric types as a Double which can be coerced to any other 
numeric data type (Byte, Short, Int, Long, Float).
+* Any data type can be coerced into a String type. Please note since Excel 
stores all numbers as a Double, a large number coerced to a String will result 
in a string representation of the number in scientific notation. If this is not 
desired, then coerce the number to a Long numeric type.
 * Any numeric value can be coerced into a Date, Time, or Timestamp type, by 
assuming that the Long value is the number
   of milliseconds since epoch (Midnight GMT, January 1, 1970).
 * A String value can be coerced into a Date, Time, or Timestamp type, if its 
format matches the configured "Date
diff --git 
a/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/test/java/org/apache/nifi/excel/TestExcelRecordReader.java
 
b/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/test/java/org/apache/nifi/excel/TestExcelRecordReader.java
index 951a19a470..14f7015a15 100644
--- 
a/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/test/java/org/apache/nifi/excel/TestExcelRecordReader.java
+++ 
b/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/test/java/org/apache/nifi/excel/TestExcelRecordReader.java
@@ -349,6 +349,23 @@ public class TestExcelRecordReader {
         assertDoesNotThrow(() -> getRecords(recordReader, true, true));
     }
 
+    @Test
+    void testWhereLongSpecifiedInSchemaAsString() throws Exception {
+        final String fieldName = "Phone";
+        final RecordSchema schema = new SimpleRecordSchema(List.of(new 
RecordField(fieldName, RecordFieldType.STRING.getDataType())));
+        final ExcelRecordReaderConfiguration configuration = new 
ExcelRecordReaderConfiguration.Builder()
+                .withSchema(schema)
+                .build();
+        final Object[][] data = {{9876543210L}};
+        final InputStream workbook = createWorkbook(data);
+        final ExcelRecordReader recordReader = new 
ExcelRecordReader(configuration, workbook, logger);
+        final List<Record> records = getRecords(recordReader, true, true);
+        final Record firstRecord = records.getFirst();
+        final String scientificNotationNumber = "9.87654321E9";
+
+        assertEquals(scientificNotationNumber, 
firstRecord.getAsString(fieldName));
+    }
+
     private static InputStream createWorkbook(Object[][] data) throws 
Exception {
         final ByteArrayOutputStream workbookOutputStream = new 
ByteArrayOutputStream();
         try (XSSFWorkbook workbook = new XSSFWorkbook()) {

Reply via email to