From 95eede7018f2fd9dab22cc88e7903f3719174d56 Mon Sep 17 00:00:00 2001 From: Tobias Hafner Date: Sat, 28 Dec 2024 15:44:09 +0100 Subject: [PATCH] Abstract identifier injection for different models --- .../db/algebra/core/common/Identifier.java | 3 + .../enumerable/EnumerableIdentifier.java | 160 ++++++++++++++++++ ...ule.java => EnumerableIdentifierRule.java} | 22 ++- .../enumerable/EnumerableRelIdentifier.java | 72 -------- .../algebra/enumerable/EnumerableRules.java | 8 +- .../document/EnumerableDocIdentifier.java | 73 -------- .../document/EnumerableDocIdentifierRule.java | 61 ------- .../lpg/EnumerableLpgIdentifier.java | 73 -------- .../lpg/EnumerableLpgIdentifierRule.java | 41 ----- .../org/polypheny/db/functions/Functions.java | 35 +--- .../org/polypheny/db/util/BuiltInMethod.java | 3 +- .../db/transaction/MockTransaction.java | 7 + 12 files changed, 191 insertions(+), 367 deletions(-) create mode 100644 core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifier.java rename core/src/main/java/org/polypheny/db/algebra/enumerable/{EnumerableRelIdentifierRule.java => EnumerableIdentifierRule.java} (54%) delete mode 100644 core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableRelIdentifier.java delete mode 100644 core/src/main/java/org/polypheny/db/algebra/enumerable/document/EnumerableDocIdentifier.java delete mode 100644 core/src/main/java/org/polypheny/db/algebra/enumerable/document/EnumerableDocIdentifierRule.java delete mode 100644 core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgIdentifier.java delete mode 100644 core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgIdentifierRule.java diff --git a/core/src/main/java/org/polypheny/db/algebra/core/common/Identifier.java b/core/src/main/java/org/polypheny/db/algebra/core/common/Identifier.java index aa5fee6949..9d54555413 100644 --- a/core/src/main/java/org/polypheny/db/algebra/core/common/Identifier.java +++ b/core/src/main/java/org/polypheny/db/algebra/core/common/Identifier.java @@ -20,11 +20,13 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.SingleAlg; import org.polypheny.db.catalog.entity.Entity; +import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.plan.AlgCluster; import org.polypheny.db.plan.AlgTraitSet; @Getter public abstract class Identifier extends SingleAlg { + protected final Entity entity; protected Identifier( AlgCluster cluster, AlgTraitSet traits, Entity entity, AlgNode input ) { @@ -32,6 +34,7 @@ protected Identifier( AlgCluster cluster, AlgTraitSet traits, Entity entity, Alg this.entity = entity; } + public String algCompareString() { return this.getClass().getSimpleName() + "$" + input.algCompareString() + "$" + diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifier.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifier.java new file mode 100644 index 0000000000..638dc1f555 --- /dev/null +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifier.java @@ -0,0 +1,160 @@ +/* + * Copyright 2019-2024 The Polypheny Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.polypheny.db.algebra.enumerable; + +import java.util.List; +import org.apache.calcite.linq4j.Enumerable; +import org.apache.calcite.linq4j.function.Function1; +import org.apache.calcite.linq4j.function.Function2; +import org.apache.calcite.linq4j.tree.BlockBuilder; +import org.apache.calcite.linq4j.tree.Expression; +import org.apache.calcite.linq4j.tree.Expressions; +import org.polypheny.db.algebra.AlgNode; +import org.polypheny.db.algebra.core.common.Identifier; +import org.polypheny.db.algebra.metadata.AlgMetadataQuery; +import org.polypheny.db.catalog.Catalog; +import org.polypheny.db.catalog.entity.Entity; +import org.polypheny.db.catalog.entity.logical.LogicalEntity; +import org.polypheny.db.plan.AlgCluster; +import org.polypheny.db.plan.AlgOptCost; +import org.polypheny.db.plan.AlgPlanner; +import org.polypheny.db.plan.AlgTraitSet; +import org.polypheny.db.transaction.locking.IdentifierUtils; +import org.polypheny.db.type.entity.PolyValue; +import org.polypheny.db.type.entity.document.PolyDocument; +import org.polypheny.db.type.entity.graph.GraphPropertyHolder; +import org.polypheny.db.type.entity.numerical.PolyLong; +import org.polypheny.db.util.BuiltInMethod; + +public class EnumerableIdentifier extends Identifier implements EnumerableAlg { + + protected EnumerableIdentifier( AlgCluster cluster, AlgTraitSet traits, Entity entity, AlgNode input ) { + super( cluster, traits, entity, input ); + assert getConvention() instanceof EnumerableConvention; + } + + + @Override + public AlgOptCost computeSelfCost( AlgPlanner planner, AlgMetadataQuery mq ) { + double dRows = mq.getTupleCount( getInput() ); + return planner.getCostFactory().makeCost( dRows, 0, 0 ); + } + + + @Override + public AlgNode copy( AlgTraitSet traitSet, List inputs ) { + return new EnumerableIdentifier( inputs.get( 0 ).getCluster(), traitSet, entity, inputs.get( 0 ) ); + } + + + @Override + public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { + final BlockBuilder builder = new BlockBuilder(); + final EnumerableAlg input = (EnumerableAlg) getInput(); + final Result result = implementor.visitChild( this, 0, input, Prefer.ANY ); + final PhysType physType = result.physType(); + + Expression input_ = builder.append( "input", result.block() ); + Expression entityId_ = Expressions.constant( entity.getId() ); + Expression identification_ = null; + switch ( input.getModel() ) { + case RELATIONAL -> { + Expression addRelIdentifiers_ = Expressions.call( EnumerableIdentifier.class, "addRelIdentifiers" ); + Expression addRelIdentifierWithId_ = Expressions.call( EnumerableIdentifier.class, "bindLogicalId", addRelIdentifiers_, entityId_ ); + identification_ = builder.append( "identification", Expressions.call( BuiltInMethod.PROCESS_AND_STREAM_RIGHT.method, input_, addRelIdentifierWithId_ ) ); + } + case DOCUMENT -> { + Expression addDocIdentifiers_ = Expressions.call( EnumerableIdentifier.class, "addDocIdentifiers" ); + Expression addDocIdentifierWithId_ = Expressions.call( EnumerableIdentifier.class, "bindLogicalId", addDocIdentifiers_, entityId_ ); + identification_ = builder.append( "identification", Expressions.call( BuiltInMethod.PROCESS_AND_STREAM_RIGHT.method, input_, addDocIdentifierWithId_ ) ); + } + case GRAPH -> { + Expression addLpgIdentifiers_ = Expressions.call( EnumerableIdentifier.class, "addLpgIdentifiers" ); + Expression addLpgIdentifiersWithId_ = Expressions.call( EnumerableIdentifier.class, "bindLogicalId", addLpgIdentifiers_, entityId_ ); + identification_ = builder.append( "identification", Expressions.call( BuiltInMethod.PROCESS_AND_STREAM_RIGHT.method, input_, addLpgIdentifiersWithId_ ) ); + } + } + assert identification_ != null; + builder.add( Expressions.return_( null, identification_ ) ); + return implementor.result( physType, builder.toBlock() ); + + } + + + public static Function1, Enumerable> bindLogicalId( + Function2, Long, Enumerable> function, + long logicalId ) { + return input -> function.apply( input, logicalId ); + } + + + public static Function2, Long, Enumerable> addRelIdentifiers() { + return ( input, logicalId ) -> { + LogicalEntity entity = Catalog.getInstance().getSnapshot() + .getLogicalEntity( logicalId ) + .orElseThrow(); + return input.select( row -> { + row[0] = entity.getEntryIdentifiers() + .getNextEntryIdentifier() + .getEntryIdentifierAsPolyLong(); + return row; + } ); + }; + } + + + public static Function2, Long, Enumerable> addDocIdentifiers() { + return ( input, logicalId ) -> { + LogicalEntity entity = Catalog.getInstance().getSnapshot() + .getLogicalEntity( logicalId ) + .orElseThrow(); + return input.select( row -> { + for ( PolyValue value : row ) { + PolyLong entryIdentifier = entity.getEntryIdentifiers() + .getNextEntryIdentifier() + .getEntryIdentifierAsPolyLong(); + if ( value instanceof PolyDocument ) { + ((PolyDocument) value).put( IdentifierUtils.getIdentifierKeyAsPolyString(), entryIdentifier ); + } + } + return row; + } ); + }; + } + + + public static Function2, Long, Enumerable> addLpgIdentifiers() { + return ( input, logicalId ) -> { + LogicalEntity entity = Catalog.getInstance().getSnapshot() + .getLogicalEntity( logicalId ) + .orElseThrow(); + return input.select( row -> { + for ( PolyValue value : row ) { + PolyLong entryIdentifier = entity.getEntryIdentifiers() + .getNextEntryIdentifier() + .getEntryIdentifierAsPolyLong(); + if ( value instanceof GraphPropertyHolder ) { + ((GraphPropertyHolder) value).getProperties() + .put( IdentifierUtils.getIdentifierKeyAsPolyString(), entryIdentifier ); + } + } + return row; + } ); + }; + } + +} diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableRelIdentifierRule.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifierRule.java similarity index 54% rename from core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableRelIdentifierRule.java rename to core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifierRule.java index b8e8782d0d..1057a63333 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableRelIdentifierRule.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableIdentifierRule.java @@ -18,24 +18,30 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.convert.ConverterRule; -import org.polypheny.db.algebra.core.AlgFactories; +import org.polypheny.db.algebra.core.common.Identifier; +import org.polypheny.db.algebra.logical.document.LogicalDocIdentifier; +import org.polypheny.db.algebra.logical.lpg.LogicalLpgIdentifier; import org.polypheny.db.algebra.logical.relational.LogicalRelIdentifier; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Convention; -public class EnumerableRelIdentifierRule extends ConverterRule { - - EnumerableRelIdentifierRule() { - super( LogicalRelIdentifier.class, Convention.NONE, EnumerableConvention.INSTANCE, "EnumerableRelIdentifierRule" ); - } +public class EnumerableIdentifierRule extends ConverterRule { + + public static final EnumerableIdentifierRule REL_INSTANCE = new EnumerableIdentifierRule( LogicalRelIdentifier.class ); + public static final EnumerableIdentifierRule DOC_INSTANCE = new EnumerableIdentifierRule( LogicalDocIdentifier.class ); + public static final EnumerableIdentifierRule GRAPH_INSTANCE = new EnumerableIdentifierRule( LogicalLpgIdentifier.class ); + private EnumerableIdentifierRule( Class identifier ) { + super( identifier, Convention.NONE, EnumerableConvention.INSTANCE, "Enumerable" + identifier.getSimpleName() + "Rule" ); + } + @Override public AlgNode convert( AlgNode alg ) { - final LogicalRelIdentifier identifier = (LogicalRelIdentifier) alg; + final Identifier identifier = (Identifier) alg; final AlgTraitSet traits = identifier.getTraitSet().replace( EnumerableConvention.INSTANCE ); final AlgNode input = convert(identifier.getInput(), identifier.getInput().getTraitSet().replace( EnumerableConvention.INSTANCE )); - return new EnumerableRelIdentifier( identifier.getCluster(), traits, identifier.getEntity(), input ); + return new EnumerableIdentifier( identifier.getCluster(), traits, identifier.getEntity(), input ); } } diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableRelIdentifier.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableRelIdentifier.java deleted file mode 100644 index f526b6efb9..0000000000 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableRelIdentifier.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2019-2024 The Polypheny Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.polypheny.db.algebra.enumerable; - -import java.util.List; -import org.apache.calcite.linq4j.tree.BlockBuilder; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; -import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.algebra.core.common.Identifier; -import org.polypheny.db.algebra.metadata.AlgMetadataQuery; -import org.polypheny.db.catalog.entity.Entity; -import org.polypheny.db.plan.AlgCluster; -import org.polypheny.db.plan.AlgOptCost; -import org.polypheny.db.plan.AlgPlanner; -import org.polypheny.db.plan.AlgTraitSet; -import org.polypheny.db.util.BuiltInMethod; - -public class EnumerableRelIdentifier extends Identifier implements EnumerableAlg { - - protected EnumerableRelIdentifier( AlgCluster cluster, AlgTraitSet traits, Entity entity, AlgNode input ) { - super( cluster, traits, entity, input ); - assert getConvention() instanceof EnumerableConvention; - } - - - @Override - public AlgOptCost computeSelfCost( AlgPlanner planner, AlgMetadataQuery mq ) { - double dRows = mq.getTupleCount( getInput() ); - return planner.getCostFactory().makeCost( dRows, 0, 0 ); - } - - - @Override - public AlgNode copy( AlgTraitSet traitSet, List inputs ) { - return new EnumerableRelIdentifier( inputs.get(0).getCluster(), traitSet, entity, inputs.get( 0 ) ); - } - - - - @Override - public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { - final BlockBuilder builder = new BlockBuilder(); - final EnumerableAlg input = (EnumerableAlg) getInput(); - final Result result = implementor.visitChild( this, 0, input, Prefer.ANY ); - final PhysType physType = result.physType(); - - Expression input_ = builder.append( "input", result.block() ); - Expression entity_ = Expressions.constant(entity.getId()); - Expression identification_ = builder.append( "identification", Expressions.call( BuiltInMethod.ADD_REL_IDENTIFIERS.method, input_, entity_ ) ); - - builder.add( Expressions.return_( null, identification_ ) ); - - return implementor.result( physType, builder.toBlock() ); - - } - -} diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableRules.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableRules.java index aebddbc0f7..e210e3bbf3 100644 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableRules.java +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/EnumerableRules.java @@ -43,10 +43,8 @@ import org.polypheny.db.algebra.enumerable.common.EnumerableConstraintEnforcerRule; import org.polypheny.db.algebra.enumerable.common.EnumerableContextSwitcherRule; import org.polypheny.db.algebra.enumerable.common.EnumerableModifyCollectRule; -import org.polypheny.db.algebra.enumerable.document.EnumerableDocIdentifierRule; import org.polypheny.db.algebra.enumerable.document.EnumerableDocumentUnwindRule; import org.polypheny.db.algebra.enumerable.document.EnumerableDocumentValuesRule; -import org.polypheny.db.algebra.enumerable.lpg.EnumerableLpgIdentifierRule; import org.polypheny.db.algebra.enumerable.lpg.EnumerableLpgMatchRule; import org.polypheny.db.algebra.enumerable.lpg.EnumerableLpgTransformerRule; import org.polypheny.db.algebra.enumerable.lpg.EnumerableLpgValuesRule; @@ -77,11 +75,11 @@ private EnumerableRules() { } - public static final EnumerableRelIdentifierRule ENUMERABLE_REL_IDENTIFIER_RULE = new EnumerableRelIdentifierRule(); + public static final EnumerableIdentifierRule ENUMERABLE_REL_IDENTIFIER_RULE = EnumerableIdentifierRule.REL_INSTANCE; - public static final EnumerableDocIdentifierRule ENUMERABLE_DOC_IDENTIFIER_RULE = new EnumerableDocIdentifierRule(); + public static final EnumerableIdentifierRule ENUMERABLE_DOC_IDENTIFIER_RULE = EnumerableIdentifierRule.DOC_INSTANCE; - public static final EnumerableLpgIdentifierRule ENUMERABLE_LPG_IDENTIFIER_RULE = new EnumerableLpgIdentifierRule(); + public static final EnumerableIdentifierRule ENUMERABLE_LPG_IDENTIFIER_RULE = EnumerableIdentifierRule.GRAPH_INSTANCE; public static final EnumerableConditionalExecuteRule ENUMERABLE_CONDITIONAL_EXECUTE_RULE = new EnumerableConditionalExecuteRule(); diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/document/EnumerableDocIdentifier.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/document/EnumerableDocIdentifier.java deleted file mode 100644 index 6ec811285e..0000000000 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/document/EnumerableDocIdentifier.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2019-2024 The Polypheny Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.polypheny.db.algebra.enumerable.document; - -import java.util.List; -import org.apache.calcite.linq4j.tree.BlockBuilder; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; -import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.algebra.core.common.Identifier; -import org.polypheny.db.algebra.enumerable.EnumerableAlg; -import org.polypheny.db.algebra.enumerable.EnumerableAlgImplementor; -import org.polypheny.db.algebra.enumerable.EnumerableConvention; -import org.polypheny.db.algebra.enumerable.PhysType; -import org.polypheny.db.algebra.metadata.AlgMetadataQuery; -import org.polypheny.db.catalog.entity.Entity; -import org.polypheny.db.plan.AlgCluster; -import org.polypheny.db.plan.AlgOptCost; -import org.polypheny.db.plan.AlgPlanner; -import org.polypheny.db.plan.AlgTraitSet; -import org.polypheny.db.util.BuiltInMethod; - -public class EnumerableDocIdentifier extends Identifier implements EnumerableAlg { - - protected EnumerableDocIdentifier( AlgCluster cluster, AlgTraitSet traits, Entity entity, AlgNode input ) { - super( cluster, traits, entity, input ); - assert getConvention() instanceof EnumerableConvention; - } - - - @Override - public AlgOptCost computeSelfCost( AlgPlanner planner, AlgMetadataQuery mq ) { - double dRows = mq.getTupleCount( getInput() ); - return planner.getCostFactory().makeCost( dRows, 0, 0 ); - } - - - @Override - public AlgNode copy( AlgTraitSet traitSet, List inputs ) { - return new EnumerableDocIdentifier( inputs.get( 0 ).getCluster(), traitSet, entity, inputs.get( 0 ) ); - } - - - @Override - public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { - final BlockBuilder builder = new BlockBuilder(); - final EnumerableAlg input = (EnumerableAlg) getInput(); - final Result result = implementor.visitChild( this, 0, input, Prefer.ANY ); - final PhysType physType = result.physType(); - - Expression input_ = builder.append( "input", result.block() ); - Expression entity_ = Expressions.constant( entity.getId() ); - Expression identification_ = builder.append( "identification", Expressions.call( BuiltInMethod.ADD_DOC_IDENTIFIERS.method, input_, entity_ ) ); - - builder.add( Expressions.return_( null, identification_ ) ); - return implementor.result( physType, builder.toBlock() ); - } - -} diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/document/EnumerableDocIdentifierRule.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/document/EnumerableDocIdentifierRule.java deleted file mode 100644 index 199618166a..0000000000 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/document/EnumerableDocIdentifierRule.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2019-2024 The Polypheny Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.polypheny.db.algebra.enumerable.document; - -import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.algebra.convert.ConverterRule; -import org.polypheny.db.algebra.enumerable.EnumerableConvention; -import org.polypheny.db.algebra.logical.document.LogicalDocIdentifier; -import org.polypheny.db.plan.AlgTraitSet; -import org.polypheny.db.plan.Convention; - - - -/* - * Copyright 2019-2024 The Polypheny Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -public class EnumerableDocIdentifierRule extends ConverterRule { - - public EnumerableDocIdentifierRule() { - super( LogicalDocIdentifier.class, Convention.NONE, EnumerableConvention.INSTANCE, "EnumerableDocIdentifierRule" ); - } - - - @Override - public AlgNode convert( AlgNode alg ) { - final LogicalDocIdentifier identifier = (LogicalDocIdentifier) alg; - final AlgTraitSet traits = identifier.getTraitSet().replace( EnumerableConvention.INSTANCE ); - final AlgNode input = convert( identifier.getInput(), identifier.getInput().getTraitSet().replace( EnumerableConvention.INSTANCE ) ); - return new EnumerableDocIdentifier( identifier.getCluster(), traits, identifier.getEntity(), input ); - } - -} - diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgIdentifier.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgIdentifier.java deleted file mode 100644 index 9516de2672..0000000000 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgIdentifier.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2019-2024 The Polypheny Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.polypheny.db.algebra.enumerable.lpg; - -import java.util.List; -import org.apache.calcite.linq4j.tree.BlockBuilder; -import org.apache.calcite.linq4j.tree.Expression; -import org.apache.calcite.linq4j.tree.Expressions; -import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.algebra.core.common.Identifier; -import org.polypheny.db.algebra.enumerable.EnumerableAlg; -import org.polypheny.db.algebra.enumerable.EnumerableAlgImplementor; -import org.polypheny.db.algebra.enumerable.EnumerableConvention; -import org.polypheny.db.algebra.enumerable.PhysType; -import org.polypheny.db.algebra.metadata.AlgMetadataQuery; -import org.polypheny.db.catalog.entity.Entity; -import org.polypheny.db.plan.AlgCluster; -import org.polypheny.db.plan.AlgOptCost; -import org.polypheny.db.plan.AlgPlanner; -import org.polypheny.db.plan.AlgTraitSet; -import org.polypheny.db.util.BuiltInMethod; - -public class EnumerableLpgIdentifier extends Identifier implements EnumerableAlg { - - protected EnumerableLpgIdentifier( AlgCluster cluster, AlgTraitSet traits, Entity entity, AlgNode input ) { - super( cluster, traits, entity, input ); - assert getConvention() instanceof EnumerableConvention; - } - - - @Override - public AlgOptCost computeSelfCost( AlgPlanner planner, AlgMetadataQuery mq ) { - double dRows = mq.getTupleCount( getInput() ); - return planner.getCostFactory().makeCost( dRows, 0, 0 ); - } - - - @Override - public AlgNode copy( AlgTraitSet traitSet, List inputs ) { - return new EnumerableLpgIdentifier( inputs.get( 0 ).getCluster(), traitSet, entity, inputs.get( 0 ) ); - } - - - @Override - public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { - final BlockBuilder builder = new BlockBuilder(); - final EnumerableAlg input = (EnumerableAlg) getInput(); - final Result result = implementor.visitChild( this, 0, input, Prefer.ANY ); - final PhysType physType = result.physType(); - - Expression input_ = builder.append( "input", result.block() ); - Expression entity_ = Expressions.constant( entity.getId() ); - Expression identification_ = builder.append( "identification", Expressions.call( BuiltInMethod.ADD_LPG_IDENTIFIERS.method, input_, entity_ ) ); - - builder.add( Expressions.return_( null, identification_ ) ); - return implementor.result( physType, builder.toBlock() ); - } - -} diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgIdentifierRule.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgIdentifierRule.java deleted file mode 100644 index 0212940245..0000000000 --- a/core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgIdentifierRule.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2019-2024 The Polypheny Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.polypheny.db.algebra.enumerable.lpg; - -import org.polypheny.db.algebra.AlgNode; -import org.polypheny.db.algebra.convert.ConverterRule; -import org.polypheny.db.algebra.enumerable.EnumerableConvention; -import org.polypheny.db.algebra.logical.lpg.LogicalLpgIdentifier; -import org.polypheny.db.plan.AlgTraitSet; -import org.polypheny.db.plan.Convention; - -public class EnumerableLpgIdentifierRule extends ConverterRule { - - public EnumerableLpgIdentifierRule() { - super( LogicalLpgIdentifier.class, Convention.NONE, EnumerableConvention.INSTANCE, "EnumerableLpgIdentifierRule" ); - } - - - @Override - public AlgNode convert( AlgNode alg ) { - final LogicalLpgIdentifier identifier = (LogicalLpgIdentifier) alg; - final AlgTraitSet traits = identifier.getTraitSet().replace( EnumerableConvention.INSTANCE ); - final AlgNode input = convert( identifier.getInput(), identifier.getInput().getTraitSet().replace( EnumerableConvention.INSTANCE ) ); - return new EnumerableLpgIdentifier( identifier.getCluster(), traits, identifier.getEntity(), input ); - } - -} diff --git a/core/src/main/java/org/polypheny/db/functions/Functions.java b/core/src/main/java/org/polypheny/db/functions/Functions.java index 6eb6bbcd94..41ccefdec5 100644 --- a/core/src/main/java/org/polypheny/db/functions/Functions.java +++ b/core/src/main/java/org/polypheny/db/functions/Functions.java @@ -23,6 +23,7 @@ import com.drew.metadata.Metadata; import com.drew.metadata.Tag; import com.fasterxml.jackson.core.JsonParser.Feature; +import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.collect.Sets; import com.google.gson.Gson; @@ -293,40 +294,10 @@ public static Enumerable batch( final DataContext context, final Enumerable

addRelIdentifiers(final Enumerable input, long logicalId) { - LogicalEntity entity = Catalog.getInstance().getSnapshot().getLogicalEntity( logicalId ).orElseThrow(); - return input.select( row -> { - row[0] = entity.getEntryIdentifiers().getNextEntryIdentifier().getEntryIdentifierAsPolyLong(); - return row; - } ); - } - - @SuppressWarnings("unused") - public static Enumerable addDocIdentifiers(final Enumerable input, long logicalId) { - LogicalEntity entity = Catalog.getInstance().getSnapshot().getLogicalEntity( logicalId ).orElseThrow(); - return input.select( row -> { - for ( PolyValue value : row ) { - PolyLong entryIdentifier = entity.getEntryIdentifiers().getNextEntryIdentifier().getEntryIdentifierAsPolyLong(); - ((PolyDocument) value).put( IdentifierUtils.getIdentifierKeyAsPolyString(), entryIdentifier ); - } - return row; - } ); + public static Enumerable processAndStreamRight(final Enumerable input, final Function1, Enumerable> processing){ + return processing.apply(input); } - @SuppressWarnings("unused") - public static Enumerable addLpgIdentifiers(final Enumerable input, long logicalId) { - LogicalEntity entity = Catalog.getInstance().getSnapshot().getLogicalEntity( logicalId ).orElseThrow(); - return input.select( row -> { - for ( PolyValue value : row ) { - PolyLong entryIdentifier = entity.getEntryIdentifiers().getNextEntryIdentifier().getEntryIdentifierAsPolyLong(); - ((GraphPropertyHolder) value).getProperties().put( IdentifierUtils.getIdentifierKeyAsPolyString(), entryIdentifier ); - } - return row; - } ); - } - - @SuppressWarnings("unused") public static Enumerable streamRight( final DataContext context, final Enumerable input, final Function0> executorCall, final List polyTypes ) { AlgDataTypeFactory factory = new PolyTypeFactoryImpl( AlgDataTypeSystem.DEFAULT ); diff --git a/core/src/main/java/org/polypheny/db/util/BuiltInMethod.java b/core/src/main/java/org/polypheny/db/util/BuiltInMethod.java index 49e21a15e3..1bd5ed79cd 100644 --- a/core/src/main/java/org/polypheny/db/util/BuiltInMethod.java +++ b/core/src/main/java/org/polypheny/db/util/BuiltInMethod.java @@ -105,8 +105,6 @@ import org.polypheny.db.algebra.metadata.BuiltInMetadata.TupleCount; import org.polypheny.db.algebra.metadata.BuiltInMetadata.UniqueKeys; import org.polypheny.db.algebra.metadata.Metadata; -import org.polypheny.db.catalog.entity.Entity; -import org.polypheny.db.catalog.entity.logical.LogicalEntity; import org.polypheny.db.catalog.snapshot.Snapshot; import org.polypheny.db.functions.CrossModelFunctions; import org.polypheny.db.functions.CypherFunctions; @@ -157,6 +155,7 @@ public enum BuiltInMethod { SWITCH_CONTEXT( DataContext.class, "switchContext" ), BATCH( Functions.class, "batch", DataContext.class, Enumerable.class ), STREAM_RIGHT( Functions.class, "streamRight", DataContext.class, Enumerable.class, Function0.class, List.class ), + PROCESS_AND_STREAM_RIGHT(Functions.class, "processAndStreamRight", Enumerable.class, Function1.class), ADD_REL_IDENTIFIERS(Functions.class, "addRelIdentifiers", Enumerable.class, long.class), ADD_DOC_IDENTIFIERS(Functions.class, "addDocIdentifiers", Enumerable.class, long.class), ADD_LPG_IDENTIFIERS(Functions.class, "addLpgIdentifiers", Enumerable.class, long.class), diff --git a/dbms/src/test/java/org/polypheny/db/transaction/MockTransaction.java b/dbms/src/test/java/org/polypheny/db/transaction/MockTransaction.java index f398ed383f..7ef4e0a23f 100644 --- a/dbms/src/test/java/org/polypheny/db/transaction/MockTransaction.java +++ b/dbms/src/test/java/org/polypheny/db/transaction/MockTransaction.java @@ -34,6 +34,7 @@ import org.polypheny.db.processing.Processor; import org.polypheny.db.transaction.locking.Lockable; import org.polypheny.db.transaction.locking.Lockable.LockType; +import org.polypheny.db.transaction.locking.VersionedEntryIdentifier; public class MockTransaction implements Transaction { @@ -243,4 +244,10 @@ public void acquireLockable( Lockable lockable, LockType lockType ) { locks.add( lockable ); } + + @Override + public void addReadEntity( VersionedEntryIdentifier entryIdentifier ) { + + } + }