Skip to content

Commit

Permalink
Bloom index now properly indexes relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed Sep 12, 2017
1 parent b8284e9 commit 0c8cc6d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Expand Up @@ -25,6 +25,7 @@
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;


import org.neo4j.graphdb.Entity;
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException; import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.event.PropertyEntry; import org.neo4j.graphdb.event.PropertyEntry;
Expand Down Expand Up @@ -62,7 +63,6 @@ public Object beforeCommit( TransactionData data ) throws Exception
data.assignedNodeProperties().forEach( propertyEntry -> nodeMap.put( propertyEntry.entity().getId(), propertyEntry.entity().getAllProperties() ) ); data.assignedNodeProperties().forEach( propertyEntry -> nodeMap.put( propertyEntry.entity().getId(), propertyEntry.entity().getAllProperties() ) );


Map<Long,Map<String,Object>> relationshipMap = new HashMap<Long,Map<String,Object>>(); Map<Long,Map<String,Object>> relationshipMap = new HashMap<Long,Map<String,Object>>();

data.removedRelationshipProperties().forEach( propertyEntry -> data.removedRelationshipProperties().forEach( propertyEntry ->
{ {
try try
Expand All @@ -89,14 +89,15 @@ public void afterCommit( TransactionData data, Object state )
deleteIndexData( data.deletedNodes(), nodeIndex ); deleteIndexData( data.deletedNodes(), nodeIndex );
//update relationship index //update relationship index
Map<Long,Map<String,Object>> relationshipMap = ((Map<Long,Map<String,Object>>[]) state)[1]; Map<Long,Map<String,Object>> relationshipMap = ((Map<Long,Map<String,Object>>[]) state)[1];
updatePropertyData( data.removedNodeProperties(), relationshipMap, relationshipIndex ); updatePropertyData( data.removedRelationshipProperties(), relationshipMap, relationshipIndex );
updatePropertyData( data.assignedNodeProperties(), relationshipMap, relationshipIndex ); updatePropertyData( data.assignedRelationshipProperties(), relationshipMap, relationshipIndex );
deleteIndexData( data.deletedNodes(), nodeIndex ); deleteIndexData( data.deletedNodes(), nodeIndex );
} }


private void updatePropertyData( Iterable<PropertyEntry<Node>> propertyEntries, Map<Long,Map<String,Object>> state, WritableDatabaseBloomIndex nodeIndex ) private <E extends Entity> void updatePropertyData( Iterable<PropertyEntry<E>> propertyEntries, Map<Long,Map<String,Object>> state,
WritableDatabaseBloomIndex nodeIndex )
{ {
for ( PropertyEntry<Node> propertyEntry : propertyEntries ) for ( PropertyEntry<E> propertyEntry : propertyEntries )
{ {
long nodeId = propertyEntry.entity().getId(); long nodeId = propertyEntry.entity().getId();
Map<String,Object> allProperties = state.get( nodeId ); Map<String,Object> allProperties = state.get( nodeId );
Expand Down
Expand Up @@ -27,6 +27,9 @@
import java.util.Collections; import java.util.Collections;


import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Result; import org.neo4j.graphdb.Result;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.graphdb.factory.GraphDatabaseSettings;
Expand All @@ -39,7 +42,9 @@
public class BloomIT public class BloomIT
{ {
public static final String NODES = "CALL dbms.bloom.bloomNodes([\"%s\"])"; public static final String NODES = "CALL dbms.bloom.bloomNodes([\"%s\"])";
public static final String RELS = "CALL dbms.bloom.bloomRelationships([\"%s\"])";
public static final String NODEID = "nodeid"; public static final String NODEID = "nodeid";
public static final String RELID = "relid";
@Rule @Rule
public final EphemeralFileSystemRule fs = new EphemeralFileSystemRule(); public final EphemeralFileSystemRule fs = new EphemeralFileSystemRule();


Expand All @@ -52,21 +57,29 @@ public void before() throws Exception
factory = new TestGraphDatabaseFactory(); factory = new TestGraphDatabaseFactory();
factory.setFileSystem( fs.get() ); factory.setFileSystem( fs.get() );
factory.addKernelExtensions( Collections.singletonList( new BloomKernelExtensionFactory() ) ); factory.addKernelExtensions( Collections.singletonList( new BloomKernelExtensionFactory() ) );
db = factory.newImpermanentDatabase( Collections.singletonMap( GraphDatabaseSettings.bloom_indexed_properties, "prop" ) ); db = factory.newImpermanentDatabase( Collections.singletonMap( GraphDatabaseSettings.bloom_indexed_properties, "prop, relprop" ) );
} }


@Test @Test
public void shouldPopulateAndQueryIndexes() throws Exception public void shouldPopulateAndQueryIndexes() throws Exception
{ {
try ( Transaction transaction = db.beginTx() ) try ( Transaction transaction = db.beginTx() )
{ {
db.createNode().setProperty( "prop", "This is a integration test." ); Node node1 = db.createNode();
node1.setProperty( "prop", "This is a integration test." );
Node node2 = db.createNode();
node2.setProperty( "prop", "This is a related integration test" );
Relationship relationship = node1.createRelationshipTo( node2, RelationshipType.withName( "type" ) );
relationship.setProperty( "relprop", "They relate" );
transaction.success(); transaction.success();
} }


Result result = db.execute( String.format( NODES, "integration" ) ); Result result = db.execute( String.format( NODES, "integration" ) );

assertEquals( 0L, result.next().get( NODEID ) ); assertEquals( 0L, result.next().get( NODEID ) );
assertEquals( 1L, result.next().get( NODEID ) );
assertFalse( result.hasNext() );
result = db.execute( String.format( RELS, "relate" ) );
assertEquals( 0L, result.next().get( RELID ) );
assertFalse( result.hasNext() ); assertFalse( result.hasNext() );
} }


Expand Down

0 comments on commit 0c8cc6d

Please sign in to comment.