Skip to content

Commit

Permalink
feat: Sort exported field names
Browse files Browse the repository at this point in the history
  • Loading branch information
jruaux committed Sep 5, 2024
1 parent ba064ac commit 037c4ab
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions plugins/riot/src/main/java/com/redis/riot/FileExport.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.redis.riot;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
Expand Down Expand Up @@ -196,9 +198,11 @@ private FlatFileItemWriter<Map<String, Object>> writer(FlatFileItemWriterBuilder
if (CollectionUtils.isEmpty(headerRecord)) {
log.warn("Could not determine header");
} else {
Map<String, Object> headerFieldMap = new HashMap<>();
headerRecord.forEach((k, v) -> headerFieldMap.put(k, k));
String headerLine = lineAggregator.aggregate(headerFieldMap);
List<String> fields = new ArrayList<>(headerRecord.keySet());
Collections.sort(fields);
Map<String, Object> fieldMap = new LinkedHashMap<>();
fields.forEach(f -> fieldMap.put(f, f));
String headerLine = lineAggregator.aggregate(fieldMap);
log.info("Found header: {}", headerLine);
writer.headerCallback(w -> w.write(headerLine));
}
Expand Down

0 comments on commit 037c4ab

Please sign in to comment.