gianm commented on code in PR #12918: URL: https://github.com/apache/druid/pull/12918#discussion_r951609486
########## extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/report/MSQStagesReport.java: ########## @@ -0,0 +1,181 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.msq.indexing.report; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.google.common.base.Preconditions; +import org.apache.druid.msq.kernel.QueryDefinition; +import org.apache.druid.msq.kernel.StageDefinition; +import org.apache.druid.msq.kernel.controller.ControllerStagePhase; +import org.joda.time.DateTime; +import org.joda.time.Interval; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class MSQStagesReport +{ + private final List<Stage> stages; + + @JsonCreator + public MSQStagesReport(@JsonProperty("stages") final List<Stage> stages) + { + this.stages = Preconditions.checkNotNull(stages, "stages"); + } + + public static MSQStagesReport create( + final QueryDefinition queryDef, + final Map<Integer, ControllerStagePhase> stagePhaseMap, + final Map<Integer, Interval> stageRuntimeMap, + final Map<Integer, Integer> stageWorkerCountMap, + final Map<Integer, Integer> stagePartitionCountMap + ) + { + final List<Stage> stages = new ArrayList<>(); + + final int[] stageNumbers = + queryDef.getStageDefinitions().stream().mapToInt(StageDefinition::getStageNumber).toArray(); + Arrays.sort(stageNumbers); + + for (final int stageNumber : stageNumbers) { + final StageDefinition stageDef = queryDef.getStageDefinition(stageNumber); + + final int workerCount = stageWorkerCountMap.getOrDefault(stageNumber, 0); + final int partitionCount = stagePartitionCountMap.getOrDefault(stageNumber, 0); + final Interval stageRuntimeInterval = stageRuntimeMap.get(stageNumber); + final DateTime stageStartTime = stageRuntimeInterval == null ? null : stageRuntimeInterval.getStart(); + final long stageDuration = stageRuntimeInterval == null ? 0 : stageRuntimeInterval.toDurationMillis(); + + final Stage stage = new Stage( + stageNumber, + stageDef, + stagePhaseMap.get(stageNumber), + workerCount, + partitionCount, + stageStartTime, + stageDuration + ); + stages.add(stage); + } + + return new MSQStagesReport(stages); + } + + @JsonValue Review Comment: Ah. Good point. The way to do this: > Another option would be to change the deserialization instead in the MSQTaskReportPayload/MSQStagesReport Would be to remove the `@JsonProperty` annotation from the constructor field. This causes it to deserialize directly from a list. I'll make that change, and add deserialization tests. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
