Skip to content

Commit 08b3ea0

Browse files
committed
add configuration options for flink platform bounded datastreams
1 parent 25305e3 commit 08b3ea0

4 files changed

Lines changed: 72 additions & 7 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.wayang.flink.mapping;
20+
21+
import java.util.Collection;
22+
import java.util.Collections;
23+
24+
import org.apache.wayang.basic.operators.TextFileSource;
25+
import org.apache.wayang.core.mapping.Mapping;
26+
import org.apache.wayang.core.mapping.OperatorPattern;
27+
import org.apache.wayang.core.mapping.PlanTransformation;
28+
import org.apache.wayang.core.mapping.ReplacementSubplanFactory;
29+
import org.apache.wayang.core.mapping.SubplanPattern;
30+
import org.apache.wayang.flink.operators.FlinkBoundedTextFileSource;
31+
import org.apache.wayang.flink.platform.FlinkPlatform;
32+
33+
public class BoundedTextFileSourceMapping implements Mapping {
34+
@Override
35+
public Collection<PlanTransformation> getTransformations() {
36+
return Collections.singleton(new PlanTransformation(
37+
this.createSubplanPattern(),
38+
this.createReplacementSubplanFactory(),
39+
FlinkPlatform.getInstance()
40+
));
41+
}
42+
43+
private SubplanPattern createSubplanPattern() {
44+
final OperatorPattern<?> operatorPattern = new OperatorPattern<>(
45+
"source", new TextFileSource("", null), false
46+
);
47+
return SubplanPattern.createSingleton(operatorPattern);
48+
}
49+
50+
private ReplacementSubplanFactory createReplacementSubplanFactory() {
51+
return new ReplacementSubplanFactory.OfSingleOperators<TextFileSource>(
52+
(matchedOperator, epoch) -> new FlinkBoundedTextFileSource(matchedOperator).at(epoch)
53+
);
54+
}
55+
}

wayang-platforms/wayang-flink/src/main/java/org/apache/wayang/flink/mapping/Mappings.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,21 @@
1919
package org.apache.wayang.flink.mapping;
2020

2121
import org.apache.wayang.core.mapping.Mapping;
22+
import org.apache.wayang.flink.plugin.FlinkBasicPlugin;
2223

2324
import java.util.Arrays;
2425
import java.util.Collection;
2526

2627
/**
27-
* Register for {@link Mapping}s for this platform.
28+
* Register for {@link Mapping}s for {@link FlinkBasicPlugin}.
2829
*/
2930
public class Mappings {
3031

31-
public static Collection<Mapping> BASIC_MAPPINGS = Arrays.asList(
32+
/**
33+
* Mappings using Flink's DataSets
34+
* @deprecated DataSet API in Flink has been deprecated move over to bounded streams for a 1-to-1 replacement {@link #BOUNDED_STREAM_MAPPINGS}.
35+
*/
36+
public static final Collection<Mapping> BASIC_MAPPINGS = Arrays.asList(
3237
new CartesianMapping(),
3338
new CoGroupMapping(),
3439
new CollectionSourceMapping(),
@@ -60,6 +65,9 @@ public class Mappings {
6065
new ZipWithIdMapping()
6166
);
6267

68+
public static final Collection<Mapping> BOUNDED_STREAM_MAPPINGS = Arrays.asList(
69+
new BoundedTextFileSourceMapping()
70+
);
6371
}
6472

6573

wayang-platforms/wayang-flink/src/main/java/org/apache/wayang/flink/mapping/TextFileSourceMapping.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
/**
3434
* Mapping from {@link TextFileSource} to {@link FlinkTextFileSource}.
3535
*/
36-
@SuppressWarnings("unchecked")
3736
public class TextFileSourceMapping implements Mapping {
3837
@Override
3938
public Collection<PlanTransformation> getTransformations() {
@@ -46,7 +45,7 @@ public Collection<PlanTransformation> getTransformations() {
4645

4746

4847
private SubplanPattern createSubplanPattern() {
49-
final OperatorPattern operatorPattern = new OperatorPattern(
48+
final OperatorPattern<?> operatorPattern = new OperatorPattern<>(
5049
"source", new TextFileSource("", null), false
5150
);
5251
return SubplanPattern.createSingleton(operatorPattern);

wayang-platforms/wayang-flink/src/main/java/org/apache/wayang/flink/plugin/FlinkBasicPlugin.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@
3535
/**
3636
* This {@link Plugin} enables to use the basic Wayang {@link Operator}s on the {@link FlinkPlatform}.
3737
*/
38-
public class FlinkBasicPlugin implements Plugin{
38+
public class FlinkBasicPlugin implements Plugin {
39+
boolean useBoundedDataStreams = false;
40+
3941
@Override
4042
public Collection<Platform> getRequiredPlatforms() {
4143
return Arrays.asList(FlinkPlatform.getInstance(), JavaPlatform.getInstance());
4244
}
4345

4446
@Override
4547
public Collection<Mapping> getMappings() {
46-
return Mappings.BASIC_MAPPINGS;
48+
49+
return useBoundedDataStreams ? Mappings.BOUNDED_STREAM_MAPPINGS : Mappings.BASIC_MAPPINGS;
4750
}
4851

4952
@Override
@@ -53,6 +56,6 @@ public Collection<ChannelConversion> getChannelConversions() {
5356

5457
@Override
5558
public void setProperties(Configuration configuration) {
56-
59+
useBoundedDataStreams = configuration.getBooleanProperty("wayang.flink.platforms.useDataStreams", false);
5760
}
5861
}

0 commit comments

Comments
 (0)