lukecwik commented on a change in pull request #11596: URL: https://github.com/apache/beam/pull/11596#discussion_r421756445
########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/splittabledofn/OrderedTimeRange.java ########## @@ -0,0 +1,155 @@ +/* + * 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.beam.sdk.transforms.splittabledofn; + +import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import org.apache.beam.sdk.coders.AtomicCoder; +import org.apache.beam.sdk.coders.CoderException; +import org.apache.beam.sdk.coders.InstantCoder; +import org.apache.beam.sdk.util.VarInt; +import org.apache.beam.sdk.values.TypeDescriptor; +import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Objects; +import org.joda.time.Duration; +import org.joda.time.Instant; + +/** A restriction represented by a range of Instants [from, to). */ +public class OrderedTimeRange Review comment: why not use the offset range tracker and convert time to `long`? ########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/splittabledofn/OffsetRangeTracker.java ########## @@ -94,6 +94,9 @@ public void checkDone() throws IllegalStateException { if (range.getFrom() == range.getTo()) { return; } + if (lastAttemptedOffset == null) { + throw new IllegalStateException("lastAttemptedOffset should not be null"); + } checkState( lastAttemptedOffset >= range.getTo() - 1, "Last attempted offset was %s in range %s, claiming work in [%s, %s) was not attempted", Review comment: Please make this a seperate PR and add a test that covers this case to the OffsetRangeTrackerTest ```suggestion checkState( lastAttemptedOffset != null && lastAttemptedOffset >= range.getTo() - 1, "Last attempted offset was %s in range %s, claiming work in [%s, %s) was not attempted", ``` ########## File path: sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HL7v2IO.java ########## @@ -472,24 +548,120 @@ public void initClient() throws IOException { this.client = new HttpHealthcareApiClient(); } + @GetInitialRestriction + public OrderedTimeRange getEarliestToLatestRestriction(@Element String hl7v2Store) + throws IOException { + from = this.client.getEarliestHL7v2SendTime(hl7v2Store, this.filter); + // filters are [from, to) to match logic of OffsetRangeTracker but need latest element to be + // included in results set to add an extra ms to the upper bound. + to = this.client.getLatestHL7v2SendTime(hl7v2Store, this.filter).plus(1); + return new OrderedTimeRange(from, to); + } + + @NewTracker + public OrderedTimeRangeTracker newTracker(@Restriction OrderedTimeRange timeRange) { + return timeRange.newTracker(); + } + + @SplitRestriction + public void split( + @Restriction OrderedTimeRange timeRange, OutputReceiver<OrderedTimeRange> out) { + // TODO(jaketf) How to pick optimal values for desiredNumOffsetsPerSplit ? Review comment: Typically, doing one split for every 64mbs of output has been our guidance here in the past. Dynamic splitting is meant to fill in the gap if there is too little splitting or a specific restriction has a lot more data then other restrictions. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org