Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-1643] [streaming] Auto detection of tumbling policies added + …
…WindowedDataStream refactor
- Loading branch information
Showing
13 changed files
with
300 additions
and
139 deletions.
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
84 changes: 84 additions & 0 deletions
84
...rg/apache/flink/streaming/api/invokable/operator/windowing/ParallelWindowPartitioner.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,84 @@ | |||
/* | |||
* 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.flink.streaming.api.invokable.operator.windowing; | |||
|
|||
import org.apache.flink.api.java.functions.KeySelector; | |||
import org.apache.flink.streaming.api.invokable.ChainableInvokable; | |||
import org.apache.flink.streaming.api.windowing.StreamWindow; | |||
|
|||
/** | |||
* This invokable applies either split or key partitioning depending on the | |||
* transformation. | |||
*/ | |||
public class ParallelWindowPartitioner<T> extends | |||
ChainableInvokable<StreamWindow<T>, StreamWindow<T>> { | |||
|
|||
private KeySelector<T, ?> keySelector; | |||
private int numberOfSplits; | |||
private int currentWindowID = 0; | |||
|
|||
public ParallelWindowPartitioner(KeySelector<T, ?> keySelector) { | |||
super(null); | |||
this.keySelector = keySelector; | |||
} | |||
|
|||
public ParallelWindowPartitioner(int numberOfSplits) { | |||
super(null); | |||
this.numberOfSplits = numberOfSplits; | |||
} | |||
|
|||
private static final long serialVersionUID = 1L; | |||
|
|||
@Override | |||
public void invoke() throws Exception { | |||
while (isRunning && readNext() != null) { | |||
callUserFunctionAndLogException(); | |||
} | |||
} | |||
|
|||
@Override | |||
protected void callUserFunction() throws Exception { | |||
StreamWindow<T> currentWindow = nextObject; | |||
currentWindow.setID(++currentWindowID); | |||
|
|||
if (keySelector == null) { | |||
if (numberOfSplits <= 1) { | |||
collector.collect(currentWindow); | |||
} else { | |||
for (StreamWindow<T> window : currentWindow.split(numberOfSplits)) { | |||
collector.collect(window); | |||
} | |||
} | |||
} else { | |||
|
|||
for (StreamWindow<T> window : currentWindow.partitionBy(keySelector)) { | |||
collector.collect(window); | |||
} | |||
|
|||
} | |||
} | |||
|
|||
@Override | |||
public void collect(StreamWindow<T> record) { | |||
if (isRunning) { | |||
nextObject = record; | |||
callUserFunctionAndLogException(); | |||
} | |||
} | |||
|
|||
} |
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
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
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.