|
20 | 20 | import org.apache.flink.api.common.typeinfo.TypeInformation;
|
21 | 21 | import org.apache.flink.api.connector.sink2.Sink;
|
22 | 22 | import org.apache.flink.api.connector.sink2.TwoPhaseCommittingSink;
|
| 23 | +import org.apache.flink.api.connector.source.Boundedness; |
| 24 | +import org.apache.flink.api.dag.Transformation; |
23 | 25 | import org.apache.flink.cdc.common.annotation.Internal;
|
24 | 26 | import org.apache.flink.cdc.common.annotation.VisibleForTesting;
|
25 | 27 | import org.apache.flink.cdc.common.configuration.Configuration;
|
|
48 | 50 | import org.apache.flink.streaming.api.operators.OneInputStreamOperatorFactory;
|
49 | 51 | import org.apache.flink.streaming.api.transformations.LegacySinkTransformation;
|
50 | 52 | import org.apache.flink.streaming.api.transformations.PhysicalTransformation;
|
| 53 | +import org.apache.flink.streaming.api.transformations.WithBoundedness; |
| 54 | +import org.apache.flink.util.Preconditions; |
51 | 55 |
|
52 | 56 | import java.lang.reflect.InvocationTargetException;
|
53 | 57 |
|
@@ -158,8 +162,9 @@ private <CommT> void addCommittingTopology(
|
158 | 162 | ((WithPreCommitTopology<Event, CommT>) sink).addPreCommitTopology(written);
|
159 | 163 | }
|
160 | 164 |
|
161 |
| - // TODO: Hard coding stream mode and checkpoint |
162 |
| - boolean isBatchMode = false; |
| 165 | + boolean isBatchMode = !existsUnboundedSource(inputStream.getTransformation()); |
| 166 | + |
| 167 | + // TODO: Hard coding checkpoint |
163 | 168 | boolean isCheckpointingEnabled = true;
|
164 | 169 | DataStream<CommittableMessage<CommT>> committed =
|
165 | 170 | preCommitted.transform(
|
@@ -209,4 +214,16 @@ private static <CommT> SimpleVersionedSerializer<CommT> getCommittableSerializer
|
209 | 214 | throw new RuntimeException("Failed to create CommitterOperatorFactory", e);
|
210 | 215 | }
|
211 | 216 | }
|
| 217 | + |
| 218 | + private boolean existsUnboundedSource(final Transformation<?> transformation) { |
| 219 | + return isUnboundedSource(transformation) |
| 220 | + || transformation.getTransitivePredecessors().stream() |
| 221 | + .anyMatch(this::isUnboundedSource); |
| 222 | + } |
| 223 | + |
| 224 | + private boolean isUnboundedSource(final Transformation<?> transformation) { |
| 225 | + Preconditions.checkNotNull(transformation); |
| 226 | + return transformation instanceof WithBoundedness |
| 227 | + && ((WithBoundedness) transformation).getBoundedness() != Boundedness.BOUNDED; |
| 228 | + } |
212 | 229 | }
|
0 commit comments