jsingh-yelp commented on code in PR #7311: URL: https://github.com/apache/paimon/pull/7311#discussion_r2904676303
########## paimon-flink/paimon-flink2-common/src/main/java/org/apache/paimon/flink/lineage/DataStreamProviderFactory.java: ########## @@ -0,0 +1,117 @@ +/* + * 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.paimon.flink.lineage; + +import org.apache.paimon.table.Table; + +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.datastream.DataStreamSink; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.lineage.LineageVertex; +import org.apache.flink.streaming.api.lineage.LineageVertexProvider; +import org.apache.flink.table.connector.ProviderContext; +import org.apache.flink.table.connector.sink.DataStreamSinkProvider; +import org.apache.flink.table.connector.sink.DynamicTableSink.SinkRuntimeProvider; +import org.apache.flink.table.connector.source.DataStreamScanProvider; +import org.apache.flink.table.connector.source.ScanTableSource.ScanRuntimeProvider; +import org.apache.flink.table.data.RowData; + +/** + * Factory that wraps {@link DataStreamScanProvider} and {@link DataStreamSinkProvider} with {@link + * LineageVertexProvider} support for Flink 2.0+. + */ +public class DataStreamProviderFactory { + + /** + * Returns a {@link ScanRuntimeProvider} that also implements {@link LineageVertexProvider} so + * Flink's lineage graph discovers the Paimon source table. + */ + public static ScanRuntimeProvider getScanProvider( + ScanRuntimeProvider provider, String name, Table table) { + return new LineageAwarePaimonDataStreamScanProvider( + (DataStreamScanProvider) provider, name, table); + } + + /** + * Returns a {@link SinkRuntimeProvider} that also implements {@link LineageVertexProvider} so + * Flink's lineage graph discovers the Paimon sink table. + */ + public static SinkRuntimeProvider getSinkProvider( + SinkRuntimeProvider provider, String name, Table table) { + return new LineageAwarePaimonDataStreamSinkProvider( + (DataStreamSinkProvider) provider, name, table); + } + + private static class LineageAwarePaimonDataStreamScanProvider + implements DataStreamScanProvider, LineageVertexProvider { Review Comment: Thanks for the review @yunfengzhou-hub. The reason for the delegate pattern is backward compatibility. `PaimonDataStreamScanProvider` lives in paimon-flink-common, which is built against multiple Flink versions, including ones older than 1.20. Since `LineageVertexProvider` only exists in Flink 1.20+, having `PaimonDataStreamScanProvider` directly implement it would cause a ClassNotFoundException at build/load time for older Flink versions. By using the delegate pattern with a version-specific `DataStreamProviderFactory`, the lineage-aware wrapper is only created in the paimon-flink2-common module (which targets Flink 2.x), and the older Flink modules never reference LineageVertexProvider at all. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
