use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method skipLoggingOfBadEntries.
@Test
void skipLoggingOfBadEntries() throws Exception {
// GIVEN
List<String> nodeIds = asList("a", "b", "c");
Configuration config = Configuration.COMMAS;
Path nodeData = nodeData(true, config, nodeIds, TRUE);
List<RelationshipDataLine> relationships = Arrays.asList(// line 2 of file1
relationship("a", "b", "TYPE", "aa"), // line 3 of file1
relationship("c", "bogus", "TYPE", "bb"), // line 1 of file2
relationship("b", "c", "KNOWS", "cc"), // line 2 of file2
relationship("c", "a", "KNOWS", "dd"), // line 3 of file2
relationship("missing", "a", "KNOWS", "ee"));
Path relationshipData1 = relationshipData(true, config, relationships.iterator(), lines(0, 2), true);
Path relationshipData2 = relationshipData(false, config, relationships.iterator(), lines(2, 5), true);
Path dbConfig = prepareDefaultConfigFile();
// WHEN importing data where some relationships refer to missing nodes
runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes", nodeData.toAbsolutePath().toString(), "--bad-tolerance", "2", "--skip-bad-entries-logging", "true", "--relationships", relationshipData1.toAbsolutePath().toString() + "," + relationshipData2.toAbsolutePath().toString());
assertFalse(Files.exists(badFile()));
verifyRelationships(relationships);
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldHandleAdditiveLabelsWithSpaces.
@Test
void shouldHandleAdditiveLabelsWithSpaces() throws Exception {
// GIVEN
List<String> nodeIds = nodeIds();
Configuration config = Configuration.COMMAS;
final Label label1 = label("My First Label");
final Label label2 = label("My Other Label");
Path dbConfig = prepareDefaultConfigFile();
// WHEN
runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes=My First Label:My Other Label=" + nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString(), "--relationships", relationshipData(true, config, nodeIds, TRUE, true).toAbsolutePath().toString());
// THEN
verifyData(node -> {
assertTrue(node.hasLabel(label1));
assertTrue(node.hasLabel(label2));
}, Validators.emptyValidator());
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldBeAbleToDisableSkippingOfBadRelationships.
@Test
void shouldBeAbleToDisableSkippingOfBadRelationships() throws Exception {
// GIVEN
List<String> nodeIds = asList("a", "b", "c");
Configuration config = Configuration.COMMAS;
Path nodeData = nodeData(true, config, nodeIds, TRUE);
List<RelationshipDataLine> relationships = Arrays.asList(// line 2 of file1
relationship("a", "b", "TYPE"), // line 3 of file1
relationship("c", "bogus", "TYPE"));
Path relationshipData1 = relationshipData(true, config, relationships.iterator(), lines(0, 2), true);
Path relationshipData2 = relationshipData(false, config, relationships.iterator(), lines(2, 5), true);
Path bad = badFile();
// WHEN importing data where some relationships refer to missing nodes
var e = assertThrows(Exception.class, () -> runImport("--nodes", nodeData.toAbsolutePath().toString(), "--report-file", bad.toAbsolutePath().toString(), "--skip-bad-relationships=false", "--relationships", relationshipData1.toAbsolutePath().toString() + "," + relationshipData2.toAbsolutePath().toString()));
assertExceptionContains(e, relationshipData1.toAbsolutePath().toString(), InputException.class);
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldDisallowImportWithoutNodesInput.
@Test
void shouldDisallowImportWithoutNodesInput() throws Exception {
// GIVEN
List<String> nodeIds = nodeIds();
Configuration config = Configuration.COMMAS;
// WHEN
var e = assertThrows(MissingParameterException.class, () -> runImport("--relationships", relationshipData(true, config, nodeIds, TRUE, true).toAbsolutePath().toString()));
assertThat(e).hasMessageContaining("Missing required option: '--nodes");
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldWarnIfHeaderHasLessColumnsThanDataWhenToldTo.
@Test
void shouldWarnIfHeaderHasLessColumnsThanDataWhenToldTo() throws Exception {
// GIVEN
List<String> nodeIds = nodeIds();
Configuration config = Configuration.TABS;
Path bad = badFile();
// WHEN data file contains more columns than header file
int extraColumns = 3;
runImport("--report-file", bad.toAbsolutePath().toString(), "--bad-tolerance", Integer.toString(nodeIds.size() * extraColumns), "--ignore-extra-columns", "--delimiter", "TAB", "--array-delimiter", String.valueOf(config.arrayDelimiter()), "--nodes=" + nodeHeader(config).toAbsolutePath().toString() + "," + nodeData(false, config, nodeIds, TRUE, Charset.defaultCharset(), extraColumns).toAbsolutePath().toString(), "--relationships", relationshipHeader(config).toAbsolutePath().toString() + "," + relationshipData(false, config, nodeIds, TRUE, true).toAbsolutePath().toString());
// THEN
String badContents = Files.readString(bad, Charset.defaultCharset());
assertTrue(badContents.contains("Extra column not present in header on line"));
}
Aggregations