use of org.neo4j.internal.batchimport.InputIterator in project neo4j by neo4j.
the class CsvInputTest method shouldIgnoreValuesAfterHeaderEntries.
@Test
public void shouldIgnoreValuesAfterHeaderEntries() throws Exception {
// GIVEN
Iterable<DataFactory> data = dataIterable(data("1,zergling,bubble,bobble\n" + "2,scv,pun,intended"));
Input input = new CsvInput(data, header(entry(null, Type.ID, extractors.long_()), entry("name", Type.PROPERTY, extractors.string())), datas(), defaultFormatRelationshipFileHeader(), ACTUAL, config(), NO_MONITOR, INSTANCE);
// WHEN
try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
// THEN
assertNextNode(nodes, 1L, new Object[] { "name", "zergling" }, labels());
assertNextNode(nodes, 2L, new Object[] { "name", "scv" }, labels());
assertFalse(readNext(nodes));
}
}
use of org.neo4j.internal.batchimport.InputIterator in project neo4j by neo4j.
the class CsvInputTest method shouldPropagateExceptionFromFailingDecorator.
@Test
public void shouldPropagateExceptionFromFailingDecorator() throws Exception {
// GIVEN
RuntimeException failure = new RuntimeException("FAILURE");
Iterable<DataFactory> data = datas(CsvInputTest.data(":ID,name\n1,Mattias", new FailingNodeDecorator(failure)));
Input input = new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatNodeFileHeader(), IdType.INTEGER, config(), NO_MONITOR, INSTANCE);
// WHEN
try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
readNext(nodes);
} catch (InputException e) {
// THEN
assertSame(e.getCause(), failure);
}
}
use of org.neo4j.internal.batchimport.InputIterator in project neo4j by neo4j.
the class CsvInputTest method shouldCopeWithLinesThatHasTooFewValuesButStillValidates.
@Test
public void shouldCopeWithLinesThatHasTooFewValuesButStillValidates() throws Exception {
// GIVEN
Iterable<DataFactory> data = dataIterable(data("1,ultralisk,ZERG,10\n" + "2,corruptor,ZERG\n" + "3,mutalisk,ZERG,3"));
Input input = new CsvInput(data, header(entry(null, Type.ID, extractors.long_()), entry("unit", Type.PROPERTY, extractors.string()), entry("type", Type.LABEL, extractors.string()), entry("kills", Type.PROPERTY, extractors.int_())), datas(), defaultFormatRelationshipFileHeader(), ACTUAL, config(), NO_MONITOR, INSTANCE);
// WHEN
try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
// THEN
assertNextNode(nodes, 1L, new Object[] { "unit", "ultralisk", "kills", 10 }, labels("ZERG"));
assertNextNode(nodes, 2L, new Object[] { "unit", "corruptor" }, labels("ZERG"));
assertNextNode(nodes, 3L, new Object[] { "unit", "mutalisk", "kills", 3 }, labels("ZERG"));
assertFalse(readNext(nodes));
}
}
use of org.neo4j.internal.batchimport.InputIterator in project neo4j by neo4j.
the class CsvInputTest method shouldTreatEmptyQuotedStringsAsNullIfConfiguredTo.
@Test
public void shouldTreatEmptyQuotedStringsAsNullIfConfiguredTo() throws Exception {
// GIVEN
Iterable<DataFactory> data = datas(CsvInputTest.data(":ID,one,two,three\n" + "1,\"\",,value"));
Configuration config = config().toBuilder().withEmptyQuotedStringsAsNull(true).build();
Input input = new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), IdType.INTEGER, config, NO_MONITOR, INSTANCE);
// WHEN
try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
// THEN
assertNextNode(nodes, 1L, properties("three", "value"), labels());
assertFalse(readNext(nodes));
}
}
use of org.neo4j.internal.batchimport.InputIterator in project neo4j by neo4j.
the class CsvInputTest method shouldHaveRelationshipsSpecifyStartEndNodeIdGroupsInHeader.
@Test
public void shouldHaveRelationshipsSpecifyStartEndNodeIdGroupsInHeader() throws Exception {
// GIVEN
IdType idType = IdType.INTEGER;
Iterable<DataFactory> data = dataIterable(data("123,TYPE,234\n" + "345,TYPE,456"));
Groups groups = new Groups();
Group startNodeGroup = groups.getOrCreate("StartGroup");
Group endNodeGroup = groups.getOrCreate("EndGroup");
Iterable<DataFactory> nodeHeader = dataIterable(data(":ID(" + startNodeGroup.name() + ")"), data(":ID(" + endNodeGroup.name() + ")"));
Input input = new CsvInput(nodeHeader, defaultFormatNodeFileHeader(), data, header(entry(null, Type.START_ID, startNodeGroup.name(), CsvInput.idExtractor(idType, extractors)), entry(null, Type.TYPE, extractors.string()), entry(null, Type.END_ID, endNodeGroup.name(), CsvInput.idExtractor(idType, extractors))), idType, config(), NO_MONITOR, INSTANCE);
// WHEN/THEN
try (InputIterator relationships = input.relationships(EMPTY).iterator()) {
assertRelationship(relationships, startNodeGroup, 123L, endNodeGroup, 234L, "TYPE", properties());
assertRelationship(relationships, startNodeGroup, 345L, endNodeGroup, 456L, "TYPE", properties());
assertFalse(readNext(relationships));
}
}
Aggregations