Skip to content

feat: add support for column index limit in ReadSheet#942

Open
sapienza88 wants to merge 18 commits into
apache:mainfrom
sapienza88:column_support
Open

feat: add support for column index limit in ReadSheet#942
sapienza88 wants to merge 18 commits into
apache:mainfrom
sapienza88:column_support

Conversation

@sapienza88

@sapienza88 sapienza88 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Purpose of the pull request

Related: #950

What's changed?

  • Added support for column-based reading.
  • Currently xlsx only; xls support will be added later.

Column filtering behavior: CellTagHandler#endElement

When includeColumnIndexes != null:

  • Only process target columns
  • Rewrite target columns’ internal indexes to consecutive (0-based)

When includeColumnIndexes == null:

  • Keep the original behavior

API Usage Example

// data
┌────────────┬─────────────┬────────────┬─────────────┐
│     NONameAgePassword  │
├────────────┼─────────────┼────────────┼─────────────┤
│     1Jackson22123456   │
└────────────┴─────────────┴────────────┴─────────────┘

List<Map<Integer, String>> results = FesodSheet.read(pathname)
		.sheet()
		.includeColumnIndexes(Arrays.asList(1, 3))
		.doReadSync();

Map<Integer, String> data = results.get(0);

assertEquals(2, data.size());
assertEquals("Jackson", data.get(0));
assertEquals("123456", data.get(1));

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.

@delei

delei commented Jul 5, 2026

Copy link
Copy Markdown
Member

Welcome to participate in open source contributions.

Please refer to the contribution guide, complete your PR content and modify the commit message format, and provide the unit test code.

@delei delei added the PR: first-time contributor first-time contributor label Jul 5, 2026
@bengbengbalabalabeng

Copy link
Copy Markdown
Contributor

Please refer to the code contribution. Make sure the changes can be compiled and are properly formatted :)

@sapienza88

Copy link
Copy Markdown
Contributor Author

Please refer to the code contribution. Make sure the changes can be compiled and are properly formatted :)

No I cannot make sure it compiles on CI, maybe locally but not on CI

@bengbengbalabalabeng

Copy link
Copy Markdown
Contributor

No I cannot make sure it compiles on CI, maybe locally but not on CI

To prevent CI from being blocked by formatting or compilation issues, you can first run mvn clean install -DskipTests and mvn spotless:apply locally to ensure that both the build and formatting pass.

Please refer to the code contribution.

@delei

delei commented Jul 5, 2026

Copy link
Copy Markdown
Member

No I cannot make sure it compiles on CI, maybe locally but not on CI

Hi, may I ask if this is a draft PR?

I haven't seen any complete implementation logic for this new parameter, and there are no use cases of reading Excel files in the unit test code either.

@sapienza88

sapienza88 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

No I cannot make sure it compiles on CI, maybe locally but not on CI

Hi, may I ask if this is a draft PR?

I haven't seen any complete implementation logic for this new parameter, and there are no use cases of reading Excel files in the unit test code either.

not a draft PR, i will extend it to add a complete implementation logic for the new parameter, as well as a test based on reading dummy data.

But also it depends what do you mean by "complete implementation logic"?

@delei

delei commented Jul 5, 2026

Copy link
Copy Markdown
Member

not a draft PR, i will extend it to add a complete implementation logic for the new parameter, as well as a test based on reading dummy data.

It's okay. Please continue to develop and refine this PR, and conduct unit tests in the local environment. When a PR is ready for code review by community members, you can leave a message to let us know.

@delei delei added the PR: developing This feature will be added in future releases label Jul 5, 2026
@sapienza88

sapienza88 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@delei @bengbengbalabalabeng my understanding is that fesod does not support reading a sheet by column (only by rows) but it can write to a square set of cells, is that correct? where this logic of the this PR should also be propagated? which classes are also concerned with reading with a column index?
PS: I added some tests here.

@delei

delei commented Jul 9, 2026

Copy link
Copy Markdown
Member

my understanding is that fesod does not support reading a sheet by column (only by rows) but it can write to a square set of cells, is that correct? where this logic of the this PR should also be propagated? which classes are also concerned with reading with a column index? PS: I added some tests here.

Reading and converting the data in cells is achieved through the ReadListener interface. Please refer to this method to see if it provides any inspiration or assistance to you.

BTW, I'm a little worried about this PR. Could you please start the preliminary discussion in the issue and provide your proposed solution? (e.g. #941 )

I didn't mean any offense, the other members of the community generally do not discuss proposals in the PR. This would help save the time for the code review.

@sapienza88

sapienza88 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

my understanding is that fesod does not support reading a sheet by column (only by rows) but it can write to a square set of cells, is that correct? where this logic of the this PR should also be propagated? which classes are also concerned with reading with a column index? PS: I added some tests here.

Reading and converting the data in cells is achieved through the ReadListener interface. Please refer to this method to see if it provides any inspiration or assistance to you.

BTW, I'm a little worried about this PR. Could you please start the preliminary discussion in the issue and provide your proposed solution? (e.g. #941 )

I didn't mean any offense, the other members of the community generally do not discuss proposals in the PR. This would help save the time for the code review.

@delei I meant not "in n cells" but in rows AND columns. And not a listnener function. That was a severe limitation of fesod thankfully this PR comes to the rescue, the idea is clear and simple (read a sheet by rows and columns) i think there is no need to describe it more

@sapienza88

Copy link
Copy Markdown
Contributor Author

@delei can you review the pr?

@delei

delei commented Jul 9, 2026

Copy link
Copy Markdown
Member

can you review the pr?

Please fix the errors identified in the CI and ensure that the CI can pass successfully.

Assertions.assertNotNull(readResults);
Map<Integer, String> parsedRow = readResults.get(0);
Assertions.assertEquals("1", parsedRow.get(0));
Assertions.assertEquals("Alice", parsedRow.get(1));

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.

List<Integer> targetColumns = Arrays.asList(0, 2);

The targetColumns variable has been set to only include columns 0 and 2, why are there three columns of data in the result?

Is there any misunderstanding or unfinished code logic?

@sapienza88 sapienza88 Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will correct, i wrongly thought that it is from to

@delei delei Jul 9, 2026

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.

I would like to know what features you have implemented through this PR.

Is it the case that the readResults variable only contains data from these two columns?

Assertions.assertEquals(2,parsedRow.size());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes thats correct

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@delei fixed now

@sapienza88 sapienza88 Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@delei fixed!

@delei delei Jul 12, 2026

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.

Can we continue to develop it so that it can support xls files at the same time?

@sapienza88 sapienza88 Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@delei I will do that in a separate PR, pls merge this xlsx work first

@delei delei Jul 12, 2026

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.

Thank you for your willingness to continue contributing to open source.

IMO, due to the introduction of new parameters, I hope this is a complete PR that includes all the features, making it easier for community members to understand this parameter.

You can also continue to submit new PR to add documentation for this parameter, optimize the code, or fix minor errors.

@sapienza88 sapienza88 Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@delei sure I will add docs as well for this (in a separate PR), thanks

@delei delei changed the title Add support for column index limit in ReadSheet feat: add support for column index limit in ReadSheet Jul 12, 2026
@sapienza88

sapienza88 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@delei are we done here? can you merge this (with the associated docs: #949)

delei
delei previously approved these changes Jul 15, 2026

@delei delei 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.

BTW, currently, only xlsx files are supported.

@delei delei removed the PR: developing This feature will be added in future releases label Jul 15, 2026
@sapienza88

sapienza88 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

LGTM.

BTW, currently, only xlsx files are supported.

@delei yes

Comment thread fesod-sheet/src/main/java/org/apache/fesod/sheet/FesodSheet.java
@sapienza88

Copy link
Copy Markdown
Contributor Author

@bengbengbalabalabeng all your reviews have been addressed by now


tempCellData.checkEmpty();
tempCellData.setRowIndex(xlsxReadSheetHolder.getRowIndex());
tempCellData.setColumnIndex(xlsxReadSheetHolder.getColumnIndex());

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.

Considering the earlier logic, assigning tempCellData.setColumnIndex(targetColumnIndex) here might make the behavior more consistent. What do you think :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

targetColumnIndex is assigned in an if clause, so it would not make sense to assign here for all cases.

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.

Considering the earlier logic, assigning tempCellData.setColumnIndex(targetColumnIndex) here might make the behavior more consistent.

Sorry for the confusion, my previous comment might not have been clear enough. Here is what I actually meant:

// ...

if (includeColumnIndexes == null) {
    targetColumnIndex = xlsxReadSheetHolder.getColumnIndex();
} else {
	// If it's a target column, rewrite the cell's internal index and pack it sequentially
    targetColumnIndex = includeColumnIndexes.indexOf(xlsxReadSheetHolder.getColumnIndex());
    if (targetColumnIndex < 0) {
        return;
    }
}

// ...
// line: 136 (old 154) 
tempCellData.setColumnIndex(targetColumnIndex);

Since we guarantee targetColumnIndex is resolved in both branches, placing setColumnIndex() outside the block maintains the exact same logic while avoiding code duplication. What do you think :)

@sapienza88 sapienza88 Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, that is correct and more readable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bengbengbalabalabeng the refactoring has been implemented now, you can merge this PR as well as this related passing test: #945

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.

In the previous version, when includeColumnIndexes != null, the assignment of tempCellData.setColumnIndex() was the overridden targetColumnIndex. Now, however, tempCellData.setColumnIndex() always uses the original xlsxReadSheetHolder.getColumnIndex() instead.

I want to confirm whether this change is intentional. Would you mind clarifying the expected behavior here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I must have overlooked this, now it is changed as it was in the previous correct version.

@bengbengbalabalabeng

Copy link
Copy Markdown
Contributor

Hi @sapienza88,

Please help confirm whether the updated PR description accurately reflects the changes.

@sapienza88

Copy link
Copy Markdown
Contributor Author

Hi @sapienza88,

Please help confirm whether the updated PR description accurately reflects the changes.

@bengbengbalabalabeng it absolutely does, thank you for adding it

@bengbengbalabalabeng bengbengbalabalabeng 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.

LGTM.

Merge in 24h.

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

Labels

PR: first-time contributor first-time contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants