use of org.neo4j.internal.batchimport.input.Input in project neo4j by neo4j.
the class CsvInputTest method shouldNotHaveIdSetAsPropertyIfIdHeaderEntryIsNamedForActualIds.
@Test
public void shouldNotHaveIdSetAsPropertyIfIdHeaderEntryIsNamedForActualIds() throws Exception {
// GIVEN
DataFactory data = data("myId:ID,name:string,level:int\n" + "0,Mattias,1\n" + // this node is anonymous
"1,Johan,2\n");
Iterable<DataFactory> dataIterable = dataIterable(data);
Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), ACTUAL, config(), NO_MONITOR, INSTANCE);
// WHEN
try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
// THEN
assertNextNode(nodes, 0L, new Object[] { "name", "Mattias", "level", 1 }, labels());
assertNextNode(nodes, 1L, new Object[] { "name", "Johan", "level", 2 }, labels());
assertFalse(readNext(nodes));
}
}
use of org.neo4j.internal.batchimport.input.Input in project neo4j by neo4j.
the class CsvInputTest method shouldDoWithoutRelationshipTypeHeaderIfDefaultSupplied.
@Test
public void shouldDoWithoutRelationshipTypeHeaderIfDefaultSupplied() throws Exception {
// GIVEN relationship data w/o :TYPE header
String defaultType = "HERE";
DataFactory data = data(":START_ID,:END_ID,name\n" + "0,1,First\n" + "2,3,Second\n", InputEntityDecorators.defaultRelationshipType(defaultType));
Iterable<DataFactory> dataIterable = dataIterable(data);
Input input = new CsvInput(datas(), defaultFormatNodeFileHeader(), dataIterable, defaultFormatRelationshipFileHeader(), ACTUAL, config(), NO_MONITOR, INSTANCE);
// WHEN
try (InputIterator relationships = input.relationships(EMPTY).iterator()) {
// THEN
assertNextRelationship(relationships, 0L, 1L, defaultType, properties("name", "First"));
assertNextRelationship(relationships, 2L, 3L, defaultType, properties("name", "Second"));
assertFalse(readNext(relationships));
}
}
use of org.neo4j.internal.batchimport.input.Input in project neo4j by neo4j.
the class ParallelBatchImporterTest method verifyData.
private void verifyData(int nodeCount, int relationshipCount, GraphDatabaseService db, Transaction tx, IdGroupDistribution groups, long nodeRandomSeed, long relationshipRandomSeed) throws IOException {
// Read all nodes, relationships and properties ad verify against the input data.
LongAdder propertyCount = new LongAdder();
try (InputIterator nodes = nodes(nodeRandomSeed, nodeCount, config.batchSize(), inputIdGenerator, groups, propertyCount).iterator();
InputIterator relationships = relationships(relationshipRandomSeed, relationshipCount, config.batchSize(), inputIdGenerator, groups, propertyCount, new LongAdder()).iterator();
ResourceIterator<Node> dbNodes = tx.getAllNodes().iterator()) {
// Nodes
Map<String, Node> nodeByInputId = new HashMap<>(nodeCount);
while (dbNodes.hasNext()) {
Node node = dbNodes.next();
String id = (String) node.getProperty("id");
assertNull(nodeByInputId.put(id, node));
}
int verifiedNodes = 0;
long allNodesScanLabelCount = 0;
InputChunk chunk = nodes.newChunk();
InputEntity input = new InputEntity();
while (nodes.next(chunk)) {
while (chunk.next(input)) {
String iid = uniqueId(input.idGroup, input.objectId);
Node node = nodeByInputId.get(iid);
assertNodeEquals(input, node);
verifiedNodes++;
assertDegrees(node);
allNodesScanLabelCount += Iterables.count(node.getLabels());
}
}
assertEquals(nodeCount, verifiedNodes);
// Labels
long labelScanStoreEntryCount = stream(tx.getAllLabels()).flatMap(l -> tx.findNodes(l).stream()).count();
assertEquals(allNodesScanLabelCount, labelScanStoreEntryCount, format("Expected label scan store and node store to have same number labels. But %n" + "#labelsInNodeStore=%d%n" + "#labelsInLabelScanStore=%d%n", allNodesScanLabelCount, labelScanStoreEntryCount));
// Relationships
chunk = relationships.newChunk();
Map<String, Relationship> relationshipByName = new HashMap<>();
for (Relationship relationship : tx.getAllRelationships()) {
relationshipByName.put((String) relationship.getProperty("id"), relationship);
}
int verifiedRelationships = 0;
while (relationships.next(chunk)) {
while (chunk.next(input)) {
if (!inputIdGenerator.isMiss(input.objectStartId) && !inputIdGenerator.isMiss(input.objectEndId)) {
// A relationship referring to missing nodes. The InputIdGenerator is expected to generate
// some (very few) of those. Skip it.
String name = (String) propertyOf(input, "id");
Relationship relationship = relationshipByName.get(name);
assertNotNull(relationship, "Expected there to be a relationship with name '" + name + "'");
assertEquals(nodeByInputId.get(uniqueId(input.startIdGroup, input.objectStartId)), relationship.getStartNode());
assertEquals(nodeByInputId.get(uniqueId(input.endIdGroup, input.objectEndId)), relationship.getEndNode());
assertRelationshipEquals(input, relationship);
}
verifiedRelationships++;
}
}
assertEquals(relationshipCount, verifiedRelationships);
}
}
Aggregations