phet commented on code in PR #4082: URL: https://github.com/apache/gobblin/pull/4082#discussion_r1878679601
########## gobblin-utility/src/main/java/org/apache/gobblin/util/WorkUnitSizeInfo.java: ########## @@ -0,0 +1,127 @@ +/* + * 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.gobblin.util; + +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicLong; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.tdunning.math.stats.TDigest; + +import org.apache.gobblin.service.ServiceConfigKeys; +import org.apache.gobblin.source.workunit.MultiWorkUnit; +import org.apache.gobblin.source.workunit.WorkUnit; + + +/** Bare-bones size information about a {@link WorkUnit}, possibly a {@link MultiWorkUnit} */ +@Data +@NoArgsConstructor // IMPORTANT: for jackson (de)serialization +@RequiredArgsConstructor +public class WorkUnitSizeInfo { + // NOTE: `@NonNull` to include field in `@RequiredArgsConstructor`, despite - "warning: @NonNull is meaningless on a primitive... @RequiredArgsConstructor" + @NonNull private int numConstituents; + @NonNull private long totalSize; + @NonNull private double medianSize; + @NonNull private double meanSize; + @NonNull private double stddevSize; + + /** @return the 'zero' {@link WorkUnitSizeInfo} */ + public static WorkUnitSizeInfo empty() { + return new WorkUnitSizeInfo(0, 0, 0.0, 0.0, 0.0); + } + + /** + * convenience factory to measure a {@link WorkUnit} - preferable to direct ctor call + * @returns {@link #empty()} when the `WorkUnit` is not measurable by defining {@link ServiceConfigKeys#WORK_UNIT_SIZE} + */ + public static WorkUnitSizeInfo forWorkUnit(WorkUnit workUnit) { + if (!workUnit.isMultiWorkUnit()) { + long wuSize = workUnit.getPropAsLong(ServiceConfigKeys.WORK_UNIT_SIZE, 0); + return new WorkUnitSizeInfo(1, wuSize, wuSize, wuSize, 0.0); Review Comment: yes, you are correct: for now it's pretty geared toward `CopySource` - most others will in fact be 0. the "contract" here is fortunately clear and reasonable for any `Source`: just add a number under the size key and then play along! `WorkUnitsSizeSummary` rides within the `GenerateWorkUnitsResult`, to which I've added a `String sourceClass` member. that is to qualify the size numbers by source. (some sources might count bytes, others num records, possibly with those size-weighted.) and of course not all sources extract a definite amount of data, known up front. in such cases, the source-qualified count of `WorkUnits` (aka. parallelism potential) may be most informative. meanwhile the `WorkUnitSizeInfo` entities only appear later in the job, post-`GenerateWorkUnitsResult`, so their numbers should be considered contextualized within the same job and its earlier `WorkUnitsSizeSummary`. -- 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: dev-unsubscr...@gobblin.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org