Skip to content
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

[HUDI-9147] Support HoodieFileGroupReader for Flink and use FileGroup reader in compaction #13078

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

cshuo
Copy link
Contributor

@cshuo cshuo commented Apr 3, 2025

Change Logs

  • Implement FileGroup reader for Flink
  • Support Flink compaction use FileGroup reader

Impact

Improve perf for Flink compaction

Risk level (write none, low medium or high below)

medium

Documentation Update

Describe any necessary documentation update if there is any new feature, config, or user-facing change. If not, put "none".

  • The config description must be updated if new configs are added or the default value of the configs are changed
  • Any new feature or user-facing change requires updating the Hudi website. Please create a Jira ticket, attach the
    ticket number here and follow the instruction to make
    changes to the website.

Contributor's checklist

  • Read through contributor's guide
  • Change Logs and Impact were stated clearly
  • Adequate tests were added if applicable
  • CI passed

@github-actions github-actions bot added the size:XL PR with lines of changes > 1000 label Apr 3, 2025
@cshuo cshuo force-pushed the HUDI-9147 branch 6 times, most recently from d65a9ab to 1fb19df Compare April 3, 2025 13:53
@cshuo
Copy link
Contributor Author

cshuo commented Apr 4, 2025

cc @danny0405 PTAL, thks


@Override
public String getRecordKey(RowData record, Schema schema) {
return Objects.toString(getValue(record, schema, RECORD_KEY_METADATA_FIELD));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the record key metadata always there in the row data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here just follows the current FG reader based compaction in HoodieCompactor:

&& config.populateMetaFields(); // Virtual key support by fg reader is not ready

i.e., one of the prerequisites for FG reader based compaction is populateMetaFields is enabled.

(String) metadataMap.get(INTERNAL_META_PARTITION_PATH));
// delete record
if (recordOption.isEmpty()) {
return new HoodieEmptyRecord<>(hoodieKey, HoodieRecord.HoodieRecordType.FLINK);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to set up the ordering value correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, will update.

public RowData seal(RowData rowData) {
if (rowDataSerializer == null) {
RowType requiredRowType = (RowType) AvroSchemaConverter.convertToDataType(getSchemaHandler().getRequiredSchema()).getLogicalType();
rowDataSerializer = new RowDataSerializer(requiredRowType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to cache the serializer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The serializer here is not created at record level, it's a member field for the FlinkRowDataReaderContext

}
}

AbstractHoodieRowData rowWithMetaFields = HoodieRowDataCreation.create(metaFields, data, withOperationField, withMetaFields);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just store StringData for AbstractHoodieRowData metadata fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that for memory efficiency.

@@ -309,7 +309,7 @@ public Map<String, Object> generateMetadataForRecord(
* @param schema The Avro schema of the record.
* @return A mapping containing the metadata.
*/
public Map<String, Object> generateMetadataForRecord(T record, Schema schema) {
public Map<String, Object> generateMetadataForRecord(T record, Schema schema, Option<String> orderingFieldName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orderingFieldName is added to generate ordering value in FlinkRowDataReaderContext.

generateMetadataForRecord only generates recordKey by default, and the generated metadata map will be used to construct HoodieFlinkRecord in constructHoodieRecord(Option<RowData> recordOption, Map<String, Object> metadataMap), where ordering value is necessary.

@@ -138,6 +139,15 @@ private FlinkOptions() {
+ "These merger impls will filter by record.merger.strategy. "
+ "Hudi will pick most efficient implementation to perform merging/combining of the records (during update, reading MOR table, etc)");

@AdvancedConfig
public static final ConfigOption<String> RECORD_MERGE_MODE = ConfigOptions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add the option for Hoodie core options, all the hoodie options are applied automically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, users can configure merging strategy by the option payload.class (default value is EventTimeAvroPayload for event time merging semantics), which is Avro-based.

After we introduce FG reader based compaction, users should not use the legacy config based on Avro payload, and the merging mode configs should be exposed to users to choose the expected merging behavior.

Btw, the compatibility work for payload config is also included in in the PR.

String instantTime,
Option<EngineBroadcastManager> broadcastManagerOpt) throws IOException {
Configuration conf = metaClient.getStorage().getConf().unwrapAs(Configuration.class);
FlinkRowDataReaderContext readerContext = new FlinkRowDataReaderContext(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is no need to store Flink conf in FlinkRowDataReaderContext, the InternalSchemaManager needs the Flink conf to do 2 things:

  1. decide if the schema evolution is enabled: we can move this check into HoodieWriteConfig.isSchemaEvolutionEnabled;
  2. generates Hadoop conf from it, but the hadoop conf is already in FlinkRowDataReaderContext.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the usage you mentioned, flink conf stored in FlinkRowDataReaderContext is also used to:

  • generate partition specs for FlinkParquetReader;
  • get config read.utc-timezone to create field converter (Flink value -> Avro value) in getOrderingValue;

Any recommended cleaner way to achieve these?

@cshuo
Copy link
Contributor Author

cshuo commented Apr 5, 2025

Java CI / validate-bundles (scala-2.12, flink1.14, 1.10.0, spark3.3, spark3.3.4) failed because hudi-flink 1.14 bundle is running with flink-1.15 docker env, and there is some class compatibility problem, will see how to fix this.

@hudi-bot
Copy link

hudi-bot commented Apr 6, 2025

CI report:

Bot commands @hudi-bot supports the following commands:
  • @hudi-bot run azure re-run the last Azure build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XL PR with lines of changes > 1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants