use of org.neo4j.internal.batchimport.input.Input 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.input.Input 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.input.Input 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));
}
}
use of org.neo4j.internal.batchimport.input.Input in project neo4j by neo4j.
the class CsvInputTest method shouldProvideRelationshipsFromCsvInput.
@Test
public void shouldProvideRelationshipsFromCsvInput() throws Exception {
// GIVEN
IdType idType = IdType.STRING;
Iterable<DataFactory> data = dataIterable(data("node1,node2,KNOWS,1234567\n" + "node2,node10,HACKS,987654"));
Input input = new CsvInput(datas(), defaultFormatNodeFileHeader(), data, header(entry("from", Type.START_ID, CsvInput.idExtractor(idType, extractors)), entry("to", Type.END_ID, CsvInput.idExtractor(idType, extractors)), entry("type", Type.TYPE, extractors.string()), entry("since", Type.PROPERTY, extractors.long_())), idType, config(), NO_MONITOR, INSTANCE);
// WHEN/THEN
try (InputIterator relationships = input.relationships(EMPTY).iterator()) {
assertNextRelationship(relationships, "node1", "node2", "KNOWS", properties("since", 1234567L));
assertNextRelationship(relationships, "node2", "node10", "HACKS", properties("since", 987654L));
}
}
use of org.neo4j.internal.batchimport.input.Input in project neo4j by neo4j.
the class CsvInputTest method shouldAllowNodesWithoutIdHeader.
@Test
public void shouldAllowNodesWithoutIdHeader() throws Exception {
// GIVEN
DataFactory data = data("name:string,level:int\n" + "Mattias,1\n" + "Johan,2\n");
Iterable<DataFactory> dataIterable = dataIterable(data);
Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), IdType.STRING, config(), NO_MONITOR, INSTANCE);
// WHEN
try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
// THEN
assertNextNode(nodes, null, new Object[] { "name", "Mattias", "level", 1 }, labels());
assertNextNode(nodes, null, new Object[] { "name", "Johan", "level", 2 }, labels());
assertFalse(readNext(nodes));
}
}
Aggregations