-
Notifications
You must be signed in to change notification settings - Fork 971
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: treat empty strings as null values from csv imports (#1996)
* test: add integration test for empty string csv * Fix typo and make CSV schema fields nullable Signed-off-by: Florent Biville <florent.biville@neo4j.com> * chore: clean up unnecessary checks and tests * chore: fix style * test: add unit test for CsvSources * test: improvement on CsvSources test * chore: fix style * fix: add yaml support for specification parser * Revert "fix: add yaml support for specification parser" This reverts commit 03ff0ef. --------- Signed-off-by: Florent Biville <florent.biville@neo4j.com>
- Loading branch information
Showing
6 changed files
with
154 additions
and
11 deletions.
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
72 changes: 72 additions & 0 deletions
72
...-neo4j/src/test/java/com/google/cloud/teleport/v2/neo4j/model/helpers/CsvSourcesTest.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,72 @@ | ||
/* | ||
* Copyright (C) 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.google.cloud.teleport.v2.neo4j.model.helpers; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import com.google.cloud.teleport.v2.neo4j.model.sources.TextFormat; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.apache.commons.csv.CSVFormat; | ||
import org.apache.commons.csv.CSVParser; | ||
import org.apache.commons.csv.CSVRecord; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
@RunWith(Parameterized.class) | ||
public class CsvSourcesTest { | ||
|
||
@Parameterized.Parameter(0) | ||
public TextFormat textFormat; | ||
|
||
@Parameterized.Parameter(1) | ||
public char delimiter; | ||
|
||
@Parameterized.Parameters(name = "{0}") | ||
public static List<Object[]> testParameters() { | ||
return Arrays.asList( | ||
new Object[][] { | ||
{TextFormat.EXCEL, ','}, | ||
{TextFormat.INFORMIX, ','}, | ||
{TextFormat.MONGO, ','}, | ||
{TextFormat.MONGO_TSV, '\t'}, | ||
{TextFormat.MYSQL, '\t'}, | ||
{TextFormat.ORACLE, ','}, | ||
{TextFormat.POSTGRES, '\t'}, | ||
{TextFormat.POSTGRESQL_CSV, ','}, | ||
{TextFormat.RFC4180, ','}, | ||
{TextFormat.DEFAULT, ','} | ||
}); | ||
} | ||
|
||
@Test | ||
public void shouldParseEmptyColumnsAsNullValues() throws IOException { | ||
String line = "1" + delimiter; | ||
CSVFormat csvFormat = CsvSources.toCsvFormat(textFormat); | ||
|
||
try (CSVParser csvParser = CSVParser.parse(line, csvFormat)) { | ||
List<CSVRecord> csvRecords = csvParser.getRecords(); | ||
assertThat(csvRecords).hasSize(1); | ||
|
||
CSVRecord csvRecord = csvRecords.get(0); | ||
assertThat(csvRecord).hasSize(2); | ||
assertThat(csvRecord.get(0)).isEqualTo("1"); | ||
assertThat(csvRecord.get(1)).isEqualTo(null); | ||
} | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
...lecloud-to-neo4j/src/test/resources/testing-specs/data-conversion/empty-strings-spec.json
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,28 @@ | ||
{ | ||
"source": { | ||
"type": "text", | ||
"name": "data", | ||
"ordered_field_names": "int64,datetime", | ||
"uri": "$externalcsvuri" | ||
}, | ||
"targets": [ | ||
{ | ||
"node": { | ||
"name": "Node", | ||
"source": "data", | ||
"mode": "append", | ||
"mappings": { | ||
"label": "\"Node\"", | ||
"properties": { | ||
"keys": [ | ||
"int64" | ||
], | ||
"dates": [ | ||
"datetime" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
v2/googlecloud-to-neo4j/src/test/resources/testing-specs/data-conversion/empty-strings.csv
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 @@ | ||
1, |