-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Cypher's CALL procedure support
- Loading branch information
1 parent
ba868f9
commit 8265d38
Showing
22 changed files
with
739 additions
and
6 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
core/src/main/java/org/polypheny/db/adapter/NeoProcedureProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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.adapter; | ||
|
||
import org.polypheny.db.algebra.AlgNode; | ||
import org.polypheny.db.plan.AlgCluster; | ||
import org.polypheny.db.plan.AlgPlanner; | ||
import org.polypheny.db.plan.AlgTraitSet; | ||
import org.polypheny.db.plan.Convention; | ||
import org.polypheny.db.plan.volcano.VolcanoPlanner; | ||
import org.polypheny.db.type.entity.PolyValue; | ||
import java.util.ArrayList; | ||
|
||
public interface NeoProcedureProvider { | ||
public Convention getConvention( AlgPlanner planner ); | ||
public AlgNode getCall( AlgCluster cluster, AlgTraitSet traits, ArrayList<String> namespace, String procedureName, ArrayList<PolyValue> arguments, boolean yieldAll, ArrayList<String> yieldItems); | ||
public Adapter getStore(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,8 @@ enum NodeType { | |
VALUES, | ||
AGGREGATE, | ||
MERGE, | ||
SORT | ||
SORT, | ||
CALL | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
core/src/main/java/org/polypheny/db/algebra/core/lpg/LpgCall.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* 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.core.lpg; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.polypheny.db.adapter.Adapter; | ||
import org.polypheny.db.algebra.AbstractAlgNode; | ||
import org.polypheny.db.algebra.metadata.AlgMetadataQuery; | ||
import org.polypheny.db.algebra.type.AlgDataType; | ||
import org.polypheny.db.algebra.type.AlgDataTypeField; | ||
import org.polypheny.db.algebra.type.AlgDataTypeFieldImpl; | ||
import org.polypheny.db.algebra.type.AlgRecordType; | ||
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.type.PolyType; | ||
import org.polypheny.db.type.entity.PolyValue; | ||
import java.util.ArrayList; | ||
|
||
public abstract class LpgCall extends AbstractAlgNode implements LpgAlg { | ||
|
||
@Getter | ||
ArrayList<String> namespace; | ||
@Getter | ||
String procedureName; | ||
@Getter | ||
ArrayList<PolyValue> arguments; | ||
@Setter | ||
@Getter | ||
Adapter procedureProvider; // will only be used when we reach a Neo4j store, so normally just pass a null to it | ||
|
||
@Getter | ||
boolean yieldAll; | ||
@Getter | ||
ArrayList<String> yieldItems; | ||
|
||
public LpgCall( AlgCluster cluster, AlgTraitSet traits, ArrayList<String> namespace, String procedureName, ArrayList<PolyValue> arguments, Adapter procedureProvider, boolean yieldAll, ArrayList<String> yieldItems ) { | ||
super( cluster, traits ); | ||
this.namespace = namespace; | ||
this.procedureName = procedureName; | ||
this.arguments = arguments; | ||
this.procedureProvider = procedureProvider; | ||
this.yieldAll = yieldAll; | ||
this.yieldItems = yieldItems; | ||
} | ||
|
||
@Override | ||
public String algCompareString() { | ||
return getClass().getSimpleName().toString() + "$" + String.join( ".", namespace ) | ||
+ "." + procedureName + "$" + arguments.hashCode(); | ||
} | ||
|
||
|
||
@Override | ||
public NodeType getNodeType() { | ||
return NodeType.CALL; | ||
} | ||
|
||
@Override | ||
protected AlgDataType deriveRowType() { | ||
if (!(procedureName.equals( "labels" ))) { | ||
throw new UnsupportedOperationException("The called procedure is not supported"); | ||
} | ||
ArrayList<AlgDataTypeField> fields = new ArrayList<>(); | ||
fields.add( new AlgDataTypeFieldImpl( -1L, "Labels", 0, getCluster().getTypeFactory().createPolyType( PolyType.VARCHAR ) ) ); | ||
return new AlgRecordType( fields ); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
core/src/main/java/org/polypheny/db/algebra/logical/lpg/LogicalLpgCall.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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.logical.lpg; | ||
|
||
import org.polypheny.db.adapter.Adapter; | ||
import org.polypheny.db.algebra.core.lpg.LpgCall; | ||
import org.polypheny.db.plan.AlgCluster; | ||
import org.polypheny.db.plan.AlgTraitSet; | ||
import org.polypheny.db.type.entity.PolyValue; | ||
import java.util.ArrayList; | ||
|
||
public class LogicalLpgCall extends LpgCall { | ||
|
||
public LogicalLpgCall( AlgCluster cluster, AlgTraitSet traits, ArrayList<String> namespace, String procedureName, ArrayList<PolyValue> arguments, Adapter procedureProvider, boolean yieldAll, ArrayList<String> yieldItems ) { | ||
super( cluster, traits, namespace, procedureName, arguments, procedureProvider, yieldAll, yieldItems ); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
core/src/main/java/org/polypheny/db/algebra/rules/CypherCallLogicalToPhysicalRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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.rules; | ||
|
||
import org.polypheny.db.adapter.Adapter; | ||
import org.polypheny.db.adapter.AdapterManager; | ||
import org.polypheny.db.adapter.NeoProcedureProvider; | ||
import org.polypheny.db.algebra.AlgNode; | ||
import org.polypheny.db.algebra.core.AlgFactories; | ||
import org.polypheny.db.algebra.core.common.Modify; | ||
import org.polypheny.db.algebra.core.lpg.LpgCall; | ||
import org.polypheny.db.algebra.enumerable.EnumerableConvention; | ||
import org.polypheny.db.algebra.logical.lpg.LogicalLpgCall; | ||
import org.polypheny.db.plan.AlgOptRule; | ||
import org.polypheny.db.plan.AlgOptRuleCall; | ||
import org.polypheny.db.plan.Convention; | ||
|
||
public class CypherCallLogicalToPhysicalRule extends AlgOptRule { | ||
|
||
public static final CypherCallLogicalToPhysicalRule INSTANCE = new CypherCallLogicalToPhysicalRule( LogicalLpgCall.class ); | ||
|
||
public CypherCallLogicalToPhysicalRule( Class<? extends LpgCall> callAlg ) { | ||
super( operand( callAlg, Convention.NONE, r -> true, any() ), AlgFactories.LOGICAL_BUILDER, callAlg.getSimpleName() + "ToPhysical" ); | ||
} | ||
|
||
@Override | ||
public void onMatch( AlgOptRuleCall call ) { | ||
LpgCall oldAlg = call.alg( 0 ); | ||
Adapter neo = null; | ||
for ( Adapter a : AdapterManager.getInstance().getStores().values() ) { | ||
if ( a.adapterName.contains( "Neo" ) ) { | ||
neo = a; | ||
} | ||
} | ||
if ( neo == null ) { | ||
throw new RuntimeException( "No neo adapter found" ); | ||
} | ||
AlgNode newAlg = oldAlg; | ||
newAlg.getTraitSet().replace( ((NeoProcedureProvider)neo).getConvention(call.getPlanner()) ); | ||
((LpgCall)newAlg).setProcedureProvider( ((NeoProcedureProvider)neo).getStore() ); | ||
//AlgNode newAlg = ((NeoProcedureProvider)neo).getCall( oldAlg.getCluster(), oldAlg.getTraitSet(), oldAlg.getNamespace(), oldAlg.getProcedureName(), oldAlg.getArguments() ); | ||
if ( newAlg != null ) { | ||
call.transformTo( newAlg ); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.