Skip to content
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

[DATAFLOW-139] Incorrect DSG url lead to NPE #13

Merged
merged 2 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public RowToCsv(String csvDelimiter) {
}

public String getCsvFromRow(Row row) {
return row.getValues().stream().map(Object::toString).collect(Collectors.joining(csvDelimiter));
return row.getValues().stream()
.map(item -> item == null ? "null" : item)
.map(Object::toString)
.collect(Collectors.joining(csvDelimiter));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ public void testRowToCSV() {
Assert.assertEquals(String.join(";", fields), csvResult);
}

@Test
public void testRowToCSVWithNull() {
final String nullableTestSchema =
"{\"fields\":[{\"mode\":\"REQUIRED\",\"name\":\"FieldName1\",\"type\":\"STRING\"},{\"mode\":\"NULLABLE\",\"name\":\"FieldName2\",\"type\":\"STRING\"}]}";
final String expectedCsv = "TestValueOne;null";

List<Object> values = Lists.newArrayList("TestValueOne", null);

Schema beamSchema = new SchemasUtils(nullableTestSchema).getBeamSchema();
Row.Builder rowBuilder = Row.withSchema(beamSchema);
Row row = rowBuilder.addValues(values).build();
String csvResult = new RowToCsv(";").getCsvFromRow(row);
Assert.assertEquals(expectedCsv, csvResult);
}

@Test
public void testFileSystemIOReadCSV() throws IOException {
PCollection<String> jsons = fileSystemIORead(CSV_FILE_PATH, FORMAT.CSV);
Expand Down