use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldImportSplitInputFiles.
@Test
void shouldImportSplitInputFiles() throws Exception {
// GIVEN
List<String> nodeIds = nodeIds();
Configuration config = Configuration.COMMAS;
Path dbConfig = prepareDefaultConfigFile();
// WHEN
runImport("--additional-config", dbConfig.toAbsolutePath().toString(), // One group with one header file and one data file
"--nodes", nodeHeader(config).toAbsolutePath().toString() + "," + nodeData(false, config, nodeIds, lines(0, NODE_COUNT / 2)).toAbsolutePath().toString(), // One group with two data files, where the header sits in the first file
"--nodes", nodeData(true, config, nodeIds, lines(NODE_COUNT / 2, NODE_COUNT * 3 / 4)).toAbsolutePath().toString() + "," + nodeData(false, config, nodeIds, lines(NODE_COUNT * 3 / 4, NODE_COUNT)).toAbsolutePath().toString(), "--relationships", relationshipHeader(config).toAbsolutePath().toString() + "," + relationshipData(false, config, nodeIds, TRUE, true).toAbsolutePath().toString());
// THEN
verifyData();
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldNotImportOnEmptyExistingDatabase.
@Test
void shouldNotImportOnEmptyExistingDatabase() throws Exception {
// Given a db with default token indexes
createDefaultDatabaseWithTokenIndexes();
List<String> nodeIds = nodeIds();
Configuration config = COMMAS;
Path dbConfig = defaultConfig();
// When csv is imported
assertThatThrownBy(() -> runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes", nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString(), "--high-io", "false", "--relationships", relationshipData(true, config, nodeIds, TRUE, true).toAbsolutePath().toString())).hasCauseInstanceOf(DirectoryNotEmptyException.class);
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldFailIfHeaderHasLessColumnsThanData.
@Test
void shouldFailIfHeaderHasLessColumnsThanData() throws Exception {
// GIVEN
List<String> nodeIds = nodeIds();
Configuration config = Configuration.TABS;
// WHEN data file contains more columns than header file
int extraColumns = 3;
var e = assertThrows(InputException.class, () -> runImport("--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()));
assertTrue(suppressOutput.getOutputVoice().containsMessage("IMPORT FAILED"));
assertFalse(suppressOutput.getErrorVoice().containsMessage(e.getClass().getName()));
assertTrue(e.getMessage().contains("Extra column not present in header on line"));
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method failOnInvalidDatabaseName.
@Test
void failOnInvalidDatabaseName() throws Exception {
List<String> nodeIds = nodeIds();
Configuration config = Configuration.COMMAS;
Path dbConfig = prepareDefaultConfigFile();
var e = assertThrows(Exception.class, () -> runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes", nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString(), "--database", "__incorrect_db__"));
assertThat(e).hasMessageContaining("Invalid database name '__incorrect_db__'.");
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldLogRelationshipsReferringToMissingNode.
@Test
void shouldLogRelationshipsReferringToMissingNode() 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 bad = badFile();
Path dbConfig = prepareDefaultConfigFile();
// WHEN importing data where some relationships refer to missing nodes
runImport("--nodes", nodeData.toAbsolutePath().toString(), "--report-file", bad.toAbsolutePath().toString(), "--skip-bad-relationships", "--bad-tolerance", "2", "--additional-config", dbConfig.toAbsolutePath().toString(), "--relationships", relationshipData1.toAbsolutePath().toString() + "," + relationshipData2.toAbsolutePath().toString());
// THEN
String badContents = Files.readString(bad, Charset.defaultCharset());
assertTrue(badContents.contains("bogus"), "Didn't contain first bad relationship");
assertTrue(badContents.contains("missing"), "Didn't contain second bad relationship");
verifyRelationships(relationships);
}
Aggregations