use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldNotIncludeEmptyArraysInEntities.
@Test
public void shouldNotIncludeEmptyArraysInEntities() throws Exception {
// GIVEN
Iterable<DataFactory<InputNode>> data = DataFactories.nodeData(CsvInputTest.<InputNode>data(":ID,sprop:String[],lprop:long[]\n" + "1,,\n" + "2,a;b,10;20"));
Input input = new CsvInput(data, defaultFormatNodeFileHeader(), null, null, IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN/THEN
try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
assertNode(nodes.next(), 1L, NO_PROPERTIES, labels());
assertNode(nodes.next(), 2L, properties("sprop", new String[] { "a", "b" }, "lprop", new long[] { 10, 20 }), labels());
assertFalse(nodes.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputBatchImportIT method shouldImportDataComingFromCsvFiles.
@Test
public void shouldImportDataComingFromCsvFiles() throws Exception {
// GIVEN
BatchImporter importer = new ParallelBatchImporter(directory.graphDbDir(), fileSystemRule.get(), smallBatchSizeConfig(), NullLogService.getInstance(), invisible(), Config.empty());
List<InputNode> nodeData = randomNodeData();
List<InputRelationship> relationshipData = randomRelationshipData(nodeData);
// WHEN
boolean success = false;
try {
importer.doImport(csv(nodeDataAsFile(nodeData), relationshipDataAsFile(relationshipData), IdType.STRING, lowBufferSize(COMMAS), silentBadCollector(0), getRuntime().availableProcessors()));
// THEN
verifyImportedData(nodeData, relationshipData);
success = true;
} finally {
if (!success) {
System.err.println("Seed " + seed);
}
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldAllowNodesToBeAnonymousEvenIfIdHeaderIsNamed.
@Test
public void shouldAllowNodesToBeAnonymousEvenIfIdHeaderIsNamed() throws Exception {
// GIVEN
DataFactory<InputNode> data = data("id:ID,name:string,level:int\n" + "abc,Mattias,1\n" + // this node is anonymous
",Johan,2\n");
Iterable<DataFactory<InputNode>> dataIterable = dataIterable(data);
Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), null, null, IdType.STRING, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (ResourceIterator<InputNode> nodes = input.nodes().iterator()) {
// THEN
assertNode(nodes.next(), "abc", new Object[] { "id", "abc", "name", "Mattias", "level", 1 }, labels());
assertNode(nodes.next(), null, new Object[] { "name", "Johan", "level", 2 }, labels());
assertFalse(nodes.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldPropagateExceptionFromFailingDecorator.
@Test
public void shouldPropagateExceptionFromFailingDecorator() throws Exception {
// GIVEN
RuntimeException failure = new RuntimeException("FAILURE");
Iterable<DataFactory<InputNode>> data = DataFactories.nodeData(CsvInputTest.<InputNode>data(":ID,name\n1,Mattias", new FailingNodeDecorator(failure)));
Input input = new CsvInput(data, defaultFormatNodeFileHeader(), null, null, IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
nodes.next();
} catch (RuntimeException e) {
// THEN
assertTrue(e == failure);
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class DataFactoriesTest method shouldParseHeaderFromFirstLineOfFirstInputFile.
@Test
public void shouldParseHeaderFromFirstLineOfFirstInputFile() throws Exception {
// GIVEN
final Reader firstSource = new StringReader("id:ID\tname:String\tbirth_date:long");
final Reader secondSource = new StringReader("0\tThe node\t123456789");
DataFactory<InputNode> dataFactory = data(value -> value, () -> {
try {
return sources(firstSource, secondSource);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
Header.Factory headerFactory = defaultFormatNodeFileHeader();
Extractors extractors = new Extractors(';');
// WHEN
CharSeeker seeker = CharSeekers.charSeeker(dataFactory.create(TABS).stream(), TABS, false);
Header header = headerFactory.create(seeker, TABS, IdType.ACTUAL);
// THEN
assertArrayEquals(array(entry("id", Type.ID, extractors.long_()), entry("name", Type.PROPERTY, extractors.string()), entry("birth_date", Type.PROPERTY, extractors.long_())), header.entries());
seeker.close();
}
Aggregations