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
[NEMO-216,251,259] Support side inputs and windowing #159
Merged
Merged
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
eb7f0c2
start
363763d
chkpt
49be56d
chkpt
c8bbb77
correct dag
5386549
working on readychecking
356d8f9
test passes
johnyangk b593199
remove logs
johnyangk ed33fcf
Merge branch 'master' into 259-sideinput
johnyangk a7db129
Merge branch 'master' into 259-sideinput
johnyangk a58f344
save
johnyangk c748a09
address comments, fixing itcase
johnyangk c0a5fd4
all pass except for PerPercentileAverageITCase
johnyangk 9758be9
Merge branch 'master' into 259-sideinput
johnyangk 5f97891
all tests pass
dd312cb
Merge branch 'master' into 259-sideinput
johnyangk 7d982c8
address comments
604e7ff
checkstyle
5b81568
pushback dofntransform
0f5c630
handle empty views
45c8206
fix test
3454df4
address comments
0c8f311
remaining comments
6f53edc
fix compile
e293eef
windowed wc names
800845a
display data
johnyangk 5622b88
windowfn displaydata
johnyangk f1548d5
address comments
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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
108 changes: 108 additions & 0 deletions
108
...nd/beam/src/main/java/org/apache/nemo/compiler/frontend/beam/InMemorySideInputReader.java
This file contains 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,108 @@ | ||
/* | ||
* 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.nemo.compiler.frontend.beam; | ||
|
||
import org.apache.beam.runners.core.ReadyCheckingSideInputReader; | ||
import org.apache.beam.sdk.transforms.ViewFn; | ||
import org.apache.beam.sdk.transforms.windowing.BoundedWindow; | ||
import org.apache.beam.sdk.util.WindowedValue; | ||
import org.apache.beam.sdk.values.PCollectionView; | ||
import org.apache.nemo.common.Pair; | ||
import org.apache.nemo.compiler.frontend.beam.transform.CreateViewTransform; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.*; | ||
|
||
/** | ||
* Accumulates and provides side inputs in memory. | ||
*/ | ||
public final class InMemorySideInputReader implements ReadyCheckingSideInputReader { | ||
private static final Logger LOG = LoggerFactory.getLogger(InMemorySideInputReader.class.getName()); | ||
|
||
private long curWatermark = Long.MIN_VALUE; | ||
|
||
private final Collection<PCollectionView<?>> sideInputsToRead; | ||
private final Map<Pair<PCollectionView<?>, BoundedWindow>, Object> inMemorySideInputs; | ||
|
||
public InMemorySideInputReader(final Collection<PCollectionView<?>> sideInputsToRead) { | ||
this.sideInputsToRead = sideInputsToRead; | ||
this.inMemorySideInputs = new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public boolean isReady(final PCollectionView view, final BoundedWindow window) { | ||
return window.maxTimestamp().getMillis() < curWatermark | ||
|| inMemorySideInputs.containsKey(Pair.of(view, window)); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public <T> T get(final PCollectionView<T> view, final BoundedWindow window) { | ||
// This gets called after isReady() | ||
final T sideInputData = (T) inMemorySideInputs.get(Pair.of(view, window)); | ||
return sideInputData == null | ||
// The upstream gave us an empty sideInput | ||
? ((ViewFn<Object, T>) view.getViewFn()).apply(new CreateViewTransform.MultiView<T>(Collections.emptyList())) | ||
// The upstream gave us a concrete sideInput | ||
: sideInputData; | ||
} | ||
|
||
@Override | ||
public <T> boolean contains(final PCollectionView<T> view) { | ||
return sideInputsToRead.contains(view); | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return sideInputsToRead.isEmpty(); | ||
} | ||
|
||
/** | ||
* Stores the side input in memory to be used with main inputs. | ||
* @param view of the side input. | ||
* @param sideInputElement to add. | ||
*/ | ||
public void addSideInputElement(final PCollectionView<?> view, | ||
final WindowedValue<SideInputElement<?>> sideInputElement) { | ||
for (final BoundedWindow bw : sideInputElement.getWindows()) { | ||
inMemorySideInputs.put(Pair.of(view, bw), sideInputElement.getValue().getSideInputValue()); | ||
} | ||
} | ||
|
||
/** | ||
* Say a DoFn of this reader has 3 main inputs and 4 side inputs. | ||
* {@link org.apache.nemo.runtime.executor.datatransfer.InputWatermarkManager} guarantees that the watermark here | ||
* is the minimum of the all 7 input streams. | ||
* @param newWatermark to set. | ||
*/ | ||
public void setCurrentWatermarkOfAllMainAndSideInputs(final long newWatermark) { | ||
if (curWatermark > newWatermark) { | ||
// Cannot go backwards in time. | ||
throw new IllegalStateException(curWatermark + " > " + newWatermark); | ||
} | ||
|
||
this.curWatermark = newWatermark; | ||
// TODO #282: Handle late data | ||
inMemorySideInputs.entrySet().removeIf(entry -> { | ||
return entry.getKey().right().maxTimestamp().getMillis() <= this.curWatermark; // Discard old sideinputs. | ||
}); | ||
} | ||
} |
This file contains 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 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
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.
Why don't you use the
view
, instead ofindex
? I think usingview
is more explicit, instead of the index.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.
SideInputElement(Int, Object) is cheaper to encode than SideInputElement(PCollectionView, Object)
(The Flink runner also uses Int rather than PCollectionView)