Skip to content

Commit

Permalink
multiple renamings, adjustment to mongodb store
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Nov 27, 2023
1 parent b5c21cc commit 6bc401a
Show file tree
Hide file tree
Showing 125 changed files with 524 additions and 732 deletions.
18 changes: 9 additions & 9 deletions core/src/main/java/org/polypheny/db/adapter/Modifiable.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.polypheny.db.algebra.type.DocumentType;
import org.polypheny.db.algebra.type.GraphType;
import org.polypheny.db.catalog.Catalog;
import org.polypheny.db.catalog.entity.LogicalEntity;
import org.polypheny.db.catalog.entity.Entity;
import org.polypheny.db.catalog.entity.allocation.AllocationCollection;
import org.polypheny.db.catalog.entity.allocation.AllocationGraph;
import org.polypheny.db.catalog.entity.allocation.AllocationTable;
Expand All @@ -73,7 +73,7 @@
public interface Modifiable extends Scannable {


static AlgNode attachRelationalGraphUpdate( Modifiable modifiable, AlgNode provider, LogicalLpgModify alg, AlgBuilder builder, LogicalEntity nodesTable, LogicalEntity nodePropertiesTable, LogicalEntity edgesTable, LogicalEntity edgePropertiesTable ) {
static AlgNode attachRelationalGraphUpdate( Modifiable modifiable, AlgNode provider, LogicalLpgModify alg, AlgBuilder builder, Entity nodesTable, Entity nodePropertiesTable, Entity edgesTable, Entity edgePropertiesTable ) {
AlgNode project = new LogicalLpgProject( alg.getCluster(), alg.getTraitSet(), alg.getInput(), alg.operations, alg.ids );

List<AlgNode> inputs = new ArrayList<>();
Expand All @@ -96,7 +96,7 @@ static AlgNode attachRelationalGraphUpdate( Modifiable modifiable, AlgNode provi

}

static AlgNode attachRelationalGraphDelete( Modifiable modifiable, AlgNode provider, LogicalLpgModify alg, AlgBuilder algBuilder, LogicalEntity nodesTable, LogicalEntity nodePropertiesTable, LogicalEntity edgesTable, LogicalEntity edgePropertiesTable ) {
static AlgNode attachRelationalGraphDelete( Modifiable modifiable, AlgNode provider, LogicalLpgModify alg, AlgBuilder algBuilder, Entity nodesTable, Entity nodePropertiesTable, Entity edgesTable, Entity edgePropertiesTable ) {
AlgNode project = new LogicalLpgProject( alg.getCluster(), alg.getTraitSet(), alg.getInput(), alg.operations, alg.ids );

List<AlgNode> inputs = new ArrayList<>();
Expand All @@ -117,7 +117,7 @@ static AlgNode attachRelationalGraphDelete( Modifiable modifiable, AlgNode provi

}

static List<AlgNode> attachPreparedGraphNodeModifyDelete( Modifiable modifiable, AlgOptCluster cluster, LogicalEntity nodesTable, LogicalEntity nodePropertiesTable, AlgBuilder algBuilder ) {
static List<AlgNode> attachPreparedGraphNodeModifyDelete( Modifiable modifiable, AlgOptCluster cluster, Entity nodesTable, Entity nodePropertiesTable, AlgBuilder algBuilder ) {
RexBuilder rexBuilder = algBuilder.getRexBuilder();
AlgDataTypeFactory typeFactory = rexBuilder.getTypeFactory();

Expand Down Expand Up @@ -146,7 +146,7 @@ static List<AlgNode> attachPreparedGraphNodeModifyDelete( Modifiable modifiable,
return inputs;
}

static AlgNode attachRelationalRelatedInsert( Modifiable modifiable, AlgNode provider, LogicalLpgModify alg, AlgBuilder algBuilder, LogicalEntity nodesTable, LogicalEntity nodePropertiesTable, LogicalEntity edgesTable, LogicalEntity edgePropertiesTable ) {
static AlgNode attachRelationalRelatedInsert( Modifiable modifiable, AlgNode provider, LogicalLpgModify alg, AlgBuilder algBuilder, Entity nodesTable, Entity nodePropertiesTable, Entity edgesTable, Entity edgePropertiesTable ) {

List<AlgNode> inputs = new ArrayList<>();
List<PolyType> sequence = new ArrayList<>();
Expand All @@ -165,7 +165,7 @@ static AlgNode attachRelationalRelatedInsert( Modifiable modifiable, AlgNode pro
return new LogicalStreamer( alg.getCluster(), alg.getTraitSet(), provider, transformer );
}

static List<AlgNode> attachPreparedGraphNodeModifyInsert( Modifiable modifiable, AlgOptCluster cluster, LogicalEntity nodesTable, LogicalEntity nodePropertiesTable, AlgBuilder algBuilder ) {
static List<AlgNode> attachPreparedGraphNodeModifyInsert( Modifiable modifiable, AlgOptCluster cluster, Entity nodesTable, Entity nodePropertiesTable, AlgBuilder algBuilder ) {
RexBuilder rexBuilder = algBuilder.getRexBuilder();
AlgDataTypeFactory typeFactory = rexBuilder.getTypeFactory();

Expand All @@ -192,7 +192,7 @@ static List<AlgNode> attachPreparedGraphNodeModifyInsert( Modifiable modifiable,
return inputs;
}

static List<AlgNode> attachPreparedGraphEdgeModifyDelete( Modifiable modifiable, AlgOptCluster cluster, LogicalEntity edgesTable, LogicalEntity edgePropertiesTable, AlgBuilder algBuilder ) {
static List<AlgNode> attachPreparedGraphEdgeModifyDelete( Modifiable modifiable, AlgOptCluster cluster, Entity edgesTable, Entity edgePropertiesTable, AlgBuilder algBuilder ) {
RexBuilder rexBuilder = algBuilder.getRexBuilder();
AlgDataTypeFactory typeFactory = rexBuilder.getTypeFactory();

Expand All @@ -218,7 +218,7 @@ static List<AlgNode> attachPreparedGraphEdgeModifyDelete( Modifiable modifiable,
return inputs;
}

static List<AlgNode> attachPreparedGraphEdgeModifyInsert( Modifiable modifiable, AlgOptCluster cluster, LogicalEntity edgesTable, LogicalEntity edgePropertiesTable, AlgBuilder algBuilder ) {
static List<AlgNode> attachPreparedGraphEdgeModifyInsert( Modifiable modifiable, AlgOptCluster cluster, Entity edgesTable, Entity edgePropertiesTable, AlgBuilder algBuilder ) {
RexBuilder rexBuilder = algBuilder.getRexBuilder();
AlgDataTypeFactory typeFactory = rexBuilder.getTypeFactory();

Expand Down Expand Up @@ -248,7 +248,7 @@ static List<AlgNode> attachPreparedGraphEdgeModifyInsert( Modifiable modifiable,

}

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

Expand Down
151 changes: 8 additions & 143 deletions core/src/main/java/org/polypheny/db/adapter/java/ReflectiveSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,19 @@
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.calcite.linq4j.Enumerable;
import org.apache.calcite.linq4j.Linq4j;
import org.apache.calcite.linq4j.function.Function1;
import org.apache.calcite.linq4j.tree.Primitive;
import org.apache.commons.lang3.NotImplementedException;
import org.polypheny.db.adapter.DataContext;
import org.polypheny.db.algebra.AlgReferentialConstraint;
import org.polypheny.db.algebra.type.AlgDataType;
import org.polypheny.db.algebra.type.AlgDataTypeFactory;
import org.polypheny.db.catalog.entity.LogicalEntity;
import org.polypheny.db.catalog.entity.logical.LogicalTable;
import org.polypheny.db.catalog.entity.Entity;
import org.polypheny.db.catalog.exceptions.GenericRuntimeException;
import org.polypheny.db.catalog.logistic.EntityType;
import org.polypheny.db.schema.Function;
import org.polypheny.db.schema.Namespace;
import org.polypheny.db.schema.Namespace.Schema;
import org.polypheny.db.schema.Statistic;
import org.polypheny.db.schema.Statistics;
import org.polypheny.db.schema.TableMacro;
import org.polypheny.db.schema.impl.AbstractNamespace;
import org.polypheny.db.schema.impl.ReflectiveFunctionBase;
import org.polypheny.db.schema.types.ScannableEntity;
import org.polypheny.db.schema.types.TranslatableEntity;
import org.polypheny.db.type.entity.PolyValue;


/**
Expand All @@ -77,7 +65,7 @@ public class ReflectiveSchema extends AbstractNamespace implements Schema {

private final Class clazz;
private Object target;
private Map<String, LogicalEntity> tableMap;
private Map<String, Entity> tableMap;
private Multimap<String, Function> functionMap;


Expand Down Expand Up @@ -111,25 +99,25 @@ public Object getTarget() {


@Override
public Map<String, LogicalEntity> getTables() {
public Map<String, Entity> getTables() {
if ( tableMap == null ) {
tableMap = createTableMap();
}
return tableMap;
}


private Map<String, LogicalEntity> createTableMap() {
final ImmutableMap.Builder<String, LogicalEntity> builder = ImmutableMap.builder();
private Map<String, Entity> createTableMap() {
final ImmutableMap.Builder<String, Entity> builder = ImmutableMap.builder();
for ( Field field : clazz.getFields() ) {
final String fieldName = field.getName();
final LogicalEntity entity = fieldRelation( field );
final Entity entity = fieldRelation( field );
if ( entity == null ) {
continue;
}
builder.put( fieldName, entity );
}
Map<String, LogicalEntity> tableMap = builder.build();
Map<String, Entity> tableMap = builder.build();
// Unique-Key - Foreign-Key
for ( Field field : clazz.getFields() ) {
if ( AlgReferentialConstraint.class.isAssignableFrom( field.getType() ) ) {
Expand Down Expand Up @@ -177,7 +165,7 @@ private Multimap<String, Function> createFunctionMap() {
/**
* Returns a table based on a particular field of this schema. If the field is not of the right type to be a relation, returns null.
*/
private <T> LogicalEntity fieldRelation( final Field field ) {
private <T> Entity fieldRelation( final Field field ) {
final Type elementType = getElementType( field.getType() );
if ( elementType == null ) {
return null;
Expand Down Expand Up @@ -223,64 +211,6 @@ private static Enumerable<?> toEnumerable( final Object o ) {
}


/**
* Table that is implemented by reading from a Java object.
*/
@Slf4j
private static class ReflectiveEntity extends LogicalTable implements ScannableEntity {

private final Type elementType;
private final Enumerable<PolyValue[]> enumerable;


ReflectiveEntity( Type elementType, Enumerable<PolyValue[]> enumerable, Long id, Long partitionId, Long adapterId ) {
super( id, "test", -1, EntityType.ENTITY, null, false );
this.elementType = elementType;
this.enumerable = enumerable;
throw new NotImplementedException();
}


@Override
public Statistic getStatistic() {
return Statistics.UNKNOWN;
}


@Override
public Enumerable<PolyValue[]> scan( DataContext root ) {
if ( elementType == PolyValue[].class ) {
return enumerable;
} else {
//noinspection unchecked
//return enumerable.select( new FieldSelector( (Class<?>) elementType ) );

log.warn( "todo 23f23" );
return null;
}
}


@Override
public AlgDataType getRowType( AlgDataTypeFactory typeFactory ) {
return getRowType();
}


/*@Override
public <T> Queryable<T> asQueryable( DataContext dataContext, Snapshot snapshot, String tableName ) {
return new AbstractTableQueryable<T>( dataContext, snapshot, this, tableName ) {
@Override
@SuppressWarnings("unchecked")
public Enumerator<T> enumerator() {
return (Enumerator<T>) enumerable.enumerator();
}
};
}*/

}


/**
* Table macro based on a Java method.
*/
Expand Down Expand Up @@ -314,70 +244,5 @@ public TranslatableEntity apply( final List<Object> arguments ) {
}


/**
* Table based on a Java field.
*
* @param <T> element type
*/
private static class FieldEntity<T extends PolyValue> extends ReflectiveEntity {

private final Field field;
private Statistic statistic;


FieldEntity( Field field, Type elementType, Enumerable<PolyValue[]> enumerable, Long id, Long partitionId, Long adapterId ) {
this( field, elementType, enumerable, Statistics.UNKNOWN, id, partitionId, adapterId );
}


FieldEntity( Field field, Type elementType, Enumerable<PolyValue[]> enumerable, Statistic statistic, Long id, Long partitionId, Long adapterId ) {
super( elementType, enumerable, id, partitionId, adapterId );
this.field = field;
this.statistic = statistic;
}


public String toString() {
return "Relation {field=" + field.getName() + "}";
}


@Override
public Statistic getStatistic() {
return statistic;
}


}


/**
* Function that returns an array of a given object's field values.
*/
private static class FieldSelector implements Function1<Object, Object[]> {

private final Field[] fields;


FieldSelector( Class elementType ) {
this.fields = elementType.getFields();
}


@Override
public Object[] apply( Object o ) {
try {
final Object[] objects = new Object[fields.length];
for ( int i = 0; i < fields.length; i++ ) {
objects[i] = fields[i].get( o );
}
return objects;
} catch ( IllegalAccessException e ) {
throw new RuntimeException( e );
}
}

}

}

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.polypheny.db.algebra.metadata.Metadata;
import org.polypheny.db.algebra.metadata.MetadataFactory;
import org.polypheny.db.algebra.type.AlgDataType;
import org.polypheny.db.catalog.entity.LogicalEntity;
import org.polypheny.db.catalog.entity.Entity;
import org.polypheny.db.plan.AlgOptCluster;
import org.polypheny.db.plan.AlgOptCost;
import org.polypheny.db.plan.AlgOptPlanner;
Expand Down Expand Up @@ -389,7 +389,7 @@ public final String getDescription() {


@Override
public LogicalEntity getEntity() {
public Entity getEntity() {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/polypheny/db/algebra/AlgInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import java.util.List;
import org.polypheny.db.algebra.type.AlgDataType;
import org.polypheny.db.catalog.entity.LogicalEntity;
import org.polypheny.db.catalog.entity.Entity;
import org.polypheny.db.plan.AlgOptCluster;
import org.polypheny.db.plan.AlgTraitSet;
import org.polypheny.db.util.ImmutableBitSet;
Expand All @@ -51,7 +51,7 @@ public interface AlgInput {

AlgTraitSet getTraitSet();

LogicalEntity getEntity( String entity );
Entity getEntity( String entity );

/**
* Returns the input relational expression. Throws if there is not precisely one input.
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/polypheny/db/algebra/AlgNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.polypheny.db.algebra.metadata.AlgMetadataQuery;
import org.polypheny.db.algebra.metadata.Metadata;
import org.polypheny.db.algebra.type.AlgDataType;
import org.polypheny.db.catalog.entity.LogicalEntity;
import org.polypheny.db.catalog.entity.Entity;
import org.polypheny.db.catalog.logistic.DataModel;
import org.polypheny.db.plan.AlgImplementor;
import org.polypheny.db.plan.AlgOptCluster;
Expand Down Expand Up @@ -262,7 +262,7 @@ public interface AlgNode extends AlgOptNode, Cloneable {
*
* @return If this relational expression represents an access to a table, returns that table, otherwise returns null
*/
LogicalEntity getEntity();
Entity getEntity();

/**
* Returns the name of this relational expression's class, sans package name, for use in explain. For example, for a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
import org.polypheny.db.algebra.logical.relational.LogicalUnion;
import org.polypheny.db.algebra.logical.relational.LogicalValues;
import org.polypheny.db.algebra.type.AlgDataType;
import org.polypheny.db.catalog.entity.LogicalEntity;
import org.polypheny.db.catalog.entity.Entity;
import org.polypheny.db.catalog.logistic.EntityType;
import org.polypheny.db.plan.AlgOptCluster;
import org.polypheny.db.plan.Contexts;
Expand Down Expand Up @@ -537,7 +537,7 @@ public interface ScanFactory {
/**
* Creates a {@link RelScan}.
*/
AlgNode createScan( AlgOptCluster cluster, LogicalEntity entity );
AlgNode createScan( AlgOptCluster cluster, Entity entity );

}

Expand All @@ -548,7 +548,7 @@ public interface ScanFactory {
private static class ScanFactoryImpl implements ScanFactory {

@Override
public AlgNode createScan( AlgOptCluster cluster, LogicalEntity entity ) {
public AlgNode createScan( AlgOptCluster cluster, Entity entity ) {
// Check if RelOptTable contains a View, in this case a LogicalViewScan needs to be created
if ( entity.entityType == EntityType.VIEW ) {
return LogicalRelViewScan.create( cluster, entity );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import lombok.experimental.SuperBuilder;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.SingleAlg;
import org.polypheny.db.catalog.entity.LogicalEntity;
import org.polypheny.db.catalog.entity.Entity;
import org.polypheny.db.plan.AlgOptCluster;
import org.polypheny.db.plan.AlgTraitSet;

@SuperBuilder(toBuilder = true)
public abstract class Modify<E extends LogicalEntity> extends SingleAlg {
public abstract class Modify<E extends Entity> extends SingleAlg {

@Getter
public final E entity;
Expand Down
Loading

0 comments on commit 6bc401a

Please sign in to comment.