-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Drain Mode as WindowedValue extension #34764
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
acf46fc
drain mode as extension
stankiewicz 2409fdf
add withMetadata
stankiewicz 5473d67
add tests
stankiewicz 932b53a
fix ValueInEmptyWindows
stankiewicz 7e3e75a
style
stankiewicz 3082807
Merge branch 'apache:master' into wv_extensions
stankiewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -146,10 +146,10 @@ private static byte encodedByte(boolean isFirst, boolean isLast, Timing timing) | |||||||||
| ImmutableMap.Builder<Byte, PaneInfo> decodingBuilder = ImmutableMap.builder(); | ||||||||||
| for (Timing timing : Timing.values()) { | ||||||||||
| long onTimeIndex = timing == Timing.EARLY ? -1 : 0; | ||||||||||
| register(decodingBuilder, new PaneInfo(true, true, timing, 0, onTimeIndex)); | ||||||||||
| register(decodingBuilder, new PaneInfo(true, false, timing, 0, onTimeIndex)); | ||||||||||
| register(decodingBuilder, new PaneInfo(false, true, timing, -1, onTimeIndex)); | ||||||||||
| register(decodingBuilder, new PaneInfo(false, false, timing, -1, onTimeIndex)); | ||||||||||
| register(decodingBuilder, new PaneInfo(true, true, timing, 0, onTimeIndex, false)); | ||||||||||
| register(decodingBuilder, new PaneInfo(true, false, timing, 0, onTimeIndex, false)); | ||||||||||
| register(decodingBuilder, new PaneInfo(false, true, timing, -1, onTimeIndex, false)); | ||||||||||
| register(decodingBuilder, new PaneInfo(false, false, timing, -1, onTimeIndex, false)); | ||||||||||
| } | ||||||||||
| BYTE_TO_PANE_INFO = decodingBuilder.build(); | ||||||||||
| } | ||||||||||
|
|
@@ -159,7 +159,7 @@ private static void register(ImmutableMap.Builder<Byte, PaneInfo> builder, PaneI | |||||||||
| } | ||||||||||
|
|
||||||||||
| private final byte encodedByte; | ||||||||||
|
|
||||||||||
| private final boolean containsElementMetadata; | ||||||||||
| private final boolean isFirst; | ||||||||||
| private final boolean isLast; | ||||||||||
| private final Timing timing; | ||||||||||
|
|
@@ -177,13 +177,20 @@ private static void register(ImmutableMap.Builder<Byte, PaneInfo> builder, PaneI | |||||||||
| public static final PaneInfo ON_TIME_AND_ONLY_FIRING = | ||||||||||
| PaneInfo.createPane(true, true, Timing.ON_TIME, 0, 0); | ||||||||||
|
|
||||||||||
| private PaneInfo(boolean isFirst, boolean isLast, Timing timing, long index, long onTimeIndex) { | ||||||||||
| private PaneInfo( | ||||||||||
| boolean isFirst, | ||||||||||
| boolean isLast, | ||||||||||
| Timing timing, | ||||||||||
| long index, | ||||||||||
| long onTimeIndex, | ||||||||||
| boolean containsElementMetadata) { | ||||||||||
| this.encodedByte = encodedByte(isFirst, isLast, timing); | ||||||||||
| this.isFirst = isFirst; | ||||||||||
| this.isLast = isLast; | ||||||||||
| this.timing = timing; | ||||||||||
| this.index = index; | ||||||||||
| this.nonSpeculativeIndex = onTimeIndex; | ||||||||||
| this.containsElementMetadata = containsElementMetadata; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public static PaneInfo createPane(boolean isFirst, boolean isLast, Timing timing) { | ||||||||||
|
|
@@ -194,10 +201,21 @@ public static PaneInfo createPane(boolean isFirst, boolean isLast, Timing timing | |||||||||
| /** Factory method to create a {@link PaneInfo} with the specified parameters. */ | ||||||||||
| public static PaneInfo createPane( | ||||||||||
| boolean isFirst, boolean isLast, Timing timing, long index, long onTimeIndex) { | ||||||||||
| return createPane(isFirst, isLast, timing, index, onTimeIndex, false); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** Factory method to create a {@link PaneInfo} with the specified parameters. */ | ||||||||||
| public static PaneInfo createPane( | ||||||||||
| boolean isFirst, | ||||||||||
| boolean isLast, | ||||||||||
| Timing timing, | ||||||||||
| long index, | ||||||||||
| long onTimeIndex, | ||||||||||
| boolean containsElementMetadata) { | ||||||||||
| if (isFirst || timing == Timing.UNKNOWN) { | ||||||||||
| return checkNotNull(BYTE_TO_PANE_INFO.get(encodedByte(isFirst, isLast, timing))); | ||||||||||
| } else { | ||||||||||
| return new PaneInfo(isFirst, isLast, timing, index, onTimeIndex); | ||||||||||
| return new PaneInfo(isFirst, isLast, timing, index, onTimeIndex, containsElementMetadata); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -241,6 +259,15 @@ public long getIndex() { | |||||||||
| return index; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public boolean isElementMetadata() { | ||||||||||
| return containsElementMetadata; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public PaneInfo withElementMetadata(boolean elementMetadata) { | ||||||||||
| return new PaneInfo( | ||||||||||
| this.isFirst, this.isLast, this.timing, index, nonSpeculativeIndex, elementMetadata); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * The zero-based index of this trigger firing among non-speculative panes. | ||||||||||
| * | ||||||||||
|
|
@@ -360,7 +387,8 @@ public PaneInfo decode(final InputStream inStream) throws CoderException, IOExce | |||||||||
| byte keyAndTag = (byte) inStream.read(); | ||||||||||
| PaneInfo base = Preconditions.checkNotNull(BYTE_TO_PANE_INFO.get((byte) (keyAndTag & 0x0F))); | ||||||||||
| long index, onTimeIndex; | ||||||||||
| switch (Encoding.fromTag(keyAndTag)) { | ||||||||||
| boolean elementMetadata = (keyAndTag & 0x80) > 0; | ||||||||||
| switch (Encoding.fromTag((byte) (keyAndTag & 0x7F))) { | ||||||||||
|
||||||||||
| boolean elementMetadata = (keyAndTag & 0x80) > 0; | |
| switch (Encoding.fromTag((byte) (keyAndTag & 0x7F))) { | |
| boolean elementMetadata = keyAndTag < (keyAndTag &= 0x7f); | |
| switch (Encoding.fromTag(keyAndTag) { |
34 changes: 34 additions & 0 deletions
34
sdks/java/core/src/main/java/org/apache/beam/sdk/util/ElementMetadata.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * 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 com.google.auto.value.AutoValue; | ||
| import org.apache.beam.model.pipeline.v1.RunnerApi.DrainMode; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| @AutoValue | ||
| public abstract class ElementMetadata { | ||
|
|
||
| DrainMode.@Nullable Enum drainMode; | ||
|
|
||
| public static ElementMetadata create(DrainMode.@Nullable Enum drainMode) { | ||
| return new AutoValue_ElementMetadata(drainMode); | ||
| } | ||
|
|
||
| abstract DrainMode.@Nullable Enum drainMode(); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.