use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputBatchImportIT method buildUpExpectedData.
private void buildUpExpectedData(List<InputNode> nodeData, List<InputRelationship> relationshipData, Map<String, InputNode> expectedNodes, Map<String, String[]> expectedNodeNames, Map<String, Map<String, Map<String, AtomicInteger>>> expectedRelationships, Map<String, AtomicLong> nodeCounts, Map<String, Map<String, Map<String, AtomicLong>>> relationshipCounts) {
for (InputNode node : nodeData) {
expectedNodes.put((String) node.id(), node);
expectedNodeNames.put(nameOf(node), node.labels());
countNodeLabels(nodeCounts, node.labels());
}
for (InputRelationship relationship : relationshipData) {
// Expected relationship counts per node, type and direction
InputNode startNode = expectedNodes.get(relationship.startNode());
InputNode endNode = expectedNodes.get(relationship.endNode());
{
expectedRelationships.get(nameOf(startNode)).get(nameOf(endNode)).get(relationship.type()).incrementAndGet();
}
// Expected counts per start/end node label ids
// Let's do what CountsState#addRelationship does, roughly
relationshipCounts.get(null).get(null).get(null).incrementAndGet();
relationshipCounts.get(null).get(relationship.type()).get(null).incrementAndGet();
for (String startNodeLabelName : asSet(startNode.labels())) {
Map<String, Map<String, AtomicLong>> startLabelCounts = relationshipCounts.get(startNodeLabelName);
startLabelCounts.get(null).get(null).incrementAndGet();
Map<String, AtomicLong> typeCounts = startLabelCounts.get(relationship.type());
typeCounts.get(null).incrementAndGet();
if (COMPUTE_DOUBLE_SIDED_RELATIONSHIP_COUNTS) {
for (String endNodeLabelName : asSet(endNode.labels())) {
startLabelCounts.get(null).get(endNodeLabelName).incrementAndGet();
typeCounts.get(endNodeLabelName).incrementAndGet();
}
}
}
for (String endNodeLabelName : asSet(endNode.labels())) {
relationshipCounts.get(null).get(null).get(endNodeLabelName).incrementAndGet();
relationshipCounts.get(null).get(relationship.type()).get(endNodeLabelName).incrementAndGet();
}
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputBatchImportIT method randomNodeData.
// ======================================================
// Below is code for generating import data
// ======================================================
private List<InputNode> randomNodeData() {
List<InputNode> nodes = new ArrayList<>();
for (int i = 0; i < 300; i++) {
Object[] properties = new Object[] { "name", "Node " + i };
String id = UUID.randomUUID().toString();
nodes.add(new InputNode("source", i, i, id, properties, null, randomLabels(random), null));
}
return nodes;
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldProvideAdditiveLabels.
@Test
public void shouldProvideAdditiveLabels() throws Exception {
// GIVEN
String[] addedLabels = { "Two", "AddTwo" };
DataFactory<InputNode> data = data(":ID,name,:LABEL\n" + "0,First,\n" + "1,Second,One\n" + "2,Third,One;Two", additiveLabels(addedLabels));
Iterable<DataFactory<InputNode>> dataIterable = dataIterable(data);
Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), null, null, IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN/THEN
try (ResourceIterator<InputNode> nodes = input.nodes().iterator()) {
assertNode(nodes.next(), 0L, properties("name", "First"), labels(addedLabels));
assertNode(nodes.next(), 1L, properties("name", "Second"), labels(union(new String[] { "One" }, addedLabels)));
assertNode(nodes.next(), 2L, properties("name", "Third"), labels(union(new String[] { "One" }, addedLabels)));
assertFalse(nodes.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldIgnoreEmptyPropertyValues.
@Test
public void shouldIgnoreEmptyPropertyValues() throws Exception {
// GIVEN
DataFactory<InputNode> data = data(":ID,name,extra\n" + // here we leave out "extra" property
"0,Mattias,\n" + "1,Johan,Additional\n");
Iterable<DataFactory<InputNode>> dataIterable = dataIterable(data);
Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), null, null, IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (ResourceIterator<InputNode> nodes = input.nodes().iterator()) {
// THEN
assertNode(nodes.next(), 0L, new Object[] { "name", "Mattias" }, labels());
assertNode(nodes.next(), 1L, new Object[] { "name", "Johan", "extra", "Additional" }, labels());
assertFalse(nodes.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldIncludeDataSourceInformationOnBadFieldValueOrLine.
@Test
public void shouldIncludeDataSourceInformationOnBadFieldValueOrLine() throws Exception {
// GIVEN
Iterable<DataFactory<InputNode>> data = DataFactories.nodeData(CsvInputTest.<InputNode>data(":ID,name,other:int\n" + "1,Mattias,10\n" + "2,Johan,abc\n" + "3,Emil,12"));
Input input = new CsvInput(data, DataFactories.defaultFormatNodeFileHeader(), null, null, IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
try {
assertNode(nodes.next(), 1L, new Object[] { "name", "Mattias", "other", 10 }, labels());
nodes.next();
fail("Should have failed");
} catch (InputException e) {
// THEN
assertThat(e.getMessage(), containsString("other"));
assertThat(e.getMessage(), containsString("abc"));
}
}
}
Aggregations