danny0405 commented on code in PR #13381: URL: https://github.com/apache/hudi/pull/13381#discussion_r2119844459
########## rfc/rfc-95/rfc-95.md: ########## @@ -0,0 +1,263 @@ +<!-- + 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. +--> +# RFC-95: Hudi Flink Source Implementation + +## Proposers + +- HuangZhenQiu + +## Approvers + - Danny Chan + +## Status + +JIRA: [HUDI-9483](https://issues.apache.org/jira/browse/HUDI-9483) + +## Abstract +This RFC proposes support for new Flink source API for Flink hudi source. Hudi currently supports reading data via Flink Source Function APIs. However, it lacks a native Flink +Source API implementation for consuming Hudi tables as a first-class Flink source. The proposal aims to fill that gap by implementing a Flink Source that adheres to Flink's Source API +(introduced in Flink 1.11 and enhanced in 1.13+) to enable efficient, scalable and consistent reading of Hudi dataset in both streaming and batch modes. + +## Background +Flink FLIP-27 solve several problems/shortcomings in the streaming source interface (SourceFunction) and simultaneously to unify the source interfaces between the batch and streaming APIs. +By adopting the new source interface, Flink can read hudi data in batch mode for better processing efficiency of bounded data. It also unblocks Flink Hudi user to use Flink hybrid source to seamless +switch reading data from hudi to kafka for back-fill use cases. + +## Implementation +In the FLIP-27, the new source api split the reading logic into two major parts, SplitEnumerator, Reader. In the proposal, the implementation of native FlinkHudiSource using Flink's unified Source API +will be discussed. It supports both snapshot and incremental modes, integrate with Hudi's metadata and file indexing, provide fault-tolerant Flink sources. For the Flink SQL user, the split order and +watermark emitter for each split is very important for the correctness of result of window aggregation and window join. Thus, watermark emit and event-time processing will also be discussed below. + + + +### Hudi Source + +```java +public class HudiSource implements Source<RowData, HudiSourceSplit, HudiEnumeratorState> { + + //... + @Override + public Boundedness getBoundedness() { + return scanContext.isStreaming() ? Boundedness.CONTINUOUS_UNBOUNDED : Boundedness.BOUNDED; + } + + @Override + public SourceReader<T, HudiSourceSplit> createReader(SourceReaderContext readerContext) { + HudiSourceReaderMetrics metrics = + new HudiSourceReaderMetrics(readerContext.metricGroup(), tableName); + return new HudiSourceReader<>( + emitter, metrics, readerFunction, splitComparator, readerContext); + } + + @Override + public SplitEnumerator<HudiSourceSplit, HudiEnumeratorState> createEnumerator( + SplitEnumeratorContext<HudiSourceSplit> enumContext) { + return createEnumerator(enumContext, null); + } + + @Override + public SplitEnumerator<HudiSourceSplit, HudiEnumeratorState> restoreEnumerator( + SplitEnumeratorContext<HudiSourceSplit> enumContext, HudiEnumeratorState enumState) { + return createEnumerator(enumContext, enumState); + } + + @Override + public SimpleVersionedSerializer<HudiSourceSplit> getSplitSerializer() { + return new HudiSourceSplitSerializer(scanContext.caseSensitive()); + } + + @Override + public SimpleVersionedSerializer<HudiEnumeratorState> getEnumeratorCheckpointSerializer() { + return new HudiEnumeratorStateSerializer(scanContext.caseSensitive()); + } + + // ... +} +``` + +### Hudi Split +Similar to existing MergeOnReadInputSplit that implements InputSplit API, A new MergeOnReadSourceSplit and CdcSourceSplit will be implemented with the new SourceSplit interface. +FlinkRowDataReaderContext will be extended to be able to apply HudiSourceSplit and return a CloseableIterator that iterates RecordsWithSplitIds. Base on the change, the HudiSourceSplitReader Review Comment: Can you elaborate this `RecordsWithSplitIds`? -- 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]
