Skip to content

Commit

Permalink
Restore graph from Neo4j to graph model instead of relational model
Browse files Browse the repository at this point in the history
  • Loading branch information
murermader committed Jan 13, 2025
1 parent 42aaa95 commit 2e5e22f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public void onMatch( AlgOptRuleCall call ) {
if ( oldAlg.getEntity().unwrap( TranslatableEntity.class ).isEmpty() ) {
return;
}
AlgNode newAlg = oldAlg.getEntity().unwrap( TranslatableEntity.class ).get().toAlg( oldAlg.getCluster(), oldAlg.getTraitSet() );
TranslatableEntity one = oldAlg.getEntity().unwrap( TranslatableEntity.class ).orElseThrow();
var oldCluster = oldAlg.getCluster();
var newTraitSet = oldAlg.getTraitSet();
AlgNode newAlg = one.toAlg( oldCluster, newTraitSet );
call.transformTo( newAlg );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static String getPhysicalGraphName( long id ) {
}


private static String getMappingLabel( long id ) {
static String getMappingLabel( long id ) {
return String.format( "___n_%d___", id );
}

Expand Down Expand Up @@ -427,7 +427,7 @@ public void restoreTable( AllocationTable alloc, List<PhysicalEntity> entities,
public void restoreGraph( AllocationGraph alloc, List<PhysicalEntity> entities, Context context ) {
for ( PhysicalEntity entity : entities ) {
updateNamespace( entity.namespaceName, entity.namespaceId );
adapterCatalog.addPhysical( alloc, currentNamespace.createEntity( entity, List.of(), currentNamespace ) );
adapterCatalog.addPhysical( alloc, currentNamespace.createGraph( entity, List.of(), this.db, this ) );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.polypheny.db.plan.Convention;
import org.polypheny.db.schema.Namespace;

import static org.polypheny.db.adapter.neo4j.Neo4jPlugin.getMappingLabel;

@EqualsAndHashCode(callSuper = true)
@Value
public class NeoNamespace extends Namespace implements Expressible {
Expand Down Expand Up @@ -67,6 +69,10 @@ public NeoEntity createEntity( PhysicalEntity entity, List<? extends PhysicalFie
return new NeoEntity( entity, fields, namespace );
}

public NeoGraph createGraph( PhysicalEntity entity, List<? extends PhysicalField> fields, Driver db, Neo4jStore store ) {
return new NeoGraph( entity, fields, this.transactionProvider, db, getMappingLabel( entity.id ), store );
}


@Override
public Expression asExpression() {
Expand Down

0 comments on commit 2e5e22f

Please sign in to comment.