Skip to content

refactor: decouple read/write responsibilities and introduce ColumnBinding - #1128

Open
bengbengbalabalabeng wants to merge 18 commits into
apache:mainfrom
bengbengbalabalabeng:refactor-converters
Open

bengbengbalabalabeng wants to merge 18 commits into
apache:mainfrom
bengbengbalabalabeng:refactor-converters

Conversation

@bengbengbalabalabeng

@bengbengbalabalabeng bengbengbalabalabeng commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Purpose of the pull request

Related: #1104

What's changed?

  • Separate Converter into WriteConverter (write-specific) and ReadConverter (read-specific) while preserving backward compatibility
  • Introduce ColumnBinding to support column-scoped converters in dynamic/no-bean scenarios
  • Introduce hierarchical CellDataConverterRegistry supporting local-first delegation
  • Eliminate the tight coupling between CSV export and CellDataType in write workflows
  • Ensure template fill compatibility, supporting both native cell writes and multi-variable text interpolation

For more examples, please refer to: #1104

Checklist

  • I have read the Contributor Guide.
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

…and column binding

- Separate Converter into WriteConverter (write-specific) and ReadConverter (read-specific)
- Introduce ColumnBinding to support column-scoped converters in dynamic/no-bean scenarios
- Introduce hierarchical CellDataConverterRegistry supporting local-first delegation
- Implement LIFO precedence for custom converters
- Eliminate the issue where CSV types strongly depend on CellDataType in writing
@bengbengbalabalabeng
bengbengbalabalabeng marked this pull request as ready for review October 7, 2026 11:41
@nkuprins

nkuprins commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Thanks! All the issues mentioned are fixed.
But before approving the PR, I still have to take another deeper look (later this week).

@nkuprins nkuprins left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The global-converter docs from #1091 no longer match how this PR looks up write converters. They say a global write converter has to return null from supportExcelTypeKey() for XLSX/XLS (the GlobalStringWriteConverter variant) and CellDataTypeEnum.STRING for CSV.

Do you plan to update the docs in this PR, or in a separate one?

@bengbengbalabalabeng

Copy link
Copy Markdown
Contributor Author

The global-converter docs from #1091 no longer match how this PR looks up write converters. They say a global write converter has to return null from supportExcelTypeKey() for XLSX/XLS (the GlobalStringWriteConverter variant) and CellDataTypeEnum.STRING for CSV.

Do you plan to update the docs in this PR, or in a separate one?

The relevant documentation has been updated.

nkuprins
nkuprins previously approved these changes Nov 1, 2026

@nkuprins nkuprins left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Amazing PR 🎉

@bengbengbalabalabeng

Copy link
Copy Markdown
Contributor Author

@nkuprins , thank you very much for your review and valuable feedback!

Since these changes touch the core converter architecture and write execution flow, I'd suggest gathering additional reviews/approvals just to err on the side of caution.

@GOODBOY008 @delei, please take a look when you have a chance. Thanks!

@Mikkey-f Mikkey-f left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Header cells are pulled through custom converters

ConverterUtils.convertToStringMap is only used for header rows (AnalysisEventListener#invokeHead and DefaultAnalysisEventProcessor#buildHead), but it now resolves through the registry:

readSheetHolder.converterRegistry().findReadConverter(String.class, cellData.getType(), key)

findReadConverter gives custom and column-bound converters precedence (selectConverter), so the header path starts applying them:

  • a global ReadConverter<String> rewrites every header cell — this is issue #1098, still open;
  • a ColumnBinding converter rewrites the header cell in its bound column. That one is new in this PR: the header path now passes the column index, even though binding is meant for data cells.

I verified on ea56a7c6 with a small probe (header NAME, one data row, model @ExcelProperty("NAME")):

global converter:    invokeHeadMap -> {0=MOCK}; @ExcelProperty field -> null
column-bound (0):    invokeHeadMap -> {0=MOCK}; @ExcelProperty field -> null

Resolving the header lookup against built-in read converters only (DefaultConverterLoader.loadDefaultReadConverter() or a registry findDefaultReadConverter) makes both pass. CustomConverterTest, CustomConverterRoundTripTest, CellDataConverterRegistryTest, DefaultConverterLoaderTest and ReadConverterIsolationTest stay green; only two ConverterUtilsTest mock stubs need updating for AnalysisContext#currentReadHolder.

This matches your earlier ruling on #1098 that converters apply to data cells, not header parsing. Our #1212 fixes the header path on the old architecture — I'm happy to rework it against the registry after this merges if you'd rather keep this PR scoped. Which do you prefer?

@bengbengbalabalabeng

Copy link
Copy Markdown
Contributor Author

Hi @Mikkey-f ,

Since the related follow-up issues are already covered in #1098 and #1212, I suggest continuing those discussions in their respective threads.

The current scope of this PR is already fairly complete. To keep it manageable and avoid high review and merge overhead from an overly large PR, I would prefer not to introduce further changes here.

@Mikkey-f

Mikkey-f commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for the reply — understood, let's keep #1128 scoped as it is.

I'll continue the header-path discussion in #1098 and #1212. Once this merges, I'll rework #1212 against the new CellDataConverterRegistry (header lookup restricted to built-in converters) and add a regression test covering the column-bound case as well, so the follow-up lives in one place.

@delei

delei commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Hi, @bengbengbalabalabeng & @nkuprins

I noticed that this PR is related to older PRs and there might even be conflicts arising from it. In order to coordinate the various improvements made by different contributors, please first review and evaluate #1069 .

If the current PR better aligns with the final expectations, please consider reaching a consensus with other contributors(e.g., @Mikkey-f ). I'm willing to coordinate together.

IMO,I suggest merging the old PR first instead of closing it, and then trying to resolve any potential conflicts in the current PR. This can also implement the proposal in #1104 .

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants