private void indexRelationship( long id ) { if ( !visitingNodes ) { read.singleRelationship( id, relationshipCursor ); if ( relationshipCursor.next() && schema.isAffected( new long[]{relationshipCursor.type()} ) ) { relationshipCursor.properties( propertyCursor ); indexProperties( id ); } } }
@Test public void shouldAccessRelationshipLabels() { // given Map<Integer,Integer> counts = new HashMap<>(); try ( RelationshipScanCursor relationships = cursors.allocateRelationshipScanCursor() ) { // when read.allRelationshipsScan( relationships ); while ( relationships.next() ) { counts.compute( relationships.type(), ( k, v ) -> v == null ? 1 : v + 1 ); } } // then assertEquals( 3, counts.size() ); int[] values = new int[3]; int i = 0; for ( int value : counts.values() ) { values[i++] = value; } Arrays.sort( values ); assertArrayEquals( new int[]{1, 6, 6}, values ); }
private void initializeData() { // it enough to check only start node, since it's absence will indicate that data was not yet loaded if ( startNode == AbstractBaseRecord.NO_ID ) { KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { RelationshipScanCursor relationships = transaction.ambientRelationshipCursor(); transaction.dataRead().singleRelationship( id, relationships ); //at this point we don't care if it is there or not just load what we got relationships.next(); this.type = relationships.type(); this.startNode = relationships.sourceNodeReference(); this.endNode = relationships.targetNodeReference(); } } }
while ( relationshipScanCursor.next() ) int typeId = relationshipScanCursor.type(); relationshipScanCursor.properties( propertyCursor ); MutableIntSet propertyIds = IntSets.mutable.empty();
private void assertCountRelationships( RelationshipScanCursor relationship, int expectedCount, long sourceNode, int type, long targetNode ) { int count = 0; while ( relationship.next() ) { assertEquals( sourceNode, relationship.sourceNodeReference() ); assertEquals( type, relationship.type() ); assertEquals( targetNode, relationship.targetNodeReference() ); count++; } assertEquals( expectedCount, count ); }
@Override public void compute(int iterations, RelationshipType... relationshipTypes) { stats.iterations = iterations; long start = System.currentTimeMillis(); final int[] src = new int[nodeCount]; dst = new AtomicIntegerArray(nodeCount); final int[] degrees = computeDegrees(); stats.readNodeMillis = System.currentTimeMillis() - start; stats.nodes = nodeCount; start = System.currentTimeMillis(); int[] relationshipTypesIds = fetchRelationshipTypeIds(relationshipTypes); stats.readRelationshipMillis = System.currentTimeMillis() - start; stats.relationships = relCount; start = System.currentTimeMillis(); for (int iteration = 0; iteration < iterations; iteration++) { startIteration(src, dst, degrees); MultiThreadedGlobalGraphOperations.forAllRelationships(db, pool, BATCH_SIZE, (ktx, relationshipScanCursor) -> { if (relationshipTypes.length == 0 || contains(relationshipTypesIds, relationshipScanCursor.type())) { int endNode = (int) relationshipScanCursor.targetNodeReference(); int startNode = (int) relationshipScanCursor.sourceNodeReference(); dst.addAndGet(endNode, src[startNode]); } }); } stats.computeMillis = System.currentTimeMillis() - start; }
assertTrue( "should find relationship", relationship.next() ); assertEquals( label, relationship.type() ); assertEquals( n1, relationship.sourceNodeReference() ); assertEquals( n2, relationship.targetNodeReference() );
private void initializeData() { // it enough to check only start node, since it's absence will indicate that data was not yet loaded if ( startNode == AbstractBaseRecord.NO_ID ) { KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { RelationshipScanCursor relationships = transaction.ambientRelationshipCursor(); transaction.dataRead().singleRelationship( id, relationships ); //at this point we don't care if it is there or not just load what we got relationships.next(); this.type = relationships.type(); this.startNode = relationships.sourceNodeReference(); this.endNode = relationships.targetNodeReference(); } } }
@Override public void validateRelationshipPropertyExistenceConstraint( RelationshipScanCursor relationshipCursor, PropertyCursor propertyCursor, RelationTypeSchemaDescriptor descriptor ) throws CreateConstraintFailureException { while ( relationshipCursor.next() ) { relationshipCursor.properties( propertyCursor ); for ( int propertyKey : descriptor.getPropertyIds() ) { if ( relationshipCursor.type() == descriptor.getRelTypeId() && !hasProperty( propertyCursor, propertyKey ) ) { throw createConstraintFailure( new RelationshipPropertyExistenceException( descriptor, VERIFICATION, relationshipCursor.relationshipReference() ) ); } } } }
while ( relationshipScanCursor.next() ) int typeId = relationshipScanCursor.type(); relationshipScanCursor.properties( propertyCursor ); MutableIntSet propertyIds = IntSets.mutable.empty();