Skip to content

Commit

Permalink
fixing various bugs, correctly adding ids for rowtypes, some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Oct 7, 2023
1 parent c33df9d commit 1cbbd76
Show file tree
Hide file tree
Showing 125 changed files with 598 additions and 839 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,8 @@ public DocumentScanDelegate( Scannable scannable, DocStoreCatalog catalog ) {


@Override
public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) {
scannable.createTable( context, logical, allocation );
}


@Override
public List<PhysicalEntity> refreshTable( long allocId ) {
return scannable.refreshTable( allocId );
public List<PhysicalEntity> createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) {
return scannable.createTable( context, logical, allocation );
}


Expand All @@ -61,23 +55,12 @@ public void restoreTable( AllocationTable alloc, List<PhysicalEntity> entities )
}


@Override
public List<PhysicalEntity> refreshGraph( long allocId ) {
return Scannable.refreshGraphSubstitute( scannable, allocId );
}


@Override
public void restoreGraph( AllocationGraph alloc, List<PhysicalEntity> entities ) {
Scannable.restoreGraphSubstitute( scannable, alloc, entities );
}


@Override
public List<PhysicalEntity> refreshCollection( long allocId ) {
return scannable.refreshCollection( allocId );
}


@Override
public void restoreCollection( AllocationCollection alloc, List<PhysicalEntity> entities ) {
Expand All @@ -92,8 +75,8 @@ public void dropTable( Context context, long allocId ) {


@Override
public void createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) {
Scannable.createGraphSubstitute( scannable, context, logical, allocation );
public List<PhysicalEntity> createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) {
return Scannable.createGraphSubstitute( scannable, context, logical, allocation );
}


Expand All @@ -104,8 +87,8 @@ public void dropGraph( Context context, AllocationGraph allocation ) {


@Override
public void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) {
scannable.createCollection( context, logical, allocation );
public List<PhysicalEntity> createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) {
return scannable.createCollection( context, logical, allocation );
}


Expand Down
31 changes: 6 additions & 25 deletions core/src/main/java/org/polypheny/db/adapter/GraphScanDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,22 @@ public GraphScanDelegate( Scannable scannable, GraphStoreCatalog catalog ) {


@Override
public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) {
scannable.createTable( context, logical, allocation );
public List<PhysicalEntity> createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) {
return scannable.createTable( context, logical, allocation );
}


@Override
public List<PhysicalEntity> refreshTable( long allocId ) {
return scannable.refreshTable( allocId );
}


@Override
public void restoreTable( AllocationTable alloc, List<PhysicalEntity> entities ) {
scannable.restoreTable( alloc, entities );
}


@Override
public List<PhysicalEntity> refreshGraph( long allocId ) {
return scannable.refreshGraph( allocId );
}


@Override
public void restoreGraph( AllocationGraph alloc, List<PhysicalEntity> entities ) {
scannable.restoreGraph( alloc, entities );
}


@Override
public List<PhysicalEntity> refreshCollection( long allocId ) {
return Scannable.refreshCollectionSubstitution( scannable, allocId );
}


@Override
public void restoreCollection( AllocationCollection alloc, List<PhysicalEntity> entities ) {
Scannable.restoreCollectionSubstitute( scannable, alloc, entities );
Expand All @@ -91,8 +72,8 @@ public void dropTable( Context context, long allocId ) {


@Override
public void createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) {
scannable.createGraph( context, logical, allocation );
public List<PhysicalEntity> createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) {
return scannable.createGraph( context, logical, allocation );
}


Expand All @@ -103,8 +84,8 @@ public void dropGraph( Context context, AllocationGraph allocation ) {


@Override
public void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) {
Scannable.createCollectionSubstitute( scannable, context, logical, allocation );
public List<PhysicalEntity> createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) {
return Scannable.createCollectionSubstitute( scannable, context, logical, allocation );
}


Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/polypheny/db/adapter/Modifiable.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static AlgNode attachRelationalGraphUpdate( Modifiable modifiable, AlgNode provi
throw new GenericRuntimeException( "Graph insert of non-graph elements is not possible." );
}
}
AlgRecordType updateRowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( "ROWCOUNT", 0, alg.getCluster().getTypeFactory().createPolyType( PolyType.BIGINT ) ) ) );
AlgRecordType updateRowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( -1L, "ROWCOUNT", 0, alg.getCluster().getTypeFactory().createPolyType( PolyType.BIGINT ) ) ) );
LogicalLpgTransformer transformer = new LogicalLpgTransformer( alg.getCluster(), alg.getTraitSet(), inputs, updateRowType, sequence, Modify.Operation.UPDATE );
return new LogicalStreamer( alg.getCluster(), alg.getTraitSet(), project, transformer );

Expand All @@ -111,7 +111,7 @@ static AlgNode attachRelationalGraphDelete( Modifiable modifiable, AlgNode provi
throw new GenericRuntimeException( "Graph delete of non-graph elements is not possible." );
}
}
AlgRecordType updateRowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( "ROWCOUNT", 0, alg.getCluster().getTypeFactory().createPolyType( PolyType.BIGINT ) ) ) );
AlgRecordType updateRowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( -1L, "ROWCOUNT", 0, alg.getCluster().getTypeFactory().createPolyType( PolyType.BIGINT ) ) ) );
LogicalLpgTransformer transformer = new LogicalLpgTransformer( alg.getCluster(), alg.getTraitSet(), inputs, updateRowType, sequence, Modify.Operation.DELETE );
return new LogicalStreamer( alg.getCluster(), alg.getTraitSet(), project, transformer );

Expand Down Expand Up @@ -160,7 +160,7 @@ static AlgNode attachRelationalRelatedInsert( Modifiable modifiable, AlgNode pro
throw new RuntimeException( "Graph insert of non-graph elements is not possible." );
}
}
AlgRecordType updateRowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( "ROWCOUNT", 0, alg.getCluster().getTypeFactory().createPolyType( PolyType.BIGINT ) ) ) );
AlgRecordType updateRowType = new AlgRecordType( List.of( new AlgDataTypeFieldImpl( -1L, "ROWCOUNT", 0, alg.getCluster().getTypeFactory().createPolyType( PolyType.BIGINT ) ) ) );
LogicalLpgTransformer transformer = new LogicalLpgTransformer( alg.getCluster(), alg.getTraitSet(), inputs, updateRowType, sequence, Modify.Operation.INSERT );
return new LogicalStreamer( alg.getCluster(), alg.getTraitSet(), provider, transformer );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.polypheny.db.catalog.entity.logical.LogicalGraph;
import org.polypheny.db.catalog.entity.logical.LogicalIndex;
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.prepare.Context;
import org.polypheny.db.tools.AlgBuilder;
Expand Down Expand Up @@ -92,14 +93,14 @@ public void updateColumnType( Context context, long allocId, LogicalColumn colum


@Override
public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) {
modifiable.createTable( context, logical, allocation );
public List<PhysicalEntity> createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) {
return modifiable.createTable( context, logical, allocation );
}


@Override
public void createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) {
Scannable.createGraphSubstitute( modifiable, context, logical, allocation );
public List<PhysicalEntity> createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) {
return Scannable.createGraphSubstitute( modifiable, context, logical, allocation );
}


Expand All @@ -110,9 +111,11 @@ public void dropGraph( Context context, AllocationGraph allocation ) {


@Override
public void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) {
public List<PhysicalEntity> createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) {
PhysicalTable physical = Scannable.createSubstitutionTable( modifiable, 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.addPhysical( allocation, physical );

return List.of( physical );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,24 @@ public AlgNode getDocumentScan( long allocId, AlgBuilder builder ) {


@Override
public void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) {
scannable.createTable( context, logical, allocation );
public List<PhysicalEntity> createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation ) {
return scannable.createTable( context, logical, allocation );
}


@Override
public List<PhysicalEntity> refreshTable( long allocId ) {
return scannable.refreshTable( allocId );
}


@Override
public void restoreTable( AllocationTable alloc, List<PhysicalEntity> entities ) {
scannable.restoreTable( alloc, entities );
}


@Override
public List<PhysicalEntity> refreshGraph( long allocId ) {
return Scannable.refreshGraphSubstitute( scannable, allocId );
}


@Override
public void restoreGraph( AllocationGraph alloc, List<PhysicalEntity> entities ) {
Scannable.restoreGraphSubstitute( scannable, alloc, entities );
}


@Override
public List<PhysicalEntity> refreshCollection( long allocId ) {
return Scannable.refreshCollectionSubstitution( scannable, allocId );
}


@Override
public void restoreCollection( AllocationCollection alloc, List<PhysicalEntity> entities ) {
Scannable.restoreCollectionSubstitute( scannable, alloc, entities );
Expand All @@ -102,8 +85,8 @@ public void dropTable( Context context, long allocId ) {


@Override
public void createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) {
Scannable.createGraphSubstitute( scannable, context, logical, allocation );
public List<PhysicalEntity> createGraph( Context context, LogicalGraph logical, AllocationGraph allocation ) {
return Scannable.createGraphSubstitute( scannable, context, logical, allocation );
}


Expand All @@ -114,8 +97,8 @@ public void dropGraph( Context context, AllocationGraph allocation ) {


@Override
public void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) {
Scannable.createCollectionSubstitute( scannable, context, logical, allocation );
public List<PhysicalEntity> createCollection( Context context, LogicalCollection logical, AllocationCollection allocation ) {
return Scannable.createCollectionSubstitute( scannable, context, logical, allocation );
}


Expand Down
37 changes: 11 additions & 26 deletions core/src/main/java/org/polypheny/db/adapter/Scannable.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ default AlgNode getDocumentScan( long allocId, AlgBuilder builder ) {
return builder.documentScan( entity ).build();
}

default void createTable( Context context, LogicalTableWrapper logical, List<AllocationTableWrapper> allocations ) {
default List<List<PhysicalEntity>> createTable( Context context, LogicalTableWrapper logical, List<AllocationTableWrapper> allocations ) {
List<List<PhysicalEntity>> entities = new ArrayList<>();
for ( AllocationTableWrapper allocation : allocations ) {
createTable( context, logical, allocation );
entities.add( createTable( context, logical, allocation ) );
}
return entities;
}

static AlgNode getDocumentScanSubstitute( Scannable scannable, long allocId, AlgBuilder builder ) {
Expand All @@ -127,31 +129,12 @@ static AlgNode getDocumentScanSubstitute( Scannable scannable, long allocId, Alg
return builder.build();
}

void createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation );

List<PhysicalEntity> refreshTable( long allocId );
List<PhysicalEntity> createTable( Context context, LogicalTableWrapper logical, AllocationTableWrapper allocation );

void restoreTable( AllocationTable alloc, List<PhysicalEntity> entities );

List<PhysicalEntity> refreshGraph( long allocId );

static List<PhysicalEntity> refreshGraphSubstitute( Scannable scannable, long allocId ) {
List<PhysicalEntity> physicals = scannable.getCatalog().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 );
return physicals;
}

void restoreGraph( AllocationGraph alloc, List<PhysicalEntity> entities );

List<PhysicalEntity> refreshCollection( long allocId );

static List<PhysicalEntity> refreshCollectionSubstitution( Scannable scannable, long allocId ) {
return scannable.refreshTable( scannable.getCatalog().getPhysicalsFromAllocs( allocId ).get( 0 ).allocationId );
}


void restoreCollection( AllocationCollection alloc, List<PhysicalEntity> entities );

Expand All @@ -163,9 +146,9 @@ static List<PhysicalEntity> refreshCollectionSubstitution( Scannable scannable,
* It comes with a substitution methods called by default and should be overwritten if the inheriting {@link DataStore}
* support the LPG data model.
*/
void createGraph( Context context, LogicalGraph logical, AllocationGraph allocation );
List<PhysicalEntity> createGraph( Context context, LogicalGraph logical, AllocationGraph allocation );

static void createGraphSubstitute( Scannable scannable, Context context, LogicalGraph logical, AllocationGraph allocation ) {
static List<PhysicalEntity> createGraphSubstitute( Scannable scannable, Context context, LogicalGraph logical, AllocationGraph allocation ) {
PhysicalTable node = createSubstitutionTable( scannable, context, logical, allocation, "_node_", List.of(
Triple.of( "id", GraphType.ID_SIZE, PolyType.VARCHAR ),
Triple.of( "label", GraphType.LABEL_SIZE, PolyType.VARCHAR ) ) );
Expand All @@ -187,6 +170,7 @@ static void createGraphSubstitute( Scannable scannable, Context context, Logical
Triple.of( "value", GraphType.VALUE_SIZE, PolyType.VARCHAR ) ) );

scannable.getCatalog().addPhysical( allocation, node, nProperties, edge, eProperties );
return List.of( node, nProperties, edge, eProperties );
}

/**
Expand All @@ -210,14 +194,15 @@ static void dropGraphSubstitute( Scannable scannable, Context context, Allocatio
* It comes with a substitution methods called by default and should be overwritten if the inheriting {@link DataStore}
* support the document data model natively.
*/
void createCollection( Context context, LogicalCollection logical, AllocationCollection allocation );
List<PhysicalEntity> createCollection( Context context, LogicalCollection logical, AllocationCollection allocation );

static void createCollectionSubstitute( Scannable scannable, Context context, LogicalCollection logical, AllocationCollection allocation ) {
static List<PhysicalEntity> createCollectionSubstitute( Scannable scannable, Context context, LogicalCollection logical, AllocationCollection allocation ) {
PhysicalTable doc = createSubstitutionTable( scannable, context, logical, allocation, "_doc_", List.of(
Triple.of( DocumentType.DOCUMENT_ID, DocumentType.DATA_SIZE, PolyType.VARCHAR ),
Triple.of( DocumentType.DOCUMENT_DATA, DocumentType.DATA_SIZE, PolyType.VARCHAR ) ) );

scannable.getCatalog().addPhysical( allocation, doc );
return List.of( doc );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public static AlgDataType deriveRowType( AlgDataTypeFactory typeFactory, final A
name = base + "_" + i++;
}
containedNames.add( name );
builder.add( name, null, booleanType );
builder.add( null, name, null, booleanType );
}
}
for ( Ord<AggregateCall> aggCall : Ord.zip( aggCalls ) ) {
Expand All @@ -363,7 +363,7 @@ public static AlgDataType deriveRowType( AlgDataTypeFactory typeFactory, final A
name = base + "_" + i++;
}
containedNames.add( name );
builder.add( name, null, aggCall.e.type );
builder.add( null, name, null, aggCall.e.type );
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static AlgDataType deriveCollectRowType( SingleAlg alg, String fieldName
assert childType.isStruct();
final AlgDataTypeFactory typeFactory = alg.getCluster().getTypeFactory();
AlgDataType ret = PolyTypeUtil.createMultisetType( typeFactory, childType, false );
ret = typeFactory.builder().add( fieldName, null, ret ).build();
ret = typeFactory.builder().add( null, fieldName, null, ret ).build();
return typeFactory.createTypeWithNullability( ret, false );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ public static AlgDataType deriveUncollectRowType( AlgNode alg, boolean withOrdin

for ( AlgDataTypeField field : fields ) {
if ( field.getType() instanceof MapPolyType ) {
builder.add( UnnestOperator.MAP_KEY_COLUMN_NAME, null, field.getType().unwrap( MapPolyType.class ).getKeyType() );
builder.add( UnnestOperator.MAP_VALUE_COLUMN_NAME, null, field.getType().unwrap( MapPolyType.class ).getValueType() );
builder.add( null, UnnestOperator.MAP_KEY_COLUMN_NAME, null, field.getType().unwrap( MapPolyType.class ).getKeyType() );
builder.add( null, UnnestOperator.MAP_VALUE_COLUMN_NAME, null, field.getType().unwrap( MapPolyType.class ).getValueType() );
} else {
AlgDataType ret = field.getType().getComponentType();
assert null != ret;
if ( ret.isStruct() ) {
builder.addAll( ret.getFieldList() );
} else {
// Element type is not a record. It may be a scalar type, say "INTEGER". Wrap it in a struct type.
builder.add( CoreUtil.deriveAliasFromOrdinal( field.getIndex() ), null, ret );
builder.add( null, CoreUtil.deriveAliasFromOrdinal( field.getIndex() ), null, ret );
}
}
}
Expand Down
Loading

0 comments on commit 1cbbd76

Please sign in to comment.