Skip to content

Commit

Permalink
Minor improvements (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
gartens authored Feb 13, 2025
1 parent f989ee3 commit 4f68ea5
Show file tree
Hide file tree
Showing 56 changed files with 174 additions and 303 deletions.
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 @@ -260,7 +260,7 @@ static List<AlgNode> attachPreparedGraphEdgeModifyInsert( Modifiable modifiable,


static Modify<?> getModify( Entity table, AlgNode input, Operation operation, List<String> updateList, List<RexNode> sourceList ) {
return table.unwrap( ModifiableTable.class ).orElseThrow().toModificationTable( input.getCluster(), input.getTraitSet(), table, input, operation, updateList, sourceList );
return table.unwrapOrThrow( ModifiableTable.class ).toModificationTable( input.getCluster(), input.getTraitSet(), table, input, operation, updateList, sourceList );
}


Expand Down Expand Up @@ -349,7 +349,7 @@ static AlgNode getDocModifySubstitute( Modifiable modifiable, long allocId, Docu

builder.project( DocumentType.ofRelational().getFields().stream().map( f -> new RexDynamicParam( f.getType(), f.getIndex() ) ).toList(), DocumentType.ofRelational().getFieldNames() );

AlgNode collector = oTable.orElseThrow().unwrap( ModifiableTable.class ).orElseThrow().toModificationTable(
AlgNode collector = oTable.orElseThrow().unwrapOrThrow( ModifiableTable.class ).toModificationTable(
modify.getCluster(),
modify.getTraitSet(),
oTable.get(),
Expand All @@ -367,7 +367,7 @@ static AlgNode getDocModifySubstitute( Modifiable modifiable, long allocId, Docu
LogicalStreamer.attachFilter( oTable.get(), builder, provider.getCluster().getRexBuilder(), List.of( 0 ) );

AlgNode collector = builder.build();
collector = oTable.get().unwrap( ModifiableTable.class ).orElseThrow().toModificationTable(
collector = oTable.get().unwrapOrThrow( ModifiableTable.class ).toModificationTable(
modify.getCluster(),
modify.getTraitSet(),
oTable.get(),
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/polypheny/db/adapter/Scannable.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
public interface Scannable {

static PhysicalTable createSubstitutionTable( Scannable scannable, Context context, LogicalEntity logical, AllocationEntity allocation, String name, List<ColumnContext> nameLength, int amountPk ) {
return createSubstitutionEntity( scannable, context, logical, allocation, name, nameLength, amountPk ).unwrap( PhysicalTable.class ).orElseThrow();
return createSubstitutionEntity( scannable, context, logical, allocation, name, nameLength, amountPk ).unwrapOrThrow( PhysicalTable.class );
}

static PhysicalEntity createSubstitutionEntity( Scannable scannable, Context context, LogicalEntity logical, AllocationEntity allocation, String name, List<ColumnContext> columnsInformations, int amountPk ) {
Expand Down Expand Up @@ -137,7 +137,7 @@ default List<List<PhysicalEntity>> createTable( Context context, LogicalTableWra

static AlgNode getDocumentScanSubstitute( Scannable scannable, long allocId, AlgBuilder builder ) {
builder.clear();
PhysicalEntity table = scannable.getCatalog().getPhysicalsFromAllocs( allocId ).get( 0 ).unwrap( PhysicalEntity.class ).orElseThrow();
PhysicalEntity table = scannable.getCatalog().getPhysicalsFromAllocs( allocId ).get( 0 ).unwrapOrThrow( PhysicalEntity.class );
builder.relScan( table );
AlgDataType rowType = DocumentType.ofId();
builder.transform( ModelTrait.DOCUMENT, rowType, false, null );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public void rewriteAlg( LogicalDocumentSort alg ) {
public void rewriteAlg( LogicalDocumentScan scan ) {
AlgNode alg = scan;
if ( scan.entity.isPhysical() ) {
alg = scan.entity.unwrap( TranslatableEntity.class ).orElseThrow().toAlg( cluster, scan.traitSet );
alg = scan.entity.unwrapOrThrow( TranslatableEntity.class ).toAlg( cluster, scan.traitSet );
}
setNewForOldAlg( scan, alg );
}
Expand Down Expand Up @@ -527,7 +527,7 @@ public void rewriteAlg( LogicalLpgModify alg ) {
public void rewriteAlg( LogicalLpgScan scan ) {
AlgNode alg = scan;
if ( scan.entity.isPhysical() ) {
alg = scan.entity.unwrap( TranslatableEntity.class ).orElseThrow().toAlg( cluster, scan.traitSet );
alg = scan.entity.unwrapOrThrow( TranslatableEntity.class ).toAlg( cluster, scan.traitSet );
}
setNewForOldAlg( scan, alg );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface RelationalTransformable {


static Modify<?> getModify( Entity entity, AlgNode alg, Operation operation ) {
return entity.unwrap( ModifiableTable.class ).orElseThrow().toModificationTable( alg.getCluster(), alg.getTraitSet(), entity, alg, operation, null, null );
return entity.unwrapOrThrow( ModifiableTable.class ).toModificationTable( alg.getCluster(), alg.getTraitSet(), entity, alg, operation, null, null );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public EnumerableScan( AlgCluster cluster, AlgTraitSet traitSet, PhysicalTable t
* Creates an EnumerableScan.
*/
public static EnumerableScan create( AlgCluster cluster, Entity entity ) {
PhysicalTable oPhysicalTable = entity.unwrap( PhysicalTable.class ).orElseThrow();
PhysicalTable oPhysicalTable = entity.unwrapOrThrow( PhysicalTable.class );
Class<?> elementType = EnumerableScan.deduceElementType( oPhysicalTable );
final AlgTraitSet traitSet =
cluster.traitSetOf( EnumerableConvention.INSTANCE )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static EnforcementInformation getControl( AlgNode node, Statement statem
throw new GenericRuntimeException( "The tree did no conform, while generating the constraint enforcement query!" );
}

final LogicalTable table = modify.entity.unwrap( LogicalTable.class ).orElseThrow();
final LogicalTable table = modify.entity.unwrapOrThrow( LogicalTable.class );

AlgBuilder builder = AlgBuilder.create( statement );
final RexBuilder rexBuilder = modify.getCluster().getRexBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static void attachFilter( AlgNode modify, AlgBuilder algBuilder, RexBuild

if ( modify.getEntity().unwrap( PhysicalTable.class ).isPresent() ) {
indexes = new ArrayList<>();
for ( long fieldId : modify.getEntity().unwrap( PhysicalTable.class ).orElseThrow().getUniqueFieldIds() ) {
for ( long fieldId : modify.getEntity().unwrap( PhysicalTable.class ).get().getUniqueFieldIds() ) {
indexes.add( modify.getEntity().getTupleType().getFieldIds().indexOf( fieldId ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static AlgNode create( AlgCluster cluster, final Entity entity ) {
return ImmutableList.of();
} );

LogicalView logicalView = entity.unwrap( LogicalView.class ).orElseThrow();
LogicalView logicalView = entity.unwrapOrThrow( LogicalView.class );
AlgCollation algCollation = Catalog.snapshot().rel().getCollationInfo( entity.id );

return new LogicalRelViewScan( cluster, traitSet, entity, logicalView.prepareView( cluster ), algCollation );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void onMatch( AlgOptRuleCall call ) {
}
for ( Ord<AggregateCall> aggCall : Ord.zip( aggregate.getAggCallList() ) ) {
final AggFunction aggregation = aggCall.e.getAggregation();
final SplittableAggFunction splitter = aggregation.unwrap( SplittableAggFunction.class ).orElseThrow();
final SplittableAggFunction splitter = aggregation.unwrapOrThrow( SplittableAggFunction.class );
if ( !aggCall.e.getArgList().isEmpty() && fieldSet.contains( ImmutableBitSet.of( aggCall.e.getArgList() ) ) ) {
final RexNode singleton = splitter.singleton( rexBuilder, joinInput.getTupleType(), aggCall.e.transform( mapping ) );

Expand All @@ -218,7 +218,7 @@ public void onMatch( AlgOptRuleCall call ) {
final int newGroupKeyCount = belowAggregateKey.cardinality();
for ( Ord<AggregateCall> aggCall : Ord.zip( aggregate.getAggCallList() ) ) {
final AggFunction aggregation = aggCall.e.getAggregation();
final SplittableAggFunction splitter = aggregation.unwrap( SplittableAggFunction.class ).orElseThrow();
final SplittableAggFunction splitter = aggregation.unwrapOrThrow( SplittableAggFunction.class );
final AggregateCall call1;
if ( fieldSet.contains( ImmutableBitSet.of( aggCall.e.getArgList() ) ) ) {
final AggregateCall splitCall = splitter.split( aggCall.e, mapping );
Expand Down Expand Up @@ -260,7 +260,7 @@ public void onMatch( AlgOptRuleCall call ) {
final List<RexNode> projects = new ArrayList<>( rexBuilder.identityProjects( algBuilder.peek().getTupleType() ) );
for ( Ord<AggregateCall> aggCall : Ord.zip( aggregate.getAggCallList() ) ) {
final AggFunction aggregation = aggCall.e.getAggregation();
final SplittableAggFunction splitter = aggregation.unwrap( SplittableAggFunction.class ).orElseThrow();
final SplittableAggFunction splitter = aggregation.unwrapOrThrow( SplittableAggFunction.class );
final Integer leftSubTotal = sides.get( 0 ).split.get( aggCall.i );
final Integer rightSubTotal = sides.get( 1 ).split.get( aggCall.i );
newAggCalls.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private SemiJoin findSemiJoinIndexByCost( LoptMultiJoin multiJoin, List<RexNode>

// Find the best index
final List<Integer> bestKeyOrder = new ArrayList<>();
LcsScan tmpFactRel = (LcsScan) factTable.unwrap( TranslatableEntity.class ).orElseThrow().toAlg( factAlg.getCluster(), factAlg.getTraitSet() );
LcsScan tmpFactRel = (LcsScan) factTable.unwrapOrThrow( TranslatableEntity.class ).toAlg( factAlg.getCluster(), factAlg.getTraitSet() );

LcsIndexOptimizer indexOptimizer = new LcsIndexOptimizer( tmpFactRel );
FemLocalIndex bestIndex =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void renameLogicalColumn( long id, String newFieldName ) {
List<PhysicalColumn> updates = new ArrayList<>();
for ( PhysicalField field : fields.values() ) {
if ( field.id == id ) {
updates.add( field.unwrap( PhysicalColumn.class ).orElseThrow().toBuilder().logicalName( newFieldName ).build() );
updates.add( field.unwrapOrThrow( PhysicalColumn.class ).toBuilder().logicalName( newFieldName ).build() );
}
}
for ( PhysicalColumn u : updates ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public static boolean canHandle( Entity entity ) {
@Override
public Enumerable<PolyValue[]> bind( DataContext dataContext ) {
// TODO: filterable and projectable
return entity.unwrap( ScannableEntity.class ).orElseThrow().scan( dataContext );
return entity.unwrapOrThrow( ScannableEntity.class ).scan( dataContext );
}


Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/polypheny/db/prepare/Prepare.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected AlgRoot optimize( AlgRoot root ) {
public void visit( AlgNode node, int ordinal, AlgNode parent ) {
if ( node instanceof RelScan ) {
final AlgCluster cluster = node.getCluster();
final AlgNode r = node.getEntity().unwrap( TranslatableEntity.class ).orElseThrow().toAlg( cluster, node.getTraitSet() );
final AlgNode r = node.getEntity().unwrapOrThrow( TranslatableEntity.class ).toAlg( cluster, node.getTraitSet() );
planner.registerClass( r );
}
super.visit( node, ordinal, parent );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ AlgNode toAlg( Queryable<T> queryable ) {
return alg;
}
if ( queryable instanceof AbstractEntityQueryable<T, ?> tableQueryable ) {
final QueryableEntity table = tableQueryable.entity.unwrap( QueryableEntity.class ).orElseThrow();
final QueryableEntity table = tableQueryable.entity.unwrapOrThrow( QueryableEntity.class );

if ( table instanceof TranslatableEntity ) {
return ((TranslatableEntity) table).toAlg( translator.cluster, translator.cluster.traitSet() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,12 @@ public AlgNode visit( LogicalRelScan scan ) {


private static long getLogicalId( Scan<?> scan ) {
return scan.entity.isLogical() ? scan.entity.id : scan.entity.unwrap( AllocationEntity.class ).orElseThrow().getLogicalId();
return scan.entity.isLogical() ? scan.entity.id : scan.entity.unwrapOrThrow( AllocationEntity.class ).getLogicalId();
}


private static long getLogicalId( Modify<?> modify ) {
return modify.entity.isLogical() ? modify.entity.id : modify.entity.unwrap( AllocationEntity.class ).orElseThrow().getLogicalId();
return modify.entity.isLogical() ? modify.entity.id : modify.entity.unwrapOrThrow( AllocationEntity.class ).getLogicalId();
}


Expand Down Expand Up @@ -463,7 +463,7 @@ private void getPartitioningInfo( LogicalRelFilter filter ) {
return;
}

handleIfPartitioned( filter, table.unwrap( LogicalTable.class ).orElseThrow() );
handleIfPartitioned( filter, table.unwrap( LogicalTable.class ).get() );
}


Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/polypheny/db/rex/RexBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ private RexLiteral makeMap( Map<Object, Object> value, AlgDataType type, boolean
final Map<RexNode, RexNode> map = value
.entrySet()
.stream()
.collect( Collectors.toMap( e -> makeLiteral( e.getKey(), mapType.unwrap( MapPolyType.class ).orElseThrow().getKeyType(), allowCast ), e -> makeLiteral( e.getValue(), mapType.unwrap( MapPolyType.class ).orElseThrow().getValueType(), allowCast ) ) );
.collect( Collectors.toMap( e -> makeLiteral( e.getKey(), mapType.unwrapOrThrow( MapPolyType.class ).getKeyType(), allowCast ), e -> makeLiteral( e.getValue(), mapType.unwrapOrThrow( MapPolyType.class ).getValueType(), allowCast ) ) );

return makeMap( type, map );
}
Expand Down
9 changes: 6 additions & 3 deletions core/src/main/java/org/polypheny/db/routing/DmlRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import java.util.List;
import org.jetbrains.annotations.Nullable;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.logical.common.LogicalBatchIterator;
import org.polypheny.db.algebra.logical.common.LogicalConditionalExecute;
import org.polypheny.db.algebra.logical.common.LogicalConstraintEnforcer;
import org.polypheny.db.algebra.logical.document.LogicalDocumentModify;
import org.polypheny.db.algebra.logical.lpg.LogicalLpgModify;
import org.polypheny.db.algebra.logical.relational.LogicalRelModify;
Expand All @@ -39,11 +42,11 @@ public interface DmlRouter {
/**
* Routes conditional executes and directly returns a RelNode.
*/
AlgNode handleConditionalExecute( AlgNode node, RoutingContext context );
LogicalConditionalExecute handleConditionalExecute( LogicalConditionalExecute node, RoutingContext context );

AlgNode handleConstraintEnforcer( AlgNode alg, RoutingContext context );
LogicalConstraintEnforcer handleConstraintEnforcer( LogicalConstraintEnforcer alg, RoutingContext context );

AlgNode handleBatchIterator( AlgNode alg, RoutingContext context );
LogicalBatchIterator handleBatchIterator( LogicalBatchIterator alg, RoutingContext context );

AlgNode routeDocumentDml( LogicalDocumentModify alg, Statement statement, @Nullable AllocationEntity target, @Nullable List<Long> excludedPlacements );

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/polypheny/db/schema/Schemas.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static Enumerable<Row<PolyValue>> queryableRow( DataContext root, Class<O
*/
public static Queryable<PolyValue[]> queryable( DataContext root, Snapshot snapshot, String entityName ) {
LogicalTable table = snapshot.rel().getTable( null, entityName ).orElseThrow();
return table.unwrap( QueryableEntity.class ).orElseThrow().asQueryable( root, snapshot );
return table.unwrapOrThrow( QueryableEntity.class ).asQueryable( root, snapshot );
}


Expand Down
37 changes: 17 additions & 20 deletions core/src/main/java/org/polypheny/db/type/PolyTypeFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,18 @@ private AlgDataType leastRestrictiveByCast( List<AlgDataType> types ) {
@Override
public AlgDataType createTypeWithNullability( final AlgDataType type, final boolean nullable ) {
final AlgDataType newType;
if ( type instanceof BasicPolyType ) {
newType = ((BasicPolyType) type).createWithNullability( nullable );
} else if ( type instanceof MapPolyType ) {
newType = copyMapType( type, nullable );
} else if ( type instanceof ArrayType ) {
newType = copyArrayType( type, nullable );
} else if ( type instanceof MultisetPolyType ) {
newType = copyMultisetType( type, nullable );
} else if ( type instanceof IntervalPolyType ) {
newType = copyIntervalType( type, nullable );
} else if ( type instanceof ObjectPolyType ) {
newType = copyObjectType( type, nullable );
if ( type instanceof BasicPolyType basicPolyType) {
newType = basicPolyType.createWithNullability( nullable );
} else if ( type instanceof MapPolyType mapPolyType ) {
newType = copyMapType( mapPolyType, nullable );
} else if ( type instanceof ArrayType arrayType ) {
newType = copyArrayType( arrayType, nullable );
} else if ( type instanceof MultisetPolyType multisetPolyType ) {
newType = copyMultisetType( multisetPolyType, nullable );
} else if ( type instanceof IntervalPolyType intervalPolyType ) {
newType = copyIntervalType( intervalPolyType, nullable );
} else if ( type instanceof ObjectPolyType objectPolyType ) {
newType = copyObjectType( objectPolyType, nullable );
} else {
return super.createTypeWithNullability( type, nullable );
}
Expand Down Expand Up @@ -482,19 +482,18 @@ private AlgDataType createDoublePrecisionType() {
}


private AlgDataType copyMultisetType( AlgDataType type, boolean nullable ) {
MultisetPolyType mt = (MultisetPolyType) type;
private AlgDataType copyMultisetType( MultisetPolyType mt, boolean nullable ) {
AlgDataType elementType = copyType( mt.getComponentType() );
return new MultisetPolyType( elementType, nullable );
}


private AlgDataType copyIntervalType( AlgDataType type, boolean nullable ) {
private AlgDataType copyIntervalType( IntervalPolyType type, boolean nullable ) {
return new IntervalPolyType( typeSystem, type.getIntervalQualifier(), nullable );
}


private AlgDataType copyObjectType( AlgDataType type, boolean nullable ) {
private AlgDataType copyObjectType( ObjectPolyType type, boolean nullable ) {
return new ObjectPolyType(
type.getPolyType(),
nullable,
Expand All @@ -503,15 +502,13 @@ private AlgDataType copyObjectType( AlgDataType type, boolean nullable ) {
}


private AlgDataType copyArrayType( AlgDataType type, boolean nullable ) {
ArrayType at = (ArrayType) type;
private AlgDataType copyArrayType( ArrayType at, boolean nullable ) {
AlgDataType elementType = copyType( at.getComponentType() );
return new ArrayType( elementType, nullable, at.getCardinality(), at.getDimension() );
}


private AlgDataType copyMapType( AlgDataType type, boolean nullable ) {
MapPolyType mt = type.unwrap( MapPolyType.class ).orElseThrow();
private AlgDataType copyMapType( MapPolyType mt, boolean nullable ) {
AlgDataType keyType = copyType( mt.getKeyType() );
AlgDataType valueType = copyType( mt.getValueType() );
return new MapPolyType( keyType, valueType, nullable );
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/polypheny/db/view/ViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public AlgNode checkNode( AlgNode other ) {
return expandViewNode( other );
} else */
if ( doesSubstituteOrderBy && other instanceof LogicalRelScan ) {
LogicalTable catalogTable = other.getEntity().unwrap( LogicalTable.class ).orElseThrow();
LogicalTable catalogTable = other.getEntity().unwrapOrThrow( LogicalTable.class );
if ( catalogTable.entityType == EntityType.MATERIALIZED_VIEW && ((LogicalMaterializedView) catalogTable).isOrdered() ) {
return orderMaterialized( other );
}
Expand Down
Loading

0 comments on commit 4f68ea5

Please sign in to comment.