-
Notifications
You must be signed in to change notification settings - Fork 109
Source, map, collection, sink for bounded data streams in Flink #661
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
base: main
Are you sure you want to change the base?
Changes from all commits
2aebabd
00dc3a2
25305e3
08b3ea0
0e3cfa5
24bb94b
65147cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * 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.wayang.flink.channels; | ||
|
|
||
| import org.apache.flink.streaming.api.datastream.DataStream; | ||
| import org.apache.wayang.core.optimizer.OptimizationContext; | ||
| import org.apache.wayang.core.plan.executionplan.Channel; | ||
| import org.apache.wayang.core.plan.wayangplan.OutputSlot; | ||
| import org.apache.wayang.core.platform.AbstractChannelInstance; | ||
| import org.apache.wayang.core.platform.ChannelDescriptor; | ||
| import org.apache.wayang.core.platform.ChannelInstance; | ||
| import org.apache.wayang.core.platform.Executor; | ||
| import org.apache.wayang.flink.execution.FlinkExecutor; | ||
|
|
||
| import java.util.OptionalLong; | ||
|
|
||
| public class DataStreamChannel extends Channel { | ||
|
|
||
| /** | ||
| * {@link ChannelInstance} implementation for {@link DataStream}s. | ||
| */ | ||
| public class Instance extends AbstractChannelInstance { | ||
|
|
||
| private DataStream<?> dataStream; | ||
|
|
||
| // TODO: this.size is currently always 0 | ||
| private long size; | ||
|
|
||
| public Instance(final FlinkExecutor executor, | ||
| final OptimizationContext.OperatorContext producerOperatorContext, | ||
| final int producerOutputIndex) { | ||
| super(executor, producerOperatorContext, producerOutputIndex); | ||
| } | ||
|
|
||
| public void accept(final DataStream<?> dataStream) { | ||
| this.dataStream = dataStream; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public <T> DataStream<T> provideDataStream() { | ||
| return (DataStream<T>) this.dataStream; | ||
| } | ||
|
|
||
| @Override | ||
| public OptionalLong getMeasuredCardinality() { | ||
| return this.size == 0 ? super.getMeasuredCardinality() : OptionalLong.of(this.size); | ||
| } | ||
|
|
||
| @Override | ||
| public DataStreamChannel getChannel() { | ||
| return DataStreamChannel.this; | ||
| } | ||
|
|
||
| @Override | ||
| protected void doDispose() { | ||
| this.dataStream = null; | ||
| } | ||
| } | ||
|
|
||
| public static final ChannelDescriptor DESCRIPTOR = new ChannelDescriptor( | ||
| DataStreamChannel.class, true, false); | ||
|
|
||
| public static final ChannelDescriptor DESCRIPTOR_MANY = new ChannelDescriptor( | ||
| DataStreamChannel.class, true, false); | ||
|
|
||
| public DataStreamChannel(final ChannelDescriptor descriptor, final OutputSlot<?> outputSlot) { | ||
| super(descriptor, outputSlot); | ||
| assert descriptor == DESCRIPTOR || descriptor == DESCRIPTOR_MANY; | ||
| this.markForInstrumentation(); | ||
| } | ||
|
|
||
| private DataStreamChannel(final DataStreamChannel parent) { | ||
| super(parent); | ||
| } | ||
|
|
||
| @Override | ||
| public Channel copy() { | ||
| return new DataStreamChannel(this); | ||
| } | ||
|
|
||
| @Override | ||
| public Instance createInstance(final Executor executor, | ||
| final OptimizationContext.OperatorContext producerOperatorContext, | ||
| final int producerOutputIndex) { | ||
| return new Instance((FlinkExecutor) executor, producerOperatorContext, producerOutputIndex); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| package org.apache.wayang.flink.execution; | ||
|
|
||
| import org.apache.flink.api.java.ExecutionEnvironment; | ||
| import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; | ||
| import org.apache.wayang.core.api.Job; | ||
| import org.apache.wayang.core.api.exception.WayangException; | ||
| import org.apache.wayang.core.optimizer.OptimizationContext; | ||
|
|
@@ -35,7 +36,6 @@ | |
| import org.apache.wayang.flink.compiler.FunctionCompiler; | ||
| import org.apache.wayang.flink.operators.FlinkExecutionOperator; | ||
| import org.apache.wayang.flink.platform.FlinkPlatform; | ||
| import com.esotericsoftware.kryo.serializers.DefaultSerializers; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
|
|
@@ -56,6 +56,12 @@ public class FlinkExecutor extends PushExecutorTemplate { | |
| */ | ||
| public ExecutionEnvironment fee; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think ideally we just remove the old Env and also DataSet with it, so that the end user of wayang doesn't even notice this change (other than a few operators missing maybe)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per discussion in the dev-list I've delegated this to the configuration. |
||
|
|
||
|
|
||
| /** | ||
| * {@link StreamExecutionEnvironment} for bounded and continuous streams. | ||
| */ | ||
| public StreamExecutionEnvironment sEnv; | ||
|
|
||
| /** | ||
| * Compiler to create flink UDFs. | ||
| */ | ||
|
|
@@ -76,6 +82,7 @@ public FlinkExecutor(FlinkPlatform flinkPlatform, Job job) { | |
| super(job); | ||
| this.platform = flinkPlatform; | ||
| this.flinkContextReference = this.platform.getFlinkContext(job); | ||
| this.sEnv = flinkPlatform.streamExecutionEnvironment; | ||
| this.fee = this.flinkContextReference.get(); | ||
| this.numDefaultPartitions = (int) this.getConfiguration().getLongProperty("wayang.flink.parallelism"); | ||
| this.fee.setParallelism(this.numDefaultPartitions); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * 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.wayang.flink.mapping; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
|
|
||
| import org.apache.wayang.basic.operators.TextFileSource; | ||
| import org.apache.wayang.core.mapping.Mapping; | ||
| import org.apache.wayang.core.mapping.OperatorPattern; | ||
| import org.apache.wayang.core.mapping.PlanTransformation; | ||
| import org.apache.wayang.core.mapping.ReplacementSubplanFactory; | ||
| import org.apache.wayang.core.mapping.SubplanPattern; | ||
| import org.apache.wayang.flink.operators.FlinkBoundedTextFileSource; | ||
| import org.apache.wayang.flink.platform.FlinkPlatform; | ||
|
|
||
| public class BoundedTextFileSourceMapping implements Mapping { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As everything is bounded as of now in Wayang, I would just call this TextFileSource and replace TextFileSource from Flink with it. We can later add a StreamedTextFileSource.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevertheless since our discussion on continuous streams hasn't concluded either I still propose we keep the bounded semantic as a way to leave the door open for continuous sources later. |
||
| @Override | ||
| public Collection<PlanTransformation> getTransformations() { | ||
| return Collections.singleton(new PlanTransformation( | ||
| this.createSubplanPattern(), | ||
| this.createReplacementSubplanFactory(), | ||
| FlinkPlatform.getInstance() | ||
| )); | ||
| } | ||
|
|
||
| private SubplanPattern createSubplanPattern() { | ||
| final OperatorPattern<?> operatorPattern = new OperatorPattern<>( | ||
| "source", new TextFileSource("", null), false | ||
| ); | ||
| return SubplanPattern.createSingleton(operatorPattern); | ||
| } | ||
|
|
||
| private ReplacementSubplanFactory createReplacementSubplanFactory() { | ||
| return new ReplacementSubplanFactory.OfSingleOperators<TextFileSource>( | ||
| (matchedOperator, epoch) -> new FlinkBoundedTextFileSource(matchedOperator).at(epoch) | ||
| ); | ||
| } | ||
| } | ||
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.
Does this have any effects?
Uh oh!
There was an error while loading. Please reload this page.
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.
Leftovers from the old
DataSetChannelimplementation the user could theoretically extend the DataStreamChannel and provide their own, but its such a niche situation I'm fine with removing it.