Skip to content

Commit 7de49a3

Browse files
Read from InputStreams with BOM + tests
1 parent ff710ca commit 7de49a3

File tree

6 files changed

+16
-33
lines changed

6 files changed

+16
-33
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>io.frictionlessdata</groupId>
55
<artifactId>tableschema-java</artifactId>
6-
<version>0.6.12-SNAPSHOT</version>
6+
<version>0.6.13-SNAPSHOT</version>
77
<packaging>jar</packaging>
88
<issueManagement>
99
<url>https://github.com/frictionlessdata/tableschema-java/issues</url>

src/main/java/io/frictionlessdata/tableschema/Table.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ public static Table fromSource(URL dataSource, Schema schema, CSVFormat format)
232232
public BeanIterator<?> iterator(Class<?> beanType, boolean relations){
233233
return new BeanIterator(this, beanType, relations);
234234
}
235+
235236
/**
236-
* This is the simplest case to read data from a Table referencing a file or URL.
237+
* This is the simplest case to read Object data from a Table referencing a file or URL.
237238
*
238239
* If a Schema is set on a table, each row will be returned as an Object array. Values in each column
239240
* are parsed and converted ("cast") to Java objects based on the Field definitions of the Schema. If no Schema is

src/main/java/io/frictionlessdata/tableschema/tabledatasource/JsonArrayTableDataSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public boolean hasReliableHeaders() {
5050
public Iterator<String[]> iterator() {
5151
String[] headers = getHeaders();
5252

53-
return Iterators.transform(((ArrayNode)dataSource).iterator(), (JsonNode input) -> {
53+
return Iterators.transform(dataSource.iterator(), (JsonNode input) -> {
5454
List<String> values = new ArrayList<>();
5555
for (String header : headers) {
5656
JsonNode val = input.get(header);

src/test/java/io/frictionlessdata/tableschema/iterator/TableBeanIteratorTest.java

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import static io.frictionlessdata.tableschema.TestHelper.getTestDataDirectory;
2929

3030
class TableBeanIteratorTest {
31-
private static Schema employeeSchema = null;
32-
private static Schema employeeSchemaAlternateDateForma = null;
3331
private static Schema gdpSchema = null;
3432
private static Table employeeTable = null;
3533
private static Table employeeTableAlternateDateFormat = null;
@@ -39,35 +37,17 @@ class TableBeanIteratorTest {
3937
@BeforeEach
4038
void setUp() throws Exception {
4139
testDataDir = getTestDataDirectory();
42-
File f = new File(getTestDataDirectory(), "schema/population_schema.json");
43-
Schema validPopulationSchema = null;
44-
try (FileInputStream fis = new FileInputStream(f)) {
45-
validPopulationSchema = Schema.fromJson (fis, false);
46-
}
47-
48-
49-
File file = new File("data/employee_data.csv");
50-
employeeSchema = BeanSchema.infer(EmployeeBean.class);
51-
employeeTable = Table.fromSource(file, testDataDir, employeeSchema, TableDataSource.getDefaultCsvFormat());
52-
53-
file = new File("data/employee_alternate_date_format.csv");
54-
employeeSchemaAlternateDateForma = BeanSchema.infer(EmployeeBeanWithAnnotation.class);
55-
employeeTableAlternateDateFormat = Table.fromSource(
56-
file,
57-
testDataDir,
58-
employeeSchemaAlternateDateForma,
59-
TableDataSource.getDefaultCsvFormat());
60-
61-
file = new File("data/gdp.csv");
62-
gdpSchema = BeanSchema.infer(GrossDomesticProductBean.class);
63-
gdpTable = Table.fromSource(file, testDataDir, gdpSchema, TableDataSource.getDefaultCsvFormat());
6440

6541
}
6642

6743

6844
@Test
6945
@DisplayName("Test deserialization of EmployeeBean")
7046
void testBeanDeserialization() throws Exception {
47+
48+
File file = new File("data/employee_data.csv");
49+
employeeTable = Table.fromSource(file, testDataDir, null, TableDataSource.getDefaultCsvFormat());
50+
7151
List<EmployeeBean> employees = new ArrayList<>();
7252
BeanIterator<EmployeeBean> bit = new BeanIterator<>(employeeTable, EmployeeBean.class, false);
7353
while (bit.hasNext()) {
@@ -91,11 +71,10 @@ void testBeanDeserialization() throws Exception {
9171
@DisplayName("Test deserialization of EmployeeBean with Annotation")
9272
void testBeanDeserialization2() throws Exception {
9373
File inFile = new File("data/employee_full.csv");
94-
employeeSchemaAlternateDateForma = BeanSchema.infer(EmployeeBeanWithAnnotation.class);
95-
employeeTableAlternateDateFormat = Table.fromSource(
74+
Table employeeTableAlternateDateFormat = Table.fromSource(
9675
inFile,
9776
testDataDir,
98-
employeeSchemaAlternateDateForma,
77+
null,
9978
TableDataSource.getDefaultCsvFormat());
10079
List<EmployeeBeanWithAnnotation> employees = new ArrayList<>();
10180
BeanIterator<EmployeeBeanWithAnnotation> bit = new BeanIterator<>(employeeTableAlternateDateFormat, EmployeeBeanWithAnnotation.class, false);
@@ -119,11 +98,14 @@ void testBeanDeserialization2() throws Exception {
11998
/*Assertions.assertEquals(45, info.get("pin"));
12099
Assertions.assertEquals(83.23, info.get("rate"));
121100
Assertions.assertEquals(90, info.get("ssn"));*/
101+
System.out.println(info);
122102
}
123103

124104
@Test
125105
@DisplayName("Test deserialization of big floats (GrossDomesticProductBean)")
126106
void testBeanDeserialization3() throws Exception {
107+
File file = new File("data/gdp.csv");
108+
gdpTable = Table.fromSource(file, testDataDir, null, TableDataSource.getDefaultCsvFormat());
127109
List<GrossDomesticProductBean> records = new ArrayList<>();
128110
BeanIterator<GrossDomesticProductBean> bit
129111
= new BeanIterator<>(gdpTable, GrossDomesticProductBean.class, false);

src/test/java/io/frictionlessdata/tableschema/schema/SchemaTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,8 @@ public void test2Issue20() throws Exception {
577577
Assertions.assertTrue(newSchema.isValid());
578578
}
579579

580-
580+
// Test for https://github.com/frictionlessdata/tableschema-java/issues/14
581+
// "schema_valid_full.json" from the Python version is named "employee_full_schema.json" here
581582
@Test
582583
public void testIssue14() throws Exception {
583584
Schema schema = Schema.fromJson(new File(getTestDataDirectory()

src/test/java/io/frictionlessdata/tableschema/tabledatasource/BeanTableDataSourceTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ void testBeanTableCreation() throws Exception {
6161
private static Collection<EmployeeBeanWithAnnotation> getEmployees() throws Exception {
6262
File testDataDir = getTestDataDirectory();
6363
File inFile = new File("data/employee_full.csv");
64-
Schema schema = BeanSchema.infer(EmployeeBeanWithAnnotation.class);
6564
Table inTable = Table.fromSource(
6665
inFile,
6766
testDataDir,
68-
schema,
67+
null,
6968
TableDataSource.getDefaultCsvFormat());
7069

7170
List<EmployeeBeanWithAnnotation> employees = new ArrayList<>();

0 commit comments

Comments
 (0)