-
Notifications
You must be signed in to change notification settings - Fork 3
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
Closes #2460: Compatibility with libre office files #2472
Merged
diasf
merged 6 commits into
develop
from
fdias-2460-xslx-reader-compatibility-with-libre-office
May 16, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0dbddf5
Closes #2460: Make xslx reader compatible with files created by libre…
diasf 53d9c85
Merge branch 'develop' into fdias-2460-xslx-reader-compatibility-with…
diasf 350f572
more tests
diasf 130fc35
more tests
diasf 5f72620
Merge branch 'develop' into fdias-2460-xslx-reader-compatibility-with…
diasf 4208973
review comments
diasf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...ava/edu/harvard/iq/dataverse/ingest/tabulardata/impl/plugins/xlsx/XLSXFileReaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.xlsx; | ||
|
||
import edu.harvard.iq.dataverse.ingest.tabulardata.TabularDataIngest; | ||
import edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.csv.CSVFileReaderTest; | ||
import edu.harvard.iq.dataverse.persistence.datafile.datavariable.DataVariable; | ||
import io.vavr.Tuple; | ||
import org.junit.jupiter.api.Assumptions; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class XLSXFileReaderTest { | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { "xslx/table-google.xlsx", "xslx/table-libre.xlsx", "xslx/table-excel.xlsx" }) | ||
void read__various_sources(String xlsxFile) throws Exception { | ||
// when | ||
TabularDataIngest result = read(xlsxFile); | ||
|
||
// then | ||
assertThat(result.getDataTable().getVarQuantity()).isEqualTo(5); | ||
assertThat(result.getDataTable().getDataVariables().stream().map(DataVariable::getName).collect(Collectors.toList())) | ||
.containsExactly( | ||
"Id", "Item", "cost", "count", "total"); | ||
assertThat(Files.readAllLines(result.getTabDelimitedFile().toPath())) | ||
.containsExactly( | ||
"1.0\t\"Banana\"\t2.3\t4.0\t9.2", | ||
"2.0\t\"Choco\"\t8.49\t2.0\t16.98", | ||
"3.0\t\"Headset\"\t248.99\t1.0\t248.99"); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"xslx/missing-columns-libre.xlsx,false", // disabled, because unsupported by the current implementation | ||
"xslx/missing-columns-excel.xlsx,true" }) | ||
void read__missing_columns(String xlsxFile, boolean enabled) throws Exception { | ||
Assumptions.assumeTrue(enabled, "Test file " + xlsxFile + " is disabled."); | ||
|
||
// when | ||
TabularDataIngest result = read(xlsxFile); | ||
|
||
// then | ||
assertThat(result.getDataTable().getVarQuantity()).isEqualTo(8); | ||
assertThat(result.getDataTable().getDataVariables().stream().map(DataVariable::getName).collect(Collectors.toList())) | ||
.containsExactly("A", "Col1", "Col2", "D", "Col4", "Col5", "G", "Col7"); | ||
assertThat(Files.readAllLines(result.getTabDelimitedFile().toPath())) | ||
.containsExactly( | ||
"\"Row1\"\t1.1\t1.2\t1.3\t1.4\t1.5\t1.6\t1.7", | ||
"\"Row2\"\t2.1\t2.2\t2.3\t2.4\t2.5\t2.6\t2.7", | ||
"\"Row3\"\t3.1\t3.2\t3.3\t3.4\t3.5\t3.6\t3.7", | ||
"\"\"\t4.1\t4.2\t4.3\t4.4\t4.5\t4.6\t4.7", | ||
"\"Row5\"\t5.1\t5.2\t5.3\t5.4\t6.5\t5.6\t5.7"); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ "xslx/value-types-libre.xlsx", "xslx/value-types-excel.xlsx" }) | ||
void read__value_types(String xlsxFile) throws Exception { | ||
// when | ||
TabularDataIngest result = read(xlsxFile); | ||
|
||
// then | ||
assertThat(result.getDataTable().getVarQuantity()).isEqualTo(4); | ||
assertThat(result.getDataTable().getDataVariables().stream().map(DataVariable::getName).collect(Collectors.toList())) | ||
.containsExactly("A", "B", "Total", "Div"); | ||
assertThat(result.getDataTable().getDataVariables().stream().map(DataVariable::getType).collect(Collectors.toList())) | ||
.containsExactly( | ||
DataVariable.VariableType.CHARACTER, | ||
DataVariable.VariableType.NUMERIC, | ||
DataVariable.VariableType.CHARACTER, | ||
DataVariable.VariableType.CHARACTER); | ||
assertThat(Files.readAllLines(result.getTabDelimitedFile().toPath())) | ||
.containsExactly( | ||
"\"1\"\t1.0\t\"1\"\t\"1\"", | ||
"\"2\"\t4.0\t\"8\"\t\"0.5\"", | ||
"\"A\"\t4.0\t\"#VALUE!\"\t\"#VALUE!\"", | ||
"\"1\"\t0.0\t\"0\"\t\"#DIV/0!\""); | ||
} | ||
|
||
private TabularDataIngest read(String xlsxFile) throws IOException { | ||
try { | ||
File file = Paths.get(CSVFileReaderTest.class.getClassLoader().getResource(xlsxFile).toURI()).toFile(); | ||
TabularDataIngest result; | ||
try (BufferedInputStream is = new BufferedInputStream(Files.newInputStream(file.toPath()))) { | ||
XLSXFileReader reader = new XLSXFileReader(new XLSXFileReaderSpi()); | ||
result = reader.read(Tuple.of(is, file), null); | ||
} | ||
return result; | ||
} catch (URISyntaxException use) { | ||
throw new RuntimeException(use); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a change request.
We could have also write it in a little shorter way:
`assertThat(result.getDataTable().getDataVariables()).extracting(DataVariable::getName)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, that's much better. Changed it.