Skip to content

[HUDI-18383] Support selective meta field population#18384

Open
prashantwason wants to merge 2 commits intoapache:masterfrom
prashantwason:selective-meta-field-population
Open

[HUDI-18383] Support selective meta field population#18384
prashantwason wants to merge 2 commits intoapache:masterfrom
prashantwason:selective-meta-field-population

Conversation

@prashantwason
Copy link
Member

@prashantwason prashantwason commented Mar 25, 2026

Describe the issue this Pull Request addresses

Closes #18383
Discussion: #17959

Currently hoodie.populate.meta.fields is all-or-nothing: either all 5 meta columns are populated, or none are (all get empty strings). Users who disable it to save storage lose incremental query capability (which requires _hoodie_commit_time). Fields like _hoodie_record_key, _hoodie_partition_path, and _hoodie_file_name can be virtualized and don't need physical storage.

Summary and Changelog

Adds hoodie.meta.fields.to.exclude config for selective meta field population. Excluded meta fields are written as null (not empty string) for optimal Parquet storage savings (nulls take zero data bytes, stored as bit flags in definition levels).

Changes:

  • Added hoodie.meta.fields.to.exclude config property in HoodieTableConfig
  • Added getMetaFieldPopulationFlags() in HoodieWriteConfig returning a pre-computed boolean[5] array indexed by meta field ordinal
  • Modified all 4 write engine paths to conditionally populate meta fields:
    • Avro file writers (HoodieAvroParquetWriter, HoodieAvroOrcWriter, HoodieAvroHFileWriter) via new prepRecordWithMetadata() overload
    • Spark InternalRow writer (HoodieSparkParquetWriter) via conditional updateRecordMetadata()
    • Spark SQL row-writer (HoodieRowCreateHandle, HoodieDatasetBulkInsertHelper) via conditional meta field array
    • Flink writer (HoodieRowDataCreateHandle) via conditional values in HoodieRowDataCreation.create()
  • Disabled bloom filter when _hoodie_record_key is excluded (bloom filter indexes record keys)
  • Fixed null safety in Flink AbstractHoodieRowData.getString() to handle null meta columns without NPE

Example config:

hoodie.populate.meta.fields=true
hoodie.meta.fields.to.exclude=_hoodie_record_key,_hoodie_partition_path,_hoodie_file_name,_hoodie_commit_seqno

Impact

New config hoodie.meta.fields.to.exclude (default: empty). No behavior change for existing users. When configured, excluded meta fields are written as null instead of computed values. Public API addition only (new config property).

Risk Level

low - Additive change. Default behavior is unchanged (empty exclude list = all fields populated). The boolean[5] array is pre-computed once per writer constructor with zero per-row allocation overhead.

Documentation Update

New config hoodie.meta.fields.to.exclude added with inline documentation. Valid values are the 5 meta field names: _hoodie_commit_time, _hoodie_commit_seqno, _hoodie_record_key, _hoodie_partition_path, _hoodie_file_name. Only effective when hoodie.populate.meta.fields=true.

Contributor's checklist

  • Read through contributor's guide
  • Enough context is provided in the sections above
  • Adequate tests were added if applicable

Add hoodie.meta.fields.to.exclude config to selectively skip meta field
population. Excluded fields are written as null for optimal Parquet storage
savings while retaining incremental query capability via _hoodie_commit_time.

Covers all 4 write paths: Avro, Spark InternalRow, Spark SQL row-writer,
and Flink. Uses pre-computed boolean[5] for zero-overhead per-row checks.

Closes apache#18383

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the size:M PR with lines of changes in (100, 300] label Mar 25, 2026
: null;
metaFields[2] = populateField[2] ? recordKey : null;
metaFields[3] = populateField[3] ? row.getUTF8String(HoodieRecord.PARTITION_PATH_META_FIELD_ORD) : null;
metaFields[4] = populateField[4] ? fileName : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

So the metadata fields are still in the table schema, it's just not populated selectively.

Copy link
Contributor

@suryaprasanna suryaprasanna left a comment

Choose a reason for hiding this comment

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

Can we have unit tests for this change?

return getBooleanOrDefault(HoodieTableConfig.POPULATE_META_FIELDS);
}

public Set<String> getMetaFieldsToExclude() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be private?

flags[2] = !excluded.contains(HoodieRecord.RECORD_KEY_METADATA_FIELD);
flags[3] = !excluded.contains(HoodieRecord.PARTITION_PATH_METADATA_FIELD);
flags[4] = !excluded.contains(HoodieRecord.FILENAME_METADATA_FIELD);
return flags;
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 include OPERATION_METADATA_FIELD as well?

private final String fileId;
private final boolean preserveHoodieMetadata;
private final boolean skipMetadataWrite;
private final boolean[] populateField;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be populateIndividualMetaFields something like that, instead of populateField, what do you think?

private final UTF8String instantTime;

private final boolean populateMetaFields;
private final boolean[] populateField;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be populateIndividualMetaFields something like that, instead of populateField, what do you think?

row.update(COMMIT_SEQNO_METADATA_FIELD.ordinal(), UTF8String.fromString(seqIdGenerator.apply(recordCount)));
row.update(RECORD_KEY_METADATA_FIELD.ordinal(), recordKey);
row.update(PARTITION_PATH_METADATA_FIELD.ordinal(), UTF8String.fromString(partitionPath));
row.update(FILENAME_METADATA_FIELD.ordinal(), fileName);
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 include OPERATION_METADATA_FIELD as well?

sparkKeyGenerator
}

val populateField = config.getMetaFieldPopulationFlags
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be populateIndividualMetaFields something like that, instead of populateField, what do you think?

.withDocumentation("When enabled, populates all meta fields. When disabled, no meta fields are populated "
+ "and incremental queries will not be functional. This is only meant to be used for append only/immutable data for batch processing");

public static final ConfigProperty<String> META_FIELDS_TO_EXCLUDE = ConfigProperty
Copy link
Contributor

Choose a reason for hiding this comment

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

This would require table version upgrade, not sure how we want to track it as part of next version.

}

public HoodieAvroOrcWriter(String instantTime, StoragePath file, HoodieOrcConfig config, HoodieSchema schema,
TaskContextSupplier taskContextSupplier, boolean[] populateField) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be populateIndividualMetaFields something like that, instead of populateField, what do you think?

…LDS_TO_EXCLUDE

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hudi-bot
Copy link
Collaborator

CI report:

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

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 44.85981% with 59 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.08%. Comparing base (69fa35b) to head (0e16051).

Files with missing lines Patch % Lines
...java/org/apache/hudi/config/HoodieWriteConfig.java 36.36% 12 Missing and 2 partials ⚠️
...ache/hudi/io/storage/HoodieSparkParquetWriter.java 40.90% 10 Missing and 3 partials ⚠️
...g/apache/hudi/io/storage/HoodieAvroFileWriter.java 0.00% 13 Missing ⚠️
...che/hudi/io/storage/row/HoodieRowCreateHandle.java 54.54% 0 Missing and 5 partials ⚠️
...udi/io/storage/hadoop/HoodieAvroParquetWriter.java 54.54% 2 Missing and 3 partials ⚠️
.../hudi/io/storage/hadoop/HoodieAvroHFileWriter.java 66.66% 2 Missing and 1 partial ⚠️
...he/hudi/io/storage/hadoop/HoodieAvroOrcWriter.java 66.66% 2 Missing and 1 partial ⚠️
...rg/apache/hudi/HoodieDatasetBulkInsertHelper.scala 33.33% 0 Missing and 2 partials ⚠️
...torage/row/HoodieInternalRowFileWriterFactory.java 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #18384      +/-   ##
============================================
- Coverage     68.37%   66.08%   -2.29%     
+ Complexity    27573    22426    -5147     
============================================
  Files          2433     1994     -439     
  Lines        133268   110704   -22564     
  Branches      16034    13944    -2090     
============================================
- Hits          91122    73163   -17959     
+ Misses        35093    31325    -3768     
+ Partials       7053     6216     -837     
Flag Coverage Δ
common-and-other-modules ?
hadoop-mr-java-client 45.15% <30.43%> (-0.01%) ⬇️
spark-client-hadoop-common 48.53% <21.49%> (-0.04%) ⬇️
spark-java-tests 48.70% <42.99%> (-0.04%) ⬇️
spark-scala-tests 45.35% <37.38%> (-0.03%) ⬇️
utilities 38.48% <35.51%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...rg/apache/hudi/common/table/HoodieTableConfig.java 94.70% <100.00%> (-0.13%) ⬇️
...torage/row/HoodieInternalRowFileWriterFactory.java 85.71% <50.00%> (-3.18%) ⬇️
...rg/apache/hudi/HoodieDatasetBulkInsertHelper.scala 90.90% <33.33%> (-1.46%) ⬇️
.../hudi/io/storage/hadoop/HoodieAvroHFileWriter.java 87.95% <66.66%> (-2.96%) ⬇️
...he/hudi/io/storage/hadoop/HoodieAvroOrcWriter.java 83.09% <66.66%> (-3.06%) ⬇️
...che/hudi/io/storage/row/HoodieRowCreateHandle.java 81.98% <54.54%> (-4.00%) ⬇️
...udi/io/storage/hadoop/HoodieAvroParquetWriter.java 81.48% <54.54%> (-18.52%) ⬇️
...ache/hudi/io/storage/HoodieSparkParquetWriter.java 65.90% <40.90%> (-27.20%) ⬇️
...g/apache/hudi/io/storage/HoodieAvroFileWriter.java 43.47% <0.00%> (-56.53%) ⬇️
...java/org/apache/hudi/config/HoodieWriteConfig.java 86.55% <36.36%> (-3.30%) ⬇️

... and 784 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M PR with lines of changes in (100, 300]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support selective meta field population

5 participants