refactor(common): hoist shared instant file name bodies - #19889
Conversation
InstantFileNameGeneratorV1 and InstantFileNameGeneratorV2 were byte-identical except for five members. Move the 33 shared bodies (the StringUtils.join extension one-liners plus makeDeltaFileName, getCommitFromCommitFile, makeFileNameAsComplete and makeFileNameAsInflight) verbatim into a new abstract BaseInstantFileNameGenerator in org.apache.hudi.common.table.timeline. V1 and V2 now extend the base and keep only the layout-specific members: getLayoutVersion, makeRequestedClusteringFileName, makeInflightClusteringFileName (V1 aliases the replace-commit names, V2 has dedicated clustering extensions), getFileName(HoodieInstant) and getFileName(String, HoodieInstant) (V2 emits requestedTime_completionTime for completed instants). These stay abstract so a future layout version must state them explicitly. The InstantFileNameGenerator interface, DefaultInstantFileNameGenerator and every caller are unchanged. The only text edit inside a retained body is V1's "1n 0.x" comment typo, now "In 0.x".
hudi-agent
left a comment
There was a problem hiding this comment.
Thanks for the contribution! This PR hoists the 33 layout-independent instant file naming methods out of InstantFileNameGeneratorV1/V2 into a new abstract BaseInstantFileNameGenerator, leaving only the five layout-specific members in the concrete classes. I verified against origin/master that the two originals differed only in those five members, that the hoisted bodies are byte-identical, that all 37 interface methods remain implemented, and that nothing keys on the concrete class hierarchy. No issues flagged from this automated pass — a Hudi committer or PMC member can take it from here for a final review.
cc @yihua
|
shoude be by design, the pattern is introducing a common interface then duplicate the impls, so that it is more easier to drop these logics when moving forward. The cost of maintaining looks okay since the evolving itself is quite slow and we just got two copies. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19889 +/- ##
============================================
+ Coverage 77.60% 79.68% +2.08%
- Complexity 33544 34388 +844
============================================
Files 2546 2547 +1
Lines 142452 142420 -32
Branches 17330 17330
============================================
+ Hits 110553 113493 +2940
+ Misses 23830 20929 -2901
+ Partials 8069 7998 -71
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
I don't quite understand the argument here. If V1 needs to be dropped, the whole class can be removed even with the refactor without issue. Also, flattening both into each class means that looking for differences can only be answered by diffing ~200 lines. With a skeletal base, the version class contains nothing but the delta, so the per-version mapping becomes more visible, not less. This improves code readability, easier to review if we're not using LLM assisted reviews and also copy-paste errors. |
Describe the issue this Pull Request addresses
InstantFileNameGeneratorV1andInstantFileNameGeneratorV2were byte-identical except for five members. The other 33 methods (theStringUtils.join(instantTime, EXTENSION)one-liners plusmakeDeltaFileName,getCommitFromCommitFile,makeFileNameAsCompleteandmakeFileNameAsInflight) were maintained twice, so any new extension had to be added in both places.Summary and Changelog
No user-visible change. Pure code motion inside
hudi-common.BaseInstantFileNameGeneratorinorg.apache.hudi.common.table.timeline, next to the interface, holding the 33 layout-independent bodies unchanged.InstantFileNameGeneratorV1andInstantFileNameGeneratorV2now extend it and keep only what differs per layout version:getLayoutVersionmakeRequestedClusteringFileName/makeInflightClusteringFileName(V1 aliases the replace-commit names, V2 has dedicated clustering extensions)getFileName(HoodieInstant)/getFileName(String completionTime, HoodieInstant)(V2 emitsrequestedTime_completionTimefor completed instants)InstantFileNameGeneratorinterface is unchanged,DefaultInstantFileNameGeneratorstill extends V2, and every caller goes through the interface orTimelineLayout, so no call site changes.The five members are left abstract rather than defaulted, so a future layout version still has to state them explicitly.
Details
InstantFileNameGeneratorare not affected.1n 0.xtoIn 0.x.TimelineLayout,TimelineArchiverV1,HoodieMetaserverBasedTimelineand the Spark tests (TestSparkReaderContextFactory,TestHoodieSparkRollback,TestColumnStatsIndex) compile as before.Impact
None. The generated file names are identical for every action, state and layout version.
Risk Level
none
Documentation Update
none
Contributor's checklist