-
Notifications
You must be signed in to change notification settings - Fork 510
feat: add support for column-based reading of CSV files #982
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
base: main
Are you sure you want to change the base?
Changes from all commits
ab2343a
069413c
9861270
d71205b
8ce06d7
bd15fe6
a189d68
076f3ae
407d0a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,11 +23,13 @@ | |
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
| import java.lang.reflect.Method; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.commons.io.FileUtils; | ||
| import org.apache.fesod.sheet.read.builder.ExcelReaderBuilder; | ||
| import org.apache.fesod.sheet.read.builder.ExcelReaderSheetBuilder; | ||
| import org.apache.fesod.sheet.read.listener.ReadListener; | ||
|
|
@@ -253,6 +255,30 @@ void testReadSheet_withAllParams_shouldReturnBuilder() { | |
| Assertions.assertNotNull(builder); | ||
| } | ||
|
|
||
| @Test | ||
| void testReadCsv_withColumnIndexes_shouldFilterColumns() throws Exception { | ||
|
|
||
| String csvContent = "ID,Name,Age,Gender\n2,Bob,25,Male"; | ||
| File csvFile = tempDir.resolve("test_columns.csv").toFile(); | ||
| FileUtils.writeStringToFile(csvFile, csvContent, StandardCharsets.UTF_8); | ||
|
|
||
| List<Integer> targetColumns = Arrays.asList(0, 2); | ||
|
|
||
| List<Map<Integer, String>> readResults = FesodSheet.read(csvFile) | ||
| .csv() | ||
| .includeColumnIndexes(targetColumns) | ||
| .doReadSync(); | ||
|
sapienza88 marked this conversation as resolved.
Comment on lines
+267
to
+270
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Method call chain error.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you point out the test example?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Please confirm that the unit tests pass locally before submitting.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bengbengbalabalabeng the test now passes locally, pls check again and merge this if all is ok. |
||
|
|
||
| Assertions.assertNotNull(readResults); | ||
| Assertions.assertEquals(1, readResults.size()); | ||
|
|
||
| Map<Integer, String> row1 = readResults.get(0); | ||
| Assertions.assertEquals( | ||
| 2, row1.size(), "Should only contain the 1 filtered columns (excepting the head by default)"); | ||
| Assertions.assertEquals("2", row1.get(0)); | ||
| Assertions.assertEquals("25", row1.get(1)); | ||
| } | ||
|
|
||
| @Test | ||
| void testReadSheet_withColumnIndexes_shouldConfigureAll() { | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.