Skip to content

Commit 4557599

Browse files
authored
[flink] fix compatibility issues of StreamExecutionEnv (#7615)
1 parent ef2d480 commit 4557599

5 files changed

Lines changed: 94 additions & 4 deletions

File tree

paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/RemoveUnexistingFilesAction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.paimon.flink.sink.Committable;
2323
import org.apache.paimon.flink.sink.CommittableTypeInfo;
2424
import org.apache.paimon.flink.utils.BoundedOneInputOperator;
25+
import org.apache.paimon.flink.utils.StreamExecutionEnvironmentUtils;
2526
import org.apache.paimon.io.CompactIncrement;
2627
import org.apache.paimon.io.DataFileMeta;
2728
import org.apache.paimon.io.DataIncrement;
@@ -108,7 +109,8 @@ public DataStream<String> buildDataStream() throws Exception {
108109
List<BinaryRow> binaryPartitions = fileStoreTable.newScan().listPartitions();
109110

110111
SingleOutputStreamOperator<byte[]> source =
111-
env.fromData(
112+
StreamExecutionEnvironmentUtils.fromData(
113+
env,
112114
binaryPartitions.stream()
113115
.map(BinaryRow::toBytes)
114116
.collect(Collectors.toList()),

paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/btree/BTreeIndexTopoBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.paimon.flink.sorter.TableSorter;
3535
import org.apache.paimon.flink.utils.BoundedOneInputOperator;
3636
import org.apache.paimon.flink.utils.JavaTypeInfo;
37+
import org.apache.paimon.flink.utils.StreamExecutionEnvironmentUtils;
3738
import org.apache.paimon.globalindex.GlobalIndexParallelWriter;
3839
import org.apache.paimon.globalindex.btree.BTreeGlobalIndexBuilder;
3940
import org.apache.paimon.globalindex.btree.BTreeIndexOptions;
@@ -211,7 +212,10 @@ protected static DataStream<Committable> executeForPartitionRange(
211212
parallelism = Math.min(parallelism, maxParallelism);
212213

213214
DataStream<Split> sourceStream =
214-
env.fromData(new JavaTypeInfo<>(Split.class), rangeSplits.toArray(new Split[0]))
215+
StreamExecutionEnvironmentUtils.fromData(
216+
env,
217+
new JavaTypeInfo<>(Split.class),
218+
rangeSplits.toArray(new Split[0]))
215219
.name("Global Index Source " + " range=" + range)
216220
.setParallelism(1);
217221

paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/globalindex/GenericIndexTopoBuilder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.paimon.flink.sink.StoreCommitter;
2929
import org.apache.paimon.flink.utils.BoundedOneInputOperator;
3030
import org.apache.paimon.flink.utils.JavaTypeInfo;
31+
import org.apache.paimon.flink.utils.StreamExecutionEnvironmentUtils;
3132
import org.apache.paimon.globalindex.GlobalIndexSingletonWriter;
3233
import org.apache.paimon.globalindex.ResultEntry;
3334
import org.apache.paimon.index.IndexFileMeta;
@@ -179,7 +180,8 @@ public static boolean buildIndex(
179180
ReadBuilder readBuilder = table.newReadBuilder().withReadType(projectedRowType);
180181

181182
DataStream<ShardTask> source =
182-
env.fromData(
183+
StreamExecutionEnvironmentUtils.fromData(
184+
env,
183185
new JavaTypeInfo<>(ShardTask.class),
184186
shardTasks.toArray(new ShardTask[0]))
185187
.name("Generic Index Source")
@@ -201,7 +203,8 @@ public static boolean buildIndex(
201203
if (!deletedIndexEntries.isEmpty()) {
202204
List<Committable> deleteCommittables = createDeleteCommittables(deletedIndexEntries);
203205
DataStream<Committable> deletes =
204-
env.fromData(
206+
StreamExecutionEnvironmentUtils.fromData(
207+
env,
205208
new CommittableTypeInfo(),
206209
deleteCommittables.toArray(new Committable[0]))
207210
.name("Index Delete Source")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.paimon.flink.utils;
20+
21+
import org.apache.flink.api.common.typeinfo.TypeInformation;
22+
import org.apache.flink.streaming.api.datastream.DataStreamSource;
23+
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
24+
25+
import java.util.Arrays;
26+
import java.util.Collection;
27+
28+
/** Utility methods about {@link StreamExecutionEnvironment} to resolve compatibility issues. */
29+
public class StreamExecutionEnvironmentUtils {
30+
31+
@SafeVarargs
32+
public static <T> DataStreamSource<T> fromData(
33+
StreamExecutionEnvironment env, TypeInformation<T> typeInfo, T... data) {
34+
return env.fromCollection(Arrays.asList(data), typeInfo);
35+
}
36+
37+
public static <T> DataStreamSource<T> fromData(
38+
StreamExecutionEnvironment env, Collection<T> data, TypeInformation<T> typeInfo) {
39+
return env.fromCollection(data, typeInfo);
40+
}
41+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.paimon.flink.utils;
20+
21+
import org.apache.flink.api.common.typeinfo.TypeInformation;
22+
import org.apache.flink.streaming.api.datastream.DataStreamSource;
23+
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
24+
25+
import java.util.Collection;
26+
27+
/** Utility methods about {@link StreamExecutionEnvironment} to resolve compatibility issues. */
28+
public class StreamExecutionEnvironmentUtils {
29+
30+
@SafeVarargs
31+
public static <T> DataStreamSource<T> fromData(
32+
StreamExecutionEnvironment env, TypeInformation<T> typeInfo, T... data) {
33+
return env.fromData(typeInfo, data);
34+
}
35+
36+
public static <T> DataStreamSource<T> fromData(
37+
StreamExecutionEnvironment env, Collection<T> data, TypeInformation<T> typeInfo) {
38+
return env.fromData(data, typeInfo);
39+
}
40+
}

0 commit comments

Comments
 (0)