Uploaded image for project: 'Apache NiFi'
  1. Apache NiFi
  2. NIFI-4822

ValidateRecord does not maintain order of CSV records

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Duplicate
    • 1.4.0, 1.5.0
    • None
    • None
    • None

    Description

      If you have ValidateRecord configured with a CSV reader and CSV writer and send in some valid data, the flow file is routed to "valid", but the columns are written out in a different order than there were read.

      This means if the next processor is another record-oriented processor using the exact same schema and reader, it will fail to read it because the first column won't be what it expects.

      From doing some digging, it appears that in WriteCsvResult there is a method getFieldNames() that does this:

      final Set<String> allFields = new LinkedHashSet<>();
      allFields.addAll(record.getRawFieldNames());
      allFields.addAll(recordSchema.getFieldNames());

      In this case, record.getRawFieldNames() is coming from the keyset of a HashMap which means it is not maintaining the order the fields were read in.

      CsvRecordReader line 97:

      final Map<String, Object> values = new HashMap<>(recordFields.size() * 2);

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              bbende Bryan Bende
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: