Skip to content

Commit

Permalink
Start debugging lpg insertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Hafner committed Dec 24, 2024
1 parent b50cfcc commit 99d830a
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 5 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/org/polypheny/db/adapter/Modifiable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 );
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<PolyNode> nodes, Collection<PolyEdge> edges, ImmutableList<ImmutableList<RexLiteral>> 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<Expression> 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() );
}

}
Original file line number Diff line number Diff line change
@@ -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<AlgNode>) r -> true, Convention.NONE, EnumerableConvention.INSTANCE, algBuilderFactory, "EnumerableLpgValuesRule" );
}


@Override
public AlgNode convert( AlgNode alg ) {
LpgValues values = (LpgValues) alg;
return EnumerableLpgValues.create(values);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public static Enumerable<PolyValue[]> addDocIdentifiers(final Enumerable<PolyVal
@SuppressWarnings("unused")
public static Enumerable<PolyValue[]> addLpgIdentifiers(final Enumerable<PolyValue[]> input, long logicalId) {
return input.select( oldRow -> {
// ToDo: find out what has to be done here

return oldRow;
} );
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/polypheny/db/tools/Programs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 99d830a

Please sign in to comment.