Skip to content

Commit

Permalink
enabled mongoadapter not starting yet
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Sep 19, 2023
1 parent 1880cbd commit 195fb35
Show file tree
Hide file tree
Showing 22 changed files with 711 additions and 513 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.polypheny.db.catalog.entity.logical.LogicalIndex;
import org.polypheny.db.catalog.entity.logical.LogicalTable;
import org.polypheny.db.catalog.entity.logical.LogicalTableWrapper;
import org.polypheny.db.catalog.entity.physical.PhysicalEntity;
import org.polypheny.db.catalog.entity.physical.PhysicalTable;
import org.polypheny.db.catalog.logistic.Collation;
import org.polypheny.db.catalog.logistic.PlacementType;
Expand Down Expand Up @@ -119,8 +120,7 @@ public AlgNode getModify( long allocId, Modify<?> modify, AlgBuilder builder ) {

@Override
public AlgNode getRelModify( long allocId, RelModify<?> modify, AlgBuilder builder ) {
Pair<AllocationEntity, List<Long>> relations = catalog.getAllocRelations().get( allocId );
PhysicalTable table = catalog.getTable( relations.getValue().get( 0 ) );
PhysicalTable table = catalog.fromAllocation( allocId );
if ( table.unwrap( ModifiableEntity.class ) == null ) {
return null;
}
Expand All @@ -137,14 +137,12 @@ public AlgNode getRelModify( long allocId, RelModify<?> modify, AlgBuilder build

@Override
public AlgNode getDocModify( long allocId, DocumentModify<?> modify, AlgBuilder builder ) {
Pair<AllocationEntity, List<Long>> relations = catalog.getAllocRelations().get( allocId );
PhysicalTable table = catalog.getTable( relations.getValue().get( 0 ) );
PhysicalTable table = catalog.fromAllocation( allocId );
if ( table.unwrap( ModifiableEntity.class ) == null ) {
return null;
}

builder.clear();

builder.push( modify.getInput() );

Pair<List<String>, List<RexNode>> updates = getRelationalDocumentModify( modify );
Expand Down Expand Up @@ -213,10 +211,11 @@ private Pair<List<String>, List<RexNode>> getRelationalDocumentModify( DocumentM

@Override
public AlgNode getGraphModify( long allocId, LpgModify<?> alg, AlgBuilder builder ) {
PhysicalTable nodesTable = catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 0 ) );
PhysicalTable nodePropertiesTable = catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 1 ) );
PhysicalTable edgesTable = catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 2 ) );
PhysicalTable edgePropertiesTable = catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 3 ) );
List<PhysicalEntity> physicals = catalog.getPhysicalsFromAllocs( allocId );
PhysicalEntity nodesTable = physicals.get( 0 );
PhysicalEntity nodePropertiesTable = physicals.get( 1 );
PhysicalEntity edgesTable = physicals.get( 2 );
PhysicalEntity edgePropertiesTable = physicals.get( 3 );

List<AlgNode> inputs = new ArrayList<>();

Expand Down Expand Up @@ -344,7 +343,7 @@ public void createGraph( Context context, LogicalGraph logical, AllocationGraph
Triple.of( "key", GraphType.KEY_SIZE, PolyType.VARCHAR ),
Triple.of( "value", GraphType.VALUE_SIZE, PolyType.VARCHAR ) ) );

catalog.getAllocRelations().put( allocation.id, Pair.of( allocation, List.of( node.id, nProperties.id, edge.id, eProperties.id ) ) );
catalog.addPhysical( allocation, node, nProperties, edge, eProperties );
}


Expand All @@ -369,28 +368,26 @@ private PhysicalTable createSubstitution( Context context, LogicalEntity logical
}

modifiable.createTable( context, LogicalTableWrapper.of( table, columns ), AllocationTableWrapper.of( allocTable, allocColumns ) );
return catalog.getTable( catalog.getAllocRelations().get( allocTable.id ).right.get( 0 ) );
return catalog.fromAllocation( allocation.id );
}


@Override
public void dropGraph( Context context, AllocationGraph allocation ) {
catalog.dropTable( allocation.id );
catalog.getAllocRelations().remove( allocation.id );
catalog.removePhysical( allocation.id );
}


@Override
public void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) {
PhysicalTable physical = createSubstitution( context, logical, allocation, "_doc_", List.of( Triple.of( DocumentType.DOCUMENT_ID, DocumentType.ID_SIZE, PolyType.VARBINARY ), Triple.of( DocumentType.DOCUMENT_DATA, DocumentType.DATA_SIZE, PolyType.VARBINARY ) ) );
catalog.getAllocRelations().put( allocation.id, Pair.of( allocation, List.of( physical.id ) ) );
catalog.addPhysical( allocation, physical );
}


@Override
public void dropCollection( Context context, AllocationCollection allocation ) {
catalog.dropTable( allocation.id );
catalog.getAllocRelations().remove( allocation.id );
catalog.removePhysical( allocation.id );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
import org.polypheny.db.catalog.entity.allocation.AllocationTable;
import org.polypheny.db.catalog.entity.allocation.AllocationTableWrapper;
import org.polypheny.db.catalog.entity.logical.LogicalTableWrapper;
import org.polypheny.db.catalog.entity.physical.PhysicalEntity;
import org.polypheny.db.catalog.entity.physical.PhysicalTable;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.prepare.Context;
import org.polypheny.db.schema.trait.ModelTrait;
import org.polypheny.db.tools.AlgBuilder;
import org.polypheny.db.util.Pair;

@AllArgsConstructor
public class RelationalScanDelegate implements Scannable {
Expand All @@ -46,23 +46,19 @@ public class RelationalScanDelegate implements Scannable {

@Override
public AlgNode getRelScan( long allocId, AlgBuilder builder ) {
Pair<AllocationEntity, List<Long>> relations = catalog.getAllocRelations().get( allocId );
return builder.scan( catalog.getTable( relations.right.get( 0 ) ) ).build();
PhysicalEntity entity = catalog.fromAllocation( allocId );
return builder.scan( entity ).build();
}


@Override
public AlgNode getGraphScan( long allocId, AlgBuilder builder ) {
builder.clear();
PhysicalTable node = catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 0 ) );
PhysicalTable nProps = catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 1 ) );
PhysicalTable edge = catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 2 ) );
PhysicalTable eProps = catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 3 ) );

builder.scan( node );
builder.scan( nProps );
builder.scan( edge );
builder.scan( eProps );
List<PhysicalEntity> physicals = catalog.getPhysicalsFromAllocs( allocId );
builder.scan( physicals.get( 0 ) );//node
builder.scan( physicals.get( 1 ) );//node Props
builder.scan( physicals.get( 2 ) );//edge
builder.scan( physicals.get( 3 ) );//edge Props

builder.transform( ModelTrait.GRAPH, GraphType.of(), false );

Expand All @@ -73,7 +69,7 @@ public AlgNode getGraphScan( long allocId, AlgBuilder builder ) {
@Override
public AlgNode getDocumentScan( long allocId, AlgBuilder builder ) {
builder.clear();
PhysicalTable table = catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 0 ) );
PhysicalTable table = catalog.fromAllocation( allocId );
builder.scan( table );
AlgDataType rowType = DocumentType.ofId();
builder.transform( ModelTrait.DOCUMENT, rowType, false );
Expand All @@ -83,12 +79,12 @@ public AlgNode getDocumentScan( long allocId, AlgBuilder builder ) {

@Override
public AlgNode getScan( long allocId, AlgBuilder builder ) {
Pair<AllocationEntity, List<Long>> alloc = catalog.getAllocRelations().get( allocId );
if ( alloc.left.unwrap( AllocationTable.class ) != null ) {
AllocationEntity alloc = catalog.getAlloc( allocId );
if ( alloc.unwrap( AllocationTable.class ) != null ) {
return getRelScan( allocId, builder );
} else if ( alloc.left.unwrap( AllocationCollection.class ) != null ) {
} else if ( alloc.unwrap( AllocationCollection.class ) != null ) {
return getDocumentScan( allocId, builder );
} else if ( alloc.left.unwrap( AllocationGraph.class ) != null ) {
} else if ( alloc.unwrap( AllocationGraph.class ) != null ) {
return getGraphScan( allocId, builder );
} else {
throw new GenericRuntimeException( "This should not happen" );
Expand All @@ -110,16 +106,17 @@ public void refreshTable( long allocId ) {

@Override
public void refreshGraph( long allocId ) {
scannable.refreshTable( catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 0 ) ).allocationId );
scannable.refreshTable( catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 1 ) ).allocationId );
scannable.refreshTable( catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 2 ) ).allocationId );
scannable.refreshTable( catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 3 ) ).allocationId );
List<PhysicalEntity> physicals = catalog.getPhysicalsFromAllocs( allocId );
scannable.refreshTable( physicals.get( 0 ).allocationId );
scannable.refreshTable( physicals.get( 1 ).allocationId );
scannable.refreshTable( physicals.get( 2 ).allocationId );
scannable.refreshTable( physicals.get( 3 ).allocationId );
}


@Override
public void refreshCollection( long allocId ) {
scannable.refreshTable( catalog.getTable( catalog.getAllocRelations().get( allocId ).getValue().get( 0 ) ).allocationId );
scannable.refreshTable( catalog.fromAllocation( allocId ).allocationId );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.polypheny.db.catalog.entity.logical.LogicalColumn;
import org.polypheny.db.catalog.entity.logical.LogicalTable;
import org.polypheny.db.catalog.entity.physical.PhysicalColumn;
import org.polypheny.db.catalog.entity.physical.PhysicalEntity;
import org.polypheny.db.catalog.entity.physical.PhysicalTable;
import org.polypheny.db.schema.Namespace;
import org.polypheny.db.util.Pair;
Expand All @@ -48,15 +47,9 @@
public class RelStoreCatalog extends StoreCatalog {


@Serialize
ConcurrentMap<Long, Namespace> namespaces;
@Serialize
ConcurrentMap<Long, PhysicalTable> tables;
@Serialize
ConcurrentMap<Pair<Long, Long>, PhysicalColumn> columns; // allocId, columnId

ConcurrentMap<Long, Pair<AllocationEntity, List<Long>>> allocRelations;


public RelStoreCatalog( long adapterId ) {
this( adapterId, new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>() );
Expand All @@ -69,17 +62,8 @@ public RelStoreCatalog(
@Deserialize("tables") Map<Long, PhysicalTable> tables,
@Deserialize("columns") Map<Pair<Long, Long>, PhysicalColumn> columns,
@Deserialize("allocRelations") Map<Long, Pair<AllocationEntity, List<Long>>> allocRelations ) {
super( adapterId );
this.namespaces = new ConcurrentHashMap<>( namespaces );
this.tables = new ConcurrentHashMap<>( tables );
super( adapterId, namespaces, tables, Map.of(), Map.of() );
this.columns = new ConcurrentHashMap<>( columns );

this.allocRelations = new ConcurrentHashMap<>( allocRelations );
}


public void addTable( PhysicalTable table ) {
tables.put( table.id, table );
}


Expand All @@ -89,7 +73,7 @@ public void addColumn( PhysicalColumn column ) {


public PhysicalTable getTable( long id ) {
return tables.get( id );
return getPhysical( id ).unwrap( PhysicalTable.class );
}


Expand All @@ -98,24 +82,13 @@ public PhysicalColumn getColumn( long id, long allocId ) {
}


public Namespace getNamespace( long id ) {
return namespaces.get( id );
}


public void addNamespace( long id, Namespace namespace ) {
namespaces.put( id, namespace );
}


public PhysicalTable createTable( String namespaceName, String tableName, Map<Long, String> columnNames, LogicalTable logical, Map<Long, LogicalColumn> lColumns, AllocationTableWrapper wrapper ) {
AllocationTable allocation = wrapper.table;
List<AllocationColumn> columns = wrapper.columns;
List<PhysicalColumn> pColumns = columns.stream().map( c -> new PhysicalColumn( columnNames.get( c.columnId ), logical.id, allocation.id, allocation.adapterId, c.position, lColumns.get( c.columnId ) ) ).collect( Collectors.toList() );
PhysicalTable table = new PhysicalTable( IdBuilder.getInstance().getNewPhysicalId(), allocation.id, tableName, pColumns, logical.namespaceId, namespaceName, allocation.adapterId );
addTable( table );
pColumns.forEach( this::addColumn );
allocRelations.put( allocation.id, Pair.of( allocation, List.of( table.id ) ) );
addPhysical( allocation, table );
return table;
}

Expand All @@ -126,7 +99,7 @@ public PhysicalColumn addColumn( String name, long allocId, long adapterId, int
List<PhysicalColumn> columns = new ArrayList<>( table.columns );
columns.add( position - 1, column );
addColumn( column );
tables.put( table.id, table.toBuilder().columns( ImmutableList.copyOf( columns ) ).build() );
addPhysical( getAlloc( table.allocationId ), table.toBuilder().columns( ImmutableList.copyOf( columns ) ).build() );
return column;
}

Expand All @@ -138,40 +111,24 @@ public PhysicalColumn updateColumnType( long allocId, LogicalColumn newCol ) {
List<PhysicalColumn> pColumn = new ArrayList<>( table.columns );
pColumn.remove( old );
pColumn.add( column );
tables.put( table.id, table.toBuilder().columns( ImmutableList.copyOf( pColumn ) ).build() );
addPhysical( getAlloc( table.allocationId ), table.toBuilder().columns( ImmutableList.copyOf( pColumn ) ).build() );

return column;
}


public PhysicalTable fromAllocation( long id ) {
return tables.get( allocRelations.get( id ).getValue().get( 0 ) );
}


@Override
public PhysicalEntity getPhysical( long id ) {
return tables.get( id );
return getPhysicalsFromAllocs( id ).get( 0 ).unwrap( PhysicalTable.class );
}


public void dropTable( long id ) {
for ( long allocId : allocRelations.get( id ).right ) {
for ( PhysicalColumn column : tables.get( allocId ).columns ) {
columns.remove( column.id );
}
tables.remove( allocId );
}
allocRelations.remove( id );

}


public void dropColum( long allocId, long columnId ) {
PhysicalColumn column = columns.get( Pair.of( allocId, columnId ) );
PhysicalTable table = fromAllocation( allocId );
List<PhysicalColumn> pColumns = new ArrayList<>( table.columns );
pColumns.remove( column );
tables.put( table.id, table.toBuilder().columns( ImmutableList.copyOf( pColumns ) ).build() );
addPhysical( getAlloc( allocId ), table.toBuilder().columns( ImmutableList.copyOf( pColumns ) ).build() );
columns.remove( Pair.of( allocId, columnId ) );
}

Expand Down
Loading

0 comments on commit 195fb35

Please sign in to comment.