From 99d830a9a62f1cebd2409f44f2de3caf2bd4f7d4 Mon Sep 17 00:00:00 2001 From: Tobias Hafner Date: Tue, 24 Dec 2024 17:02:48 +0100 Subject: [PATCH] Start debugging lpg insertions --- .../org/polypheny/db/adapter/Modifiable.java | 5 ++ .../algebra/enumerable/EnumerableRules.java | 3 + .../lpg/EnumerableLpgIdentifierRule.java | 5 +- .../enumerable/lpg/EnumerableLpgValues.java | 77 +++++++++++++++++++ .../lpg/EnumerableLpgValuesRule.java | 41 ++++++++++ .../rules/AllocationToPhysicalModifyRule.java | 4 +- .../org/polypheny/db/functions/Functions.java | 2 +- .../java/org/polypheny/db/tools/Programs.java | 1 + .../db/processing/VolcanoQueryProcessor.java | 1 + 9 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgValues.java create mode 100644 core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgValuesRule.java diff --git a/core/src/main/java/org/polypheny/db/adapter/Modifiable.java b/core/src/main/java/org/polypheny/db/adapter/Modifiable.java index cc60be941b..4e52399bdc 100644 --- a/core/src/main/java/org/polypheny/db/adapter/Modifiable.java +++ b/core/src/main/java/org/polypheny/db/adapter/Modifiable.java @@ -33,6 +33,7 @@ import org.polypheny.db.algebra.core.relational.RelModify; import org.polypheny.db.algebra.logical.common.LogicalContextSwitcher; import org.polypheny.db.algebra.logical.common.LogicalStreamer; +import org.polypheny.db.algebra.logical.lpg.LogicalLpgIdentifier; import org.polypheny.db.algebra.logical.lpg.LogicalLpgModify; import org.polypheny.db.algebra.logical.lpg.LogicalLpgProject; import org.polypheny.db.algebra.logical.lpg.LogicalLpgTransformer; @@ -442,6 +443,10 @@ static AlgNode getGraphModifySubstitute( Modifiable modifiable, long allocId, Lp if ( raw instanceof LpgProject ) { return attachRelationalRelatedInsert( modifiable, raw, (LogicalLpgModify) alg, builder, nodesTable, nodePropertiesTable, edgesTable, edgePropertiesTable ); } + if( raw instanceof LogicalLpgIdentifier) { + // TOOO TH: let's see if this works + return attachRelationalRelatedInsert( modifiable, raw, (LogicalLpgModify) alg, builder, nodesTable, nodePropertiesTable, edgesTable, edgePropertiesTable ); + } break; case UPDATE: 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 e585221960..aebddbc0f7 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 @@ -49,6 +49,7 @@ 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; import org.polypheny.db.plan.AlgOptRule; import org.polypheny.db.util.trace.PolyphenyDbTrace; import org.slf4j.Logger; @@ -120,6 +121,8 @@ private EnumerableRules() { public static final EnumerableDocumentValuesRule ENUMERABLE_DOCUMENT_VALUES_RULE = new EnumerableDocumentValuesRule( AlgFactories.LOGICAL_BUILDER ); + public static final EnumerableLpgValuesRule ENUMERABLE_LPG_VALUES_RULE = new EnumerableLpgValuesRule( AlgFactories.LOGICAL_BUILDER ); + public static final EnumerableWindowRule ENUMERABLE_WINDOW_RULE = new EnumerableWindowRule(); public static final EnumerableCollectRule ENUMERABLE_COLLECT_RULE = new EnumerableCollectRule(); 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 index cfd6108099..0212940245 100644 --- 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 @@ -20,7 +20,6 @@ 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.algebra.logical.relational.LogicalRelIdentifier; import org.polypheny.db.plan.AlgTraitSet; import org.polypheny.db.plan.Convention; @@ -33,9 +32,9 @@ public EnumerableLpgIdentifierRule() { @Override public AlgNode convert( AlgNode alg ) { - final LogicalRelIdentifier identifier = (LogicalRelIdentifier) 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 )); + 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/algebra/enumerable/lpg/EnumerableLpgValues.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgValues.java new file mode 100644 index 0000000000..154eb6ab36 --- /dev/null +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgValues.java @@ -0,0 +1,77 @@ +/* + * 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 com.google.common.collect.ImmutableList; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.calcite.linq4j.tree.BlockBuilder; +import org.apache.calcite.linq4j.tree.Expression; +import org.apache.calcite.linq4j.tree.Expressions; +import org.apache.calcite.linq4j.tree.Primitive; +import org.polypheny.db.algebra.core.lpg.LpgValues; +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.enumerable.PhysTypeImpl; +import org.polypheny.db.algebra.type.AlgDataType; +import org.polypheny.db.plan.AlgCluster; +import org.polypheny.db.plan.AlgTraitSet; +import org.polypheny.db.rex.RexLiteral; +import org.polypheny.db.type.entity.PolyValue; +import org.polypheny.db.type.entity.graph.PolyEdge; +import org.polypheny.db.type.entity.graph.PolyNode; +import org.polypheny.db.util.BuiltInMethod; + +public class EnumerableLpgValues extends LpgValues implements EnumerableAlg { + + public EnumerableLpgValues( AlgCluster cluster, AlgTraitSet traitSet, Collection nodes, Collection edges, ImmutableList> values, AlgDataType rowType ) { + super( cluster, traitSet.replace( EnumerableConvention.INSTANCE ), nodes, edges, values, rowType ); + } + + + public static EnumerableLpgValues create( LpgValues values ) { + return new EnumerableLpgValues( values.getCluster(), values.getTraitSet(), values.getNodes(), values.getEdges(), values.getValues(), values.getRowType() ); + } + + + @Override + public Result implement( EnumerableAlgImplementor implementor, Prefer pref ) { + final BlockBuilder builder = new BlockBuilder(); + final PhysType physType = PhysTypeImpl.of( + implementor.getTypeFactory(), + getTupleType(), + pref.preferCustom() + ); + final List expressions = Stream.concat( + nodes.stream().map( n -> Expressions.newArrayInit( PolyNode.class, n.asExpression() ) ), + edges.stream().map( n -> Expressions.newArrayInit( PolyEdge.class, n.asExpression() ) ) + ).collect( Collectors.toCollection( ArrayList::new ) ); + builder.add( + Expressions.return_( + null, + Expressions.call( + BuiltInMethod.AS_ENUMERABLE.method, + Expressions.newArrayInit( Primitive.box( PolyValue.class ), 2, expressions ) ) ) ); + return implementor.result( physType, builder.toBlock() ); + } + +} diff --git a/core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgValuesRule.java b/core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgValuesRule.java new file mode 100644 index 0000000000..28c87621e4 --- /dev/null +++ b/core/src/main/java/org/polypheny/db/algebra/enumerable/lpg/EnumerableLpgValuesRule.java @@ -0,0 +1,41 @@ +/* + * 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.function.Predicate; +import org.polypheny.db.algebra.AlgNode; +import org.polypheny.db.algebra.convert.ConverterRule; +import org.polypheny.db.algebra.core.lpg.LpgValues; +import org.polypheny.db.algebra.enumerable.EnumerableConvention; +import org.polypheny.db.algebra.logical.lpg.LogicalLpgValues; +import org.polypheny.db.plan.Convention; +import org.polypheny.db.tools.AlgBuilderFactory; + +public class EnumerableLpgValuesRule extends ConverterRule { + + public EnumerableLpgValuesRule( AlgBuilderFactory algBuilderFactory ) { + super( LogicalLpgValues.class, (Predicate) r -> true, Convention.NONE, EnumerableConvention.INSTANCE, algBuilderFactory, "EnumerableLpgValuesRule" ); + } + + + @Override + public AlgNode convert( AlgNode alg ) { + LpgValues values = (LpgValues) alg; + return EnumerableLpgValues.create(values); + } + +} 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 032db5589b..f974adc2bf 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 @@ -18,6 +18,7 @@ import java.util.Optional; import org.polypheny.db.adapter.AdapterManager; +import org.polypheny.db.adapter.DataStore; import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.core.AlgFactories; import org.polypheny.db.algebra.core.common.Modify; @@ -55,7 +56,8 @@ public void onMatch( AlgOptRuleCall call ) { return; } - AlgNode newAlg = AdapterManager.getInstance().getStore( oAlloc.get().adapterId ).orElseThrow().getModify( oAlloc.get().id, modify, call.builder() ); + DataStore store = AdapterManager.getInstance().getStore( oAlloc.get().adapterId ).orElseThrow(); + AlgNode newAlg = store.getModify( oAlloc.get().id, modify, call.builder() ); if ( newAlg != null ) { call.transformTo( newAlg ); 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 a82f30ef74..6e9d1a37c9 100644 --- a/core/src/main/java/org/polypheny/db/functions/Functions.java +++ b/core/src/main/java/org/polypheny/db/functions/Functions.java @@ -314,7 +314,7 @@ public static Enumerable addDocIdentifiers(final Enumerable addLpgIdentifiers(final Enumerable input, long logicalId) { return input.select( oldRow -> { - // ToDo: find out what has to be done here + return oldRow; } ); } 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 868cb911c5..ab5cf6d17a 100644 --- a/core/src/main/java/org/polypheny/db/tools/Programs.java +++ b/core/src/main/java/org/polypheny/db/tools/Programs.java @@ -158,6 +158,7 @@ public class Programs { EnumerableRules.ENUMERABLE_MINUS_RULE, EnumerableRules.ENUMERABLE_VALUES_RULE, EnumerableRules.ENUMERABLE_DOCUMENT_VALUES_RULE, + EnumerableRules.ENUMERABLE_LPG_VALUES_RULE, EnumerableRules.ENUMERABLE_WINDOW_RULE, EnumerableRules.ENUMERABLE_CALC_RULE, EnumerableRules.ENUMERABLE_FILTER_TO_CALC_RULE, diff --git a/dbms/src/main/java/org/polypheny/db/processing/VolcanoQueryProcessor.java b/dbms/src/main/java/org/polypheny/db/processing/VolcanoQueryProcessor.java index 7b168b618d..27022deb09 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/VolcanoQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/VolcanoQueryProcessor.java @@ -114,6 +114,7 @@ public class VolcanoQueryProcessor extends AbstractQueryProcessor { EnumerableRules.ENUMERABLE_CONTEXT_SWITCHER_RULE, EnumerableRules.ENUMERABLE_VALUES_RULE, EnumerableRules.ENUMERABLE_DOCUMENT_VALUES_RULE, + EnumerableRules.ENUMERABLE_LPG_VALUES_RULE, EnumerableRules.ENUMERABLE_WINDOW_RULE, EnumerableRules.ENUMERABLE_TABLE_SCAN_RULE, EnumerableRules.ENUMERABLE_TRANSFORMER_RULE,