Retain order in TaskReport. (#12005)

This commit is contained in:
Gian Merlino 2022-03-04 08:06:20 -08:00 committed by GitHub
parent 61e1ffc7f7
commit ada3ae08df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -22,7 +22,7 @@ package org.apache.druid.indexing.common;
import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo;
import java.util.HashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
/** /**
@ -44,9 +44,13 @@ public interface TaskReport
*/ */
Object getPayload(); Object getPayload();
/**
* Returns an order-preserving map that is suitable for passing into {@link TaskReportFileWriter#write}.
*/
static Map<String, TaskReport> buildTaskReports(TaskReport... taskReports) static Map<String, TaskReport> buildTaskReports(TaskReport... taskReports)
{ {
Map<String, TaskReport> taskReportMap = new HashMap<>(); // Use LinkedHashMap to preserve order of the reports.
Map<String, TaskReport> taskReportMap = new LinkedHashMap<>();
for (TaskReport taskReport : taskReports) { for (TaskReport taskReport : taskReports) {
taskReportMap.put(taskReport.getReportKey(), taskReport); taskReportMap.put(taskReport.getReportKey(), taskReport);
} }