Skip to content

Commit

Permalink
Merge branch 'refactor' of https://github.com/polypheny/Polypheny-DB
Browse files Browse the repository at this point in the history
…into backup-development
  • Loading branch information
flurfis committed Nov 3, 2023
2 parents 3aafba8 + b4bdba1 commit ffe2477
Show file tree
Hide file tree
Showing 22 changed files with 199 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public interface AllocationRelationalCatalog extends AllocationCatalog {
* @param partitionType partition Type of the added partition
* @return The id of the created partitionGroup
*/
AllocationPartitionGroup addPartitionGroup( long tableId, String partitionGroupName, long namespaceId, PartitionType partitionType, long numberOfInternalPartitions, List<String> effectivePartitionGroupQualifier, boolean isUnbound );
AllocationPartitionGroup addPartitionGroup( long tableId, String partitionGroupName, long namespaceId, PartitionType partitionType, long numberOfInternalPartitions, boolean isUnbound );

/**
* Should only be called from mergePartitions(). Deletes a single partition and all references.
Expand All @@ -89,13 +89,15 @@ public interface AllocationRelationalCatalog extends AllocationCatalog {
*
* @param tableId The unique id of the table
* @param namespaceId The unique id of the table
* @param groupId
* @param name
* @param placementType
* @param role
* @param qualifiers
* @param partitionType
* @return The id of the created partition
*/
AllocationPartition addPartition( long tableId, long namespaceId, @Nullable String name, boolean isUnbound, PlacementType placementType, DataPlacementRole role, PartitionType partitionType );
AllocationPartition addPartition( long tableId, long namespaceId, long groupId, @Nullable String name, boolean isUnbound, PlacementType placementType, DataPlacementRole role, List<String> qualifiers, PartitionType partitionType );

/**
* Deletes a single partition and all references.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
package org.polypheny.db.catalog.entity.allocation;


import com.google.common.collect.ImmutableList;
import io.activej.serializer.annotations.Deserialize;
import io.activej.serializer.annotations.Serialize;
import io.activej.serializer.annotations.SerializeNullable;
import java.io.Serializable;
import java.util.List;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.NonNull;
import lombok.Value;
import org.jetbrains.annotations.NotNull;
import org.polypheny.db.catalog.entity.CatalogObject;
import org.polypheny.db.catalog.logistic.DataPlacementRole;
import org.polypheny.db.catalog.logistic.PartitionType;
Expand All @@ -45,6 +47,9 @@ public class AllocationPartition implements CatalogObject {
@Serialize
public long logicalEntityId;

@Serialize
public long groupId;

@Getter
@Serialize
@SerializeNullable
Expand Down Expand Up @@ -75,24 +80,32 @@ public class AllocationPartition implements CatalogObject {
public DataPlacementRole role;
@Serialize
public boolean isUnbound;
@Serialize
@NotNull
public List<String> qualifiers;


public AllocationPartition(
@Deserialize("id") final long id,
@Deserialize("namespaceId") long namespaceId,
@Deserialize("logicalEntityId") final long logicalEntityId,
@Deserialize("placementType") @NonNull final PlacementType placementType,
@Deserialize("groupId") final long groupId,
@Deserialize("placementType") @NotNull final PlacementType placementType,
@Deserialize("name") @Nullable final String name,
@Deserialize("role") DataPlacementRole role,
@Deserialize("isUnbound") final boolean isUnbound,
@Deserialize("partitionType") PartitionType partitionType ) {
@Deserialize("qualifiers") @Nullable final List<String> qualifiers,
@Deserialize("partitionType") final PartitionType partitionType ) {
this.namespaceId = namespaceId;
this.logicalEntityId = logicalEntityId;
this.placementType = placementType;
this.partitionType = partitionType;
this.groupId = groupId;
this.id = id;
this.role = role;
this.isUnbound = isUnbound;
this.name = name;
this.qualifiers = qualifiers == null ? List.of() : ImmutableList.copyOf( qualifiers );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

package org.polypheny.db.catalog.entity.allocation;

import com.google.common.collect.ImmutableList;
import io.activej.serializer.annotations.Deserialize;
import io.activej.serializer.annotations.Serialize;
import io.activej.serializer.annotations.SerializeNullable;
import java.io.Serializable;
import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jetbrains.annotations.Nullable;
Expand All @@ -37,36 +35,30 @@ public class AllocationPartitionGroup implements CatalogObject {
@Serialize
public long id;
@Serialize
@SerializeNullable
public String name;
@Serialize
public long logicalEntityId;
@Serialize
public long namespaceId;
@Serialize
@SerializeNullable
public ImmutableList<String> partitionQualifiers;
@Serialize
public boolean isUnbound;
@Serialize
public long partitionKey;


public AllocationPartitionGroup(
@Deserialize("id") final long id,
@Deserialize("name") final String name,
@Deserialize("name") @Nullable final String name,
@Deserialize("logicalEntityId") final long logicalEntityId,
@Deserialize("namespaceId") final long namespaceId,
@Deserialize("partitionKey") final long partitionKey,
@Deserialize("partitionQualifiers") @Nullable final List<String> partitionQualifiers,
@Deserialize("isUnbound") final boolean isUnbound ) {
this.id = id;
this.name = name;
this.logicalEntityId = logicalEntityId;
this.namespaceId = namespaceId;
this.partitionKey = partitionKey;
// TODO @HENNLO Although the qualifiers are now part of CatalogPartitions, it might be a good improvement to
// accumulate all qualifiers of all internal partitions here to speed up query time.
this.partitionQualifiers = partitionQualifiers == null ? null : ImmutableList.copyOf( partitionQualifiers );
this.isUnbound = isUnbound;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public List<String> getReferencedKeyColumnNames() {
// Used for creating ResultSets
public List<CatalogForeignKeyColumn> getCatalogForeignKeyColumns() {
int i = 1;
LinkedList<CatalogForeignKeyColumn> list = new LinkedList<>();
List<CatalogForeignKeyColumn> list = new LinkedList<>();
List<String> referencedKeyColumnNames = getReferencedKeyColumnNames();
for ( String columnName : getColumnNames() ) {
list.add( new CatalogForeignKeyColumn( tableId, name, i, referencedKeyColumnNames.get( i - 1 ), columnName ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public LogicalPrimaryKey( @Deserialize("key") @NonNull final LogicalKey key ) {
// Used for creating ResultSets
public List<CatalogPrimaryKeyColumn> getCatalogPrimaryKeyColumns() {
int i = 1;
LinkedList<CatalogPrimaryKeyColumn> list = new LinkedList<>();
List<CatalogPrimaryKeyColumn> list = new LinkedList<>();
for ( String columnName : getColumnNames() ) {
list.add( new CatalogPrimaryKeyColumn( id, i++, columnName ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void removePlacement( long placementId ) {
@Override
public AllocationPartition addPartition( LogicalCollection collection, PartitionType partitionType, String name ) {
long id = idBuilder.getNewPartitionId();
AllocationPartition partition = new AllocationPartition( id, namespace.id, collection.id, PlacementType.MANUAL, name, DataPlacementRole.UP_TO_DATE, false, partitionType );
AllocationPartition partition = new AllocationPartition( id, namespace.id, collection.id, -1, PlacementType.MANUAL, name, DataPlacementRole.UP_TO_DATE, false, null, partitionType );
partitions.put( id, partition );
change();
return partition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void removePlacement( long id ) {
@Override
public AllocationPartition addPartition( LogicalGraph graph, PartitionType partitionType, String name ) {
long id = idBuilder.getNewPartitionId();
AllocationPartition partition = new AllocationPartition( id, namespace.id, graph.id, PlacementType.MANUAL, name, DataPlacementRole.UP_TO_DATE, false, partitionType );
AllocationPartition partition = new AllocationPartition( id, namespace.id, graph.id, -1, PlacementType.MANUAL, name, DataPlacementRole.UP_TO_DATE, false, null, partitionType );
partitions.put( id, partition );
change();
return partition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void updateColumnPlacementType( long placementId, long columnId, Placemen


@Override
public AllocationPartitionGroup addPartitionGroup( long tableId, String partitionGroupName, long namespaceId, PartitionType partitionType, long numberOfInternalPartitions, List<String> effectivePartitionGroupQualifier, boolean isUnbound ) {
public AllocationPartitionGroup addPartitionGroup( long tableId, String partitionGroupName, long namespaceId, PartitionType partitionType, long numberOfInternalPartitions, boolean isUnbound ) {
long id = idBuilder.getNewGroupId();
if ( log.isDebugEnabled() ) {
log.debug( "Creating partitionGroup of type '{}' with id '{}'", partitionType, id );
Expand All @@ -173,7 +173,6 @@ public AllocationPartitionGroup addPartitionGroup( long tableId, String partitio
tableId,
namespaceId,
0,
null,
isUnbound );

partitionGroups.put( id, partitionGroup );
Expand All @@ -188,7 +187,7 @@ public void deletePartitionGroup( long groupId ) {


@Override
public AllocationPartition addPartition( long tableId, long namespaceId, @Nullable String name, boolean isUnbound, PlacementType placementType, DataPlacementRole role, PartitionType partitionType ) {
public AllocationPartition addPartition( long tableId, long namespaceId, long groupId, @Nullable String name, boolean isUnbound, PlacementType placementType, DataPlacementRole role, List<String> qualifiers, PartitionType partitionType ) {
long id = idBuilder.getNewPartitionId();
if ( log.isDebugEnabled() ) {
log.debug( "Creating partition with id '{}'", id );
Expand All @@ -198,10 +197,12 @@ public AllocationPartition addPartition( long tableId, long namespaceId, @Nullab
id,
namespaceId,
tableId,
groupId,
placementType,
name,
role,
isUnbound,
qualifiers,
partitionType );

partitions.put( id, partition );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package org.polypheny.db.catalog.logistic;

import lombok.Getter;

@Getter
public enum PartitionType {
NONE( 0 ),
RANGE( 1 ),
Expand All @@ -32,11 +35,6 @@ public enum PartitionType {
}


public int getId() {
return id;
}


public static PartitionType getById( final int id ) {
for ( PartitionType t : values() ) {
if ( t.id == id ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,7 @@ public interface AllocSnapshot {
@NotNull
List<AllocationPartition> getPartitions();

@NotNull
List<AllocationPartition> getPartitionsFromGroup( long groupId );

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class AllocSnapshotImpl implements AllocSnapshot {
ImmutableMap<Pair<Long, Long>, AllocationPlacement> adapterLogicalToPlacement;
ImmutableMap<Long, List<AllocationEntity>> placementToPartitions;
ImmutableMap<Long, List<AllocationPlacement>> placementsOfColumn;
ImmutableMap<Long, List<AllocationPartition>> partitionsOfGroup;

ImmutableMap<Pair<Long, String>, AllocationPartition> entityPartitionNameToPartition;

Expand Down Expand Up @@ -146,6 +147,18 @@ public AllocSnapshotImpl( Map<Long, AllocationCatalog> allocationCatalogs, Map<L

this.entityPartitionNameToPartition = buildEntityPartitionNameToPartition();

this.partitionsOfGroup = buildPartitionsOfGroups();

}


private ImmutableMap<Long, List<AllocationPartition>> buildPartitionsOfGroups() {
Map<Long, List<AllocationPartition>> map = new HashMap<>();
for ( AllocationPartitionGroup group : groups.values() ) {
map.put( group.id, partitions.values().stream().filter( p -> p.groupId == group.id ).collect( Collectors.toList() ) );
}

return ImmutableMap.copyOf( map );
}


Expand Down Expand Up @@ -403,6 +416,7 @@ private ImmutableMap<Long, AllocationTable> buildTables( List<AllocationRelation
return columns.values().asList();
}


@Override
public @NonNull Optional<List<AllocationEntity>> getEntitiesOnAdapter( long id ) {
return Optional.ofNullable( allocsOnAdapters.get( id ) );
Expand Down Expand Up @@ -596,4 +610,10 @@ public Optional<AllocationPartition> getPartitionFromName( long logicalId, Strin
}


@Override
public @NotNull List<AllocationPartition> getPartitionsFromGroup( long groupId ) {
return Optional.ofNullable( partitionsOfGroup.get( groupId ) ).orElse( List.of() );
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.polypheny.db.rex.RexNode;
import org.polypheny.db.rex.RexShuttle;
import org.polypheny.db.transaction.Statement;
import org.polypheny.db.type.entity.PolyValue;


/**
Expand All @@ -36,7 +37,7 @@ public class WhereClauseVisitor extends RexShuttle {

private final Statement statement;
@Getter
private final List<Object> values = new ArrayList<>();
private final List<PolyValue> values = new ArrayList<>();
private final long partitionColumnIndex;
@Getter
protected boolean valueIdentified = false;
Expand All @@ -57,11 +58,11 @@ public RexNode visitCall( final RexCall call ) {

if ( call.operands.size() == 2 ) {
if ( call.op.getKind() == Kind.EQUALS ) {
Object value;
PolyValue value;
if ( call.operands.get( 0 ) instanceof RexIndexRef ) {
if ( ((RexIndexRef) call.operands.get( 0 )).getIndex() == partitionColumnIndex ) {
if ( call.operands.get( 1 ) instanceof RexLiteral ) {
value = ((RexLiteral) call.operands.get( 1 )).getValueForQueryParameterizer();
value = ((RexLiteral) call.operands.get( 1 )).value;
values.add( value );
valueIdentified = true;
} else if ( call.operands.get( 1 ) instanceof RexDynamicParam ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public AlgDataType createTypeWithCharsetAndCollation( AlgDataType type, Charset
@Override
public AlgDataType leastRestrictive( List<AlgDataType> types ) {
assert types != null;
assert types.size() >= 1;
assert !types.isEmpty();

AlgDataType type0 = types.get( 0 );
if ( type0.getPolyType() != null ) {
Expand Down
Loading

0 comments on commit ffe2477

Please sign in to comment.