Skip to content

Commit

Permalink
fixes for mongodb, and result iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Dec 3, 2023
1 parent 4888b60 commit 8b0d5c3
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
import com.mongodb.lang.Nullable;
import java.util.List;
import java.util.Map;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.Value;
import lombok.experimental.NonFinal;
import lombok.experimental.SuperBuilder;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.AlgWriter;
import org.polypheny.db.algebra.constant.Kind;
import org.polypheny.db.algebra.core.common.Modify;
import org.polypheny.db.algebra.type.AlgDataType;
Expand All @@ -36,10 +35,8 @@
import org.polypheny.db.rex.RexNode;
import org.polypheny.db.schema.trait.ModelTrait;

@EqualsAndHashCode(callSuper = true)
@Getter
@SuperBuilder(toBuilder = true)
@Value
@NonFinal
public abstract class DocumentModify<E extends Entity> extends Modify<E> implements DocumentAlg {

@NonNull
Expand Down Expand Up @@ -81,7 +78,19 @@ public AlgDataType deriveRowType() {

@Override
public String algCompareString() {
return "$" + getClass().getSimpleName() + "$" + operation + "$" + input.algCompareString() + "$" + updates.hashCode() + "$" + removes.hashCode() + "$" + renames.hashCode();
return "$" + getClass().getSimpleName() + "$" + entity.id + "$" + entity.getLayer() + "$" + operation + "$" + input.algCompareString() + "$" + updates.hashCode() + "$" + removes.hashCode() + "$" + renames.hashCode();
}


@Override
public AlgWriter explainTerms( AlgWriter pw ) {
return super.explainTerms( pw )
.item( "entity", entity.id )
.item( "layer", entity.getLayer() )
.item( "operation", getOperation() )
.item( "updates", updates )
.item( "removes", removes )
.item( "renames", renames );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
import java.util.Map.Entry;
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.experimental.NonFinal;
import org.jetbrains.annotations.NotNull;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.SingleAlg;
Expand All @@ -45,9 +42,6 @@
import org.polypheny.db.type.entity.PolyString;


@EqualsAndHashCode(callSuper = false)
@Value
@NonFinal
public abstract class DocumentProject extends SingleAlg implements DocumentAlg {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.polypheny.db.algebra.core.document;

import org.polypheny.db.algebra.AlgWriter;
import org.polypheny.db.algebra.core.common.Scan;
import org.polypheny.db.algebra.type.DocumentType;
import org.polypheny.db.catalog.entity.Entity;
Expand All @@ -37,6 +38,14 @@ public DocumentScan( AlgOptCluster cluster, AlgTraitSet traitSet, E collection )
}


@Override
public AlgWriter explainTerms( AlgWriter pw ) {
return super.explainTerms( pw )
.item( "table", entity.id )
.item( "layer", entity.getLayer() );
}


@Override
public String algCompareString() {
return "$" + getClass().getSimpleName() + "$" + entity.id + "$";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public AlgDataType getExpectedInputRowType( int ordinalInParent ) {
public AlgWriter explainTerms( AlgWriter pw ) {
return super.explainTerms( pw )
.item( "entity", entity.id )
.item( "layer", entity.getCatalogType() )
.item( "layer", entity.getLayer() )
.item( "operation", getOperation() )
.itemIf( "updateColumns", updateColumns, updateColumns != null )
.itemIf( "sourceExpressions", sourceExpressions, sourceExpressions != null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public ImmutableList<Integer> identity() {
public AlgWriter explainTerms( AlgWriter pw ) {
return super.explainTerms( pw )
.item( "table", entity.id )
.item( "layer", entity.getCatalogType() );
.item( "layer", entity.getLayer() );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import java.util.List;
import java.util.Map;
import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.experimental.SuperBuilder;
import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.AlgShuttle;
Expand All @@ -31,8 +29,6 @@
import org.polypheny.db.rex.RexNode;

@SuperBuilder(toBuilder = true)
@EqualsAndHashCode(callSuper = true)
@Value
public class LogicalDocumentModify extends DocumentModify<Entity> implements RelationalTransformable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public AllocationToPhysicalModifyRule( Class<? extends Modify<?>> modify ) {


private static boolean canApply( Modify<?> r ) {
return r.entity.getCatalogType() == State.ALLOCATION;
return r.entity.getLayer() == State.ALLOCATION;
}


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

import org.polypheny.db.algebra.AlgNode;
import org.polypheny.db.algebra.core.AlgFactories;
import org.polypheny.db.algebra.core.common.Scan;
import org.polypheny.db.algebra.logical.relational.LogicalRelScan;
import org.polypheny.db.plan.AlgOptRule;
import org.polypheny.db.plan.AlgOptRuleCall;
import org.polypheny.db.plan.AlgTraitSet;
import org.polypheny.db.plan.Convention;
import org.polypheny.db.schema.types.TranslatableEntity;
import org.polypheny.db.tools.AlgBuilderFactory;

Expand All @@ -41,13 +43,13 @@ public class ScanRule extends AlgOptRule {
* @param algBuilderFactory Builder for relational expressions
*/
public ScanRule( AlgBuilderFactory algBuilderFactory ) {
super( operand( LogicalRelScan.class, any() ), algBuilderFactory, ScanRule.class.getSimpleName() );
super( operandJ( Scan.class, Convention.NONE, r -> true, any() ), algBuilderFactory, ScanRule.class.getSimpleName() );
}


@Override
public void onMatch( AlgOptRuleCall call ) {
final LogicalRelScan oldAlg = call.alg( 0 );
final Scan<?> oldAlg = call.alg( 0 );
if ( oldAlg.getEntity().unwrap( TranslatableEntity.class ).isEmpty() ) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected AllocationEntity(
}


public State getCatalogType() {
public State getLayer() {
return State.ALLOCATION;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public LogicalEntity(
}


public State getCatalogType() {
public State getLayer() {
return State.LOGICAL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public Expression asExpression() {


@Override
public State getCatalogType() {
public State getLayer() {
return State.PHYSICAL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected PhysicalEntity( long id, long allocationId, long logicalId, String nam


@Override
public State getCatalogType() {
public State getLayer() {
return State.PHYSICAL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Serializable[] getParameterArray() {


@Override
public State getCatalogType() {
public State getLayer() {
return State.PHYSICAL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

public interface CatalogType {

State getCatalogType();
State getLayer();

default boolean isLogical() {
return getCatalogType() == State.LOGICAL;
return getLayer() == State.LOGICAL;
}

default boolean isAllocation() {
return getCatalogType() == State.ALLOCATION;
return getLayer() == State.ALLOCATION;
}

default boolean isPhysical() {
return getCatalogType() == State.PHYSICAL;
return getLayer() == State.PHYSICAL;
}

enum State {
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/org/polypheny/db/plan/AlgOptRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static <R extends AlgNode> AlgOptRuleOperand operand( Class<R> clazz, Alg
* @param <R> Class of relational expression to match
* @return Operand that matches a relational expression that has a particular trait and predicate
*/
public static <R extends AlgNode> AlgOptRuleOperand operandJ( Class<R> clazz, AlgTrait trait, Predicate<? super R> predicate, AlgOptRuleOperandChildren operandList ) {
public static <R extends AlgNode> AlgOptRuleOperand operandJ( Class<R> clazz, AlgTrait<?> trait, Predicate<? super R> predicate, AlgOptRuleOperandChildren operandList ) {
return new AlgOptRuleOperand( clazz, trait, predicate, operandList.policy, operandList.operands );
}

Expand All @@ -177,7 +177,7 @@ public static <R extends AlgNode> AlgOptRuleOperand operandJ( Class<R> clazz, Al
*/
@SuppressWarnings("Guava")
@Deprecated // to be removed before 2.0
public static <R extends AlgNode> AlgOptRuleOperand operand( Class<R> clazz, AlgTrait trait, com.google.common.base.Predicate<? super R> predicate, AlgOptRuleOperandChildren operandList ) {
public static <R extends AlgNode> AlgOptRuleOperand operand( Class<R> clazz, AlgTrait<?> trait, com.google.common.base.Predicate<? super R> predicate, AlgOptRuleOperandChildren operandList ) {
return operandJ( clazz, trait, (Predicate<? super R>) predicate::apply, operandList );
}

Expand All @@ -193,14 +193,14 @@ public static <R extends AlgNode> AlgOptRuleOperand operand( Class<R> clazz, Alg
* @param <R> Class of relational expression to match
* @return Operand
*/
public static <R extends AlgNode> AlgOptRuleOperand operandJ( Class<R> clazz, AlgTrait trait, Predicate<? super R> predicate, AlgOptRuleOperand first, AlgOptRuleOperand... rest ) {
public static <R extends AlgNode> AlgOptRuleOperand operandJ( Class<R> clazz, AlgTrait<?> trait, Predicate<? super R> predicate, AlgOptRuleOperand first, AlgOptRuleOperand... rest ) {
return operandJ( clazz, trait, predicate, some( first, rest ) );
}


@SuppressWarnings("Guava")
@Deprecated // to be removed before 2.0
public static <R extends AlgNode> AlgOptRuleOperand operand( Class<R> clazz, AlgTrait trait, com.google.common.base.Predicate<? super R> predicate, AlgOptRuleOperand first, AlgOptRuleOperand... rest ) {
public static <R extends AlgNode> AlgOptRuleOperand operand( Class<R> clazz, AlgTrait<?> trait, com.google.common.base.Predicate<? super R> predicate, AlgOptRuleOperand first, AlgOptRuleOperand... rest ) {
return operandJ( clazz, trait, (Predicate<? super R>) predicate::apply, first, rest );
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/polypheny/db/tools/Programs.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,13 @@ public static Program standard( AlgMetadataProvider metadataProvider ) {
( planner, alg, requiredOutputTraits ) -> {
planner.setRoot( alg );

final AlgNode rootRel2 =
final AlgNode rootAlg2 =
alg.getTraitSet().equals( requiredOutputTraits )
? alg
: planner.changeTraits( alg, requiredOutputTraits );
assert rootRel2 != null;
assert rootAlg2 != null;

planner.setRoot( rootRel2 );
planner.setRoot( rootAlg2 );
final AlgOptPlanner planner2 = planner.chooseDelegate();
final AlgNode rootRel3 = planner2.findBestExp();
assert rootRel3 != null : "could not implement exp";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public AlgProtoDataType buildProto() {


public String toString() {
return "MongoTable {" + physical.name + "}";
return "MongoEntity {" + physical.name + "}";
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void implement( Implementor implementor ) {
switch ( this.getOperation() ) {
case INSERT:
handleInsert( implementor, ((MongoDocuments) input) );
break;
case UPDATE:
handleUpdate( implementor );
break;
Expand All @@ -84,6 +85,19 @@ private void handleUpdate( Implementor implementor ) {
}


@Override
public AlgNode copy( AlgTraitSet traitSet, List<AlgNode> inputs ) {
return new MongoDocumentModify(
traitSet,
entity,
inputs.get( 0 ),
operation,
updates,
removes,
renames );
}


private void handleInsert( Implementor implementor, MongoDocuments documents ) {
implementor.operations = documents.documents
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ private MongoDocumentProjectRule() {
&& !containsIncompatible( project ),
Convention.NONE,
MongoAlg.CONVENTION,
"MongoDocumentProjectRule" );
MongoDocumentProjectRule.class.getSimpleName() );
}


Expand Down Expand Up @@ -904,7 +904,7 @@ private static class MongoDocumentModificationRule extends MongoConverterRule {

@Override
public AlgNode convert( AlgNode alg ) {
final DocumentModify<MongoEntity> modify = (DocumentModify<MongoEntity>) alg;
final DocumentModify<?> modify = (DocumentModify<?>) alg;
Optional<ModifiableTable> oModifiableCollection = modify.entity.unwrap( ModifiableTable.class );
if ( oModifiableCollection.isEmpty() ) {
return null;
Expand All @@ -916,7 +916,7 @@ public AlgNode convert( AlgNode alg ) {
final AlgTraitSet traitSet = modify.getTraitSet().replace( out );
return new MongoDocumentModify(
traitSet,
modify.entity,
modify.entity.unwrap( MongoEntity.class ).get(),
AlgOptRule.convert( modify.getInput(), traitSet ),
modify.operation,
modify.updates,
Expand Down Expand Up @@ -950,8 +950,7 @@ private static boolean supported( LogicalAggregate aggregate ) {
@Override
public AlgNode convert( AlgNode alg ) {
final LogicalAggregate agg = (LogicalAggregate) alg;
final AlgTraitSet traitSet =
agg.getTraitSet().replace( out );
final AlgTraitSet traitSet = agg.getTraitSet().replace( out );
try {
return new MongoAggregate(
alg.getCluster(),
Expand All @@ -977,15 +976,14 @@ private static class MongoDocumentAggregateRule extends MongoConverterRule {

private MongoDocumentAggregateRule() {
super( LogicalDocumentAggregate.class, r -> true, Convention.NONE, MongoAlg.CONVENTION,
"MongoDocumentAggregateRule" );
MongoDocumentAggregate.class.getSimpleName() );
}


@Override
public AlgNode convert( AlgNode alg ) {
final LogicalDocumentAggregate agg = (LogicalDocumentAggregate) alg;
final AlgTraitSet traitSet =
agg.getTraitSet().replace( out );
final AlgTraitSet traitSet = agg.getTraitSet().replace( out );
return new MongoDocumentAggregate(
alg.getCluster(),
traitSet,
Expand Down

0 comments on commit 8b0d5c3

Please sign in to comment.