Skip to content

Refactor: separate SplittableTruncateSizedRestrictions #35021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,25 @@ public static <RestrictionT, PositionT> RestrictionTracker<RestrictionT, Positio
return new RestrictionTrackerObserver<>(restrictionTracker, claimObserver);
}
}

public static <RestrictionT, PositionT> RestrictionTracker<RestrictionT, PositionT> synchronize(
RestrictionTracker<RestrictionT, PositionT> restrictionTracker) {
if (restrictionTracker instanceof RestrictionTracker.HasProgress) {
return new RestrictionTrackerObserverWithProgress<>(
restrictionTracker, (ClaimObserver<PositionT>) NOOP_CLAIM_OBSERVER);
} else {
return new RestrictionTrackerObserver<>(
restrictionTracker, (ClaimObserver<PositionT>) NOOP_CLAIM_OBSERVER);
}
}

static class NoopClaimObserver<PositionT> implements ClaimObserver<PositionT> {
@Override
public void onClaimed(PositionT position) {}

@Override
public void onClaimFailed(PositionT position) {}
}

private static final NoopClaimObserver<Object> NOOP_CLAIM_OBSERVER = new NoopClaimObserver<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,6 @@ public static <RestrictionT> TruncateResult of(RestrictionT restriction) {
return new AutoValue_RestrictionTracker_TruncateResult(restriction);
}

public abstract @Nullable RestrictionT getTruncatedRestriction();
public abstract RestrictionT getTruncatedRestriction();
}
}
45 changes: 45 additions & 0 deletions sdks/java/core/src/main/java/org/apache/beam/sdk/util/Holder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.util;

import org.apache.beam.sdk.annotations.Internal;

/**
* A trivial boxing of a value, used when nullability needs to be added to a generic type. (Optional
* does not work for this)
*
* <p>Example: For a generic type `T` the actual parameter may be nullable or not. So you cannot
* check values for null to determine presence/absence. Instead you can store a {@code @Nullable
* Holder<T>}.
*/
@Internal
public class Holder<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mark Internal?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, all of sdk/util is "internal". Not sure whether that or an annotation will stop a user from complaining if we break it though :-). I added the annotation.

private T value;

private Holder(T value) {
this.value = value;
}

public static <ValueT> Holder<ValueT> of(ValueT value) {
return new Holder<>(value);
}

public T get() {
return value;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
*/
public class KV<K, V> implements Serializable {
/** Returns a {@link KV} with the given key and value. */
@Pure
public static <K, V> KV<K, V> of(K key, V value) {
return new KV<>(key, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collection;
import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
import org.apache.beam.sdk.transforms.windowing.PaneInfo;
import org.checkerframework.dataflow.qual.Pure;
import org.joda.time.Instant;

/**
Expand All @@ -29,26 +30,32 @@
*/
public interface WindowedValue<T> {
/** The primary data for this value. */
@Pure
T getValue();

/** The timestamp of this value in event time. */
@Pure
Instant getTimestamp();

/** Returns the windows of this {@code WindowedValue}. */
@Pure
Collection<? extends BoundedWindow> getWindows();

/** The {@link PaneInfo} associated with this WindowedValue. */
@Pure
PaneInfo getPaneInfo();

/**
* A representation of each of the actual values represented by this compressed {@link
* WindowedValue}, one per window.
*/
@Pure
Iterable<WindowedValue<T>> explodeWindows();

/**
* A {@link WindowedValue} with identical metadata to the current one, but with the provided
* value.
*/
@Pure
<OtherT> WindowedValue<OtherT> withValue(OtherT value);
}
Loading
Loading