diff --git a/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentModify.java b/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentModify.java index ee4023c7cc..0fd76a34d7 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentModify.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentModify.java @@ -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; @@ -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 extends Modify implements DocumentAlg { @NonNull @@ -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 ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentProject.java b/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentProject.java index 691112e448..eb4ac5871c 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentProject.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentProject.java @@ -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; @@ -45,9 +42,6 @@ import org.polypheny.db.type.entity.PolyString; -@EqualsAndHashCode(callSuper = false) -@Value -@NonFinal public abstract class DocumentProject extends SingleAlg implements DocumentAlg { diff --git a/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentScan.java b/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentScan.java index eed155f42c..0c5c1bc05b 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/document/DocumentScan.java @@ -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; @@ -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 + "$"; diff --git a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelModify.java b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelModify.java index c5b7728c56..7d3fbbb7ab 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelModify.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelModify.java @@ -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 ) diff --git a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelScan.java b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelScan.java index 0ba768adc6..227705cba7 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/relational/RelScan.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/relational/RelScan.java @@ -104,7 +104,7 @@ public ImmutableList identity() { public AlgWriter explainTerms( AlgWriter pw ) { return super.explainTerms( pw ) .item( "table", entity.id ) - .item( "layer", entity.getCatalogType() ); + .item( "layer", entity.getLayer() ); } diff --git a/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentModify.java b/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentModify.java index 56833bdbea..0d64316819 100644 --- a/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentModify.java +++ b/core/src/main/java/org/polypheny/db/algebra/logical/document/LogicalDocumentModify.java @@ -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; @@ -31,8 +29,6 @@ import org.polypheny.db.rex.RexNode; @SuperBuilder(toBuilder = true) -@EqualsAndHashCode(callSuper = true) -@Value public class LogicalDocumentModify extends DocumentModify implements RelationalTransformable { /** diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/AllocationToPhysicalModifyRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/AllocationToPhysicalModifyRule.java index 95ac1771ec..cb7660a028 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/AllocationToPhysicalModifyRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/AllocationToPhysicalModifyRule.java @@ -43,7 +43,7 @@ public AllocationToPhysicalModifyRule( Class> modify ) { private static boolean canApply( Modify r ) { - return r.entity.getCatalogType() == State.ALLOCATION; + return r.entity.getLayer() == State.ALLOCATION; } diff --git a/core/src/main/java/org/polypheny/db/algebra/rules/ScanRule.java b/core/src/main/java/org/polypheny/db/algebra/rules/ScanRule.java index 50ed0e36de..657c339c51 100644 --- a/core/src/main/java/org/polypheny/db/algebra/rules/ScanRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/rules/ScanRule.java @@ -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; @@ -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; } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationEntity.java b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationEntity.java index 20d65bc09e..520148dba1 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationEntity.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/allocation/AllocationEntity.java @@ -68,7 +68,7 @@ protected AllocationEntity( } - public State getCatalogType() { + public State getLayer() { return State.ALLOCATION; } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java index aa3672ecc0..1838e19e96 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/logical/LogicalEntity.java @@ -42,7 +42,7 @@ public LogicalEntity( } - public State getCatalogType() { + public State getLayer() { return State.LOGICAL; } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalColumn.java b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalColumn.java index 2575ce5aa3..f6260e38e5 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalColumn.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalColumn.java @@ -155,7 +155,7 @@ public Expression asExpression() { @Override - public State getCatalogType() { + public State getLayer() { return State.PHYSICAL; } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalEntity.java b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalEntity.java index f2e4bf57c9..396f275956 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalEntity.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalEntity.java @@ -56,7 +56,7 @@ protected PhysicalEntity( long id, long allocationId, long logicalId, String nam @Override - public State getCatalogType() { + public State getLayer() { return State.PHYSICAL; } diff --git a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalField.java b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalField.java index 3d27bed400..3cc2e8132e 100644 --- a/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalField.java +++ b/core/src/main/java/org/polypheny/db/catalog/entity/physical/PhysicalField.java @@ -72,7 +72,7 @@ public Serializable[] getParameterArray() { @Override - public State getCatalogType() { + public State getLayer() { return State.PHYSICAL; } diff --git a/core/src/main/java/org/polypheny/db/catalog/refactor/CatalogType.java b/core/src/main/java/org/polypheny/db/catalog/refactor/CatalogType.java index c825479a3f..71c270688a 100644 --- a/core/src/main/java/org/polypheny/db/catalog/refactor/CatalogType.java +++ b/core/src/main/java/org/polypheny/db/catalog/refactor/CatalogType.java @@ -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 { diff --git a/core/src/main/java/org/polypheny/db/plan/AlgOptRule.java b/core/src/main/java/org/polypheny/db/plan/AlgOptRule.java index 5d4237d374..d81cf4f573 100644 --- a/core/src/main/java/org/polypheny/db/plan/AlgOptRule.java +++ b/core/src/main/java/org/polypheny/db/plan/AlgOptRule.java @@ -167,7 +167,7 @@ public static AlgOptRuleOperand operand( Class clazz, Alg * @param Class of relational expression to match * @return Operand that matches a relational expression that has a particular trait and predicate */ - public static AlgOptRuleOperand operandJ( Class clazz, AlgTrait trait, Predicate predicate, AlgOptRuleOperandChildren operandList ) { + public static AlgOptRuleOperand operandJ( Class clazz, AlgTrait trait, Predicate predicate, AlgOptRuleOperandChildren operandList ) { return new AlgOptRuleOperand( clazz, trait, predicate, operandList.policy, operandList.operands ); } @@ -177,7 +177,7 @@ public static AlgOptRuleOperand operandJ( Class clazz, Al */ @SuppressWarnings("Guava") @Deprecated // to be removed before 2.0 - public static AlgOptRuleOperand operand( Class clazz, AlgTrait trait, com.google.common.base.Predicate predicate, AlgOptRuleOperandChildren operandList ) { + public static AlgOptRuleOperand operand( Class clazz, AlgTrait trait, com.google.common.base.Predicate predicate, AlgOptRuleOperandChildren operandList ) { return operandJ( clazz, trait, (Predicate) predicate::apply, operandList ); } @@ -193,14 +193,14 @@ public static AlgOptRuleOperand operand( Class clazz, Alg * @param Class of relational expression to match * @return Operand */ - public static AlgOptRuleOperand operandJ( Class clazz, AlgTrait trait, Predicate predicate, AlgOptRuleOperand first, AlgOptRuleOperand... rest ) { + public static AlgOptRuleOperand operandJ( Class clazz, AlgTrait trait, Predicate predicate, AlgOptRuleOperand first, AlgOptRuleOperand... rest ) { return operandJ( clazz, trait, predicate, some( first, rest ) ); } @SuppressWarnings("Guava") @Deprecated // to be removed before 2.0 - public static AlgOptRuleOperand operand( Class clazz, AlgTrait trait, com.google.common.base.Predicate predicate, AlgOptRuleOperand first, AlgOptRuleOperand... rest ) { + public static AlgOptRuleOperand operand( Class clazz, AlgTrait trait, com.google.common.base.Predicate predicate, AlgOptRuleOperand first, AlgOptRuleOperand... rest ) { return operandJ( clazz, trait, (Predicate) predicate::apply, first, rest ); } diff --git a/core/src/main/java/org/polypheny/db/tools/Programs.java b/core/src/main/java/org/polypheny/db/tools/Programs.java index 74ec319f82..4c461c608b 100644 --- a/core/src/main/java/org/polypheny/db/tools/Programs.java +++ b/core/src/main/java/org/polypheny/db/tools/Programs.java @@ -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"; diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoEntity.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoEntity.java index 1af4acbc4a..b923b39277 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoEntity.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/MongoEntity.java @@ -167,7 +167,7 @@ public AlgProtoDataType buildProto() { public String toString() { - return "MongoTable {" + physical.name + "}"; + return "MongoEntity {" + physical.name + "}"; } diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoDocumentModify.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoDocumentModify.java index 6254169360..ec147b4f59 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoDocumentModify.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoDocumentModify.java @@ -62,6 +62,7 @@ public void implement( Implementor implementor ) { switch ( this.getOperation() ) { case INSERT: handleInsert( implementor, ((MongoDocuments) input) ); + break; case UPDATE: handleUpdate( implementor ); break; @@ -84,6 +85,19 @@ private void handleUpdate( Implementor implementor ) { } + @Override + public AlgNode copy( AlgTraitSet traitSet, List 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() diff --git a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoRules.java b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoRules.java index 9bfcfa8691..c25be286e4 100644 --- a/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoRules.java +++ b/plugins/mongodb-adapter/src/main/java/org/polypheny/db/adapter/mongodb/rules/MongoRules.java @@ -687,7 +687,7 @@ private MongoDocumentProjectRule() { && !containsIncompatible( project ), Convention.NONE, MongoAlg.CONVENTION, - "MongoDocumentProjectRule" ); + MongoDocumentProjectRule.class.getSimpleName() ); } @@ -904,7 +904,7 @@ private static class MongoDocumentModificationRule extends MongoConverterRule { @Override public AlgNode convert( AlgNode alg ) { - final DocumentModify modify = (DocumentModify) alg; + final DocumentModify modify = (DocumentModify) alg; Optional oModifiableCollection = modify.entity.unwrap( ModifiableTable.class ); if ( oModifiableCollection.isEmpty() ) { return null; @@ -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, @@ -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(), @@ -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,