Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi model graphical querying #445

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.polypheny.db.catalog.entity.CatalogSchema;
import org.polypheny.db.catalog.entity.CatalogTable;
import org.polypheny.db.catalog.entity.CatalogUser;
import org.polypheny.db.catalog.exceptions.NoTablePrimaryKeyException;
import org.polypheny.db.config.RuntimeConfig;
import org.polypheny.db.information.InformationManager;
import org.polypheny.db.languages.QueryLanguage;
Expand Down Expand Up @@ -216,6 +217,11 @@ public void commit() throws TransactionException {

// Handover information about commit to Materialized Manager
MaterializedViewManager.getInstance().updateCommittedXid( xid );
try {
Catalog.getInstance().commit();
} catch ( NoTablePrimaryKeyException e ) {
throw new RuntimeException( e );
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@

import java.util.List;
import lombok.Getter;
import org.polypheny.db.algebra.operators.OperatorName;
import org.polypheny.db.cypher.cypher2alg.CypherToAlgConverter.CypherContext;
import org.polypheny.db.cypher.cypher2alg.CypherToAlgConverter.RexType;
import org.polypheny.db.languages.OperatorRegistry;
import org.polypheny.db.languages.ParserPos;
import org.polypheny.db.rex.RexCall;
import org.polypheny.db.rex.RexNode;
import org.polypheny.db.util.Pair;

@Getter
public class CypherGate extends CypherExpression {
Expand All @@ -44,6 +51,38 @@ public CypherGate( Gate gate, List<CypherExpression> expressions ) {
}


@Override
public Pair<String, RexNode> getRex( CypherContext context, RexType type ) {
OperatorName operatorName = null;
switch ( gate ) {
case OR:
operatorName = OperatorName.OR;
break;
case AND:
operatorName = OperatorName.AND;
break;
case XOR:
throw new UnsupportedOperationException();
case NOT:
return handleSingular( context, type, OperatorName.NOT );
}

return Pair.of( null, new RexCall(
context.booleanType,
OperatorRegistry.get( operatorName ),
List.of( left.getRex( context, type ).right, right.getRex( context, type ).right ) ) );

}


private Pair<String, RexNode> handleSingular( CypherContext context, RexType type, OperatorName operatorName ) {
return Pair.of( null, new RexCall(
context.booleanType,
OperatorRegistry.get( operatorName ),
List.of( left.getRex( context, type ).right ) ) );
}


public enum Gate {
OR,
AND,
Expand Down
2 changes: 1 addition & 1 deletion plugins/mql-language/src/main/codegen/DocumentParser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ MqlNode Input() :
}
{
/** only one statement for now **/
n = Statement() <EOF>
n = Statement() [";"]<EOF>
{return n;}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,10 @@ public void createNewSchema( SchemaPlus rootSchema, String name ) {
final Expression expression = Schemas.subSchemaExpression( rootSchema, name, NeoNamespace.class );
String namespaceName;
String[] splits = name.split( "_" );
if ( splits.length >= 3 ) {
if ( splits.length == 3 ) {
namespaceName = splits[1];
} else if ( splits.length > 3 ) {
namespaceName = String.join( "_", Arrays.asList( splits ).subList( 1, splits.length - 1 ) );
} else {
throw new RuntimeException( "Error while generating new namespace" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public String build() {
if ( direction == EdgeDirection.LEFT_TO_RIGHT ) {
statement = statement + ">";
} else if ( direction == EdgeDirection.RIGHT_TO_LEFT ) {
statement = statement + "<";
statement = "<" + statement;
}
return statement;
}
Expand Down
47 changes: 42 additions & 5 deletions webui/src/main/java/org/polypheny/db/webui/Crud.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.polypheny.db.webui;


import static org.polypheny.db.adapter.ConnectionMethod.LINK;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
Expand Down Expand Up @@ -83,6 +85,7 @@
import org.polypheny.db.adapter.Adapter.AbstractAdapterSettingDirectory;
import org.polypheny.db.adapter.AdapterManager;
import org.polypheny.db.adapter.AdapterManager.AdapterInformation;
import org.polypheny.db.adapter.ConnectionMethod;
import org.polypheny.db.adapter.DataSource;
import org.polypheny.db.adapter.DataSource.ExportedColumn;
import org.polypheny.db.adapter.DataStore;
Expand Down Expand Up @@ -394,7 +397,21 @@ void getSchemaTree( final Context ctx ) {
}

SidebarElement tableElement = new SidebarElement( schema.name + "." + table.name, table.name, schema.namespaceType, request.routerLinkRoot, icon );
if ( request.depth > 2 ) {
// manually adding document-relation
if ( schema.namespaceType == NamespaceType.DOCUMENT ) {
schemaTree.setRouterLink( request.routerLinkRoot + "/" + schema.name );
if (request.depth == 3 && request.isCrossModel) {
String[] documentRelational = new String[]{"d"}; // should be _id and _data
String[] collectionRelational = new String[]{"shop"}; // should be an array of the collections of a schema
for (String collection : collectionRelational) {
for (String doc : documentRelational) {
tableElement.addChild(new SidebarElement(schema.name + "." + collection + "." + doc, doc, schema.namespaceType, request.routerLinkRoot, "fa fa-table").setCssClass("sidebarColumn"));
}
}
}
}

if ( request.depth > 2 && schema.namespaceType != NamespaceType.DOCUMENT) {
List<CatalogColumn> columns = catalog.getColumns( table.id );
for ( CatalogColumn column : columns ) {
tableElement.addChild( new SidebarElement( schema.name + "." + table.name + "." + column.name, column.name, schema.namespaceType, request.routerLinkRoot, icon ).setCssClass( "sidebarColumn" ) );
Expand All @@ -420,10 +437,30 @@ void getSchemaTree( final Context ctx ) {
schemaTree.addChildren( collectionTree ).setRouterLink( "" );
}
}

// new Code from Melanie - manually adding children for graphs
String[] graphLabels = new String[]{"Movie", "Character", "Person"}; // hardcoded, should be the labels of the graph
ArrayList<SidebarElement> collectionTree = new ArrayList<>();
if ( schema.namespaceType == NamespaceType.GRAPH ) {
schemaTree.setRouterLink( request.routerLinkRoot + "/" + schema.name );
if (request.depth == 2 && request.isCrossModel) {
for (String label : graphLabels) {
schemaTree.addChild(new SidebarElement(schema.name + "." + label, label, schema.namespaceType, request.routerLinkRoot, "fa fa-table"));
}
}
if (request.depth == 3 && request.isCrossModel) {
String[] graphRelational = new String[]{"id", "properties", "labels"}; // should always be these
for (String label : graphLabels) {
SidebarElement tableElement = new SidebarElement( schema.name + "." + label, label, schema.namespaceType, request.routerLinkRoot, "fa fa-table");
for (String graphx : graphRelational) {
tableElement.addChild( new SidebarElement( schema.name + "." + label + "." + graphx, graphx, schema.namespaceType, request.routerLinkRoot, "fa fa-table").setCssClass( "sidebarColumn" ) );
}
tableElement.setTableType( "VIEW" ); // is always views if .isCrossModel is true
collectionTree.add( tableElement );
}
schemaTree.addChildren( collectionTree ).setRouterLink( "" );
}
}

result.add( schemaTree );
}

Expand Down Expand Up @@ -2328,15 +2365,15 @@ void addAdapter( final Context ctx, Gson gson ) throws ServletException, IOExcep
AdapterModel a = gson.fromJson( body, AdapterModel.class );
Map<String, String> settings = new HashMap<>();

String method = a.settings.get( "method" ).getValue();
ConnectionMethod method = ConnectionMethod.UPLOAD;
if ( a.settings.containsKey( "method" ) ) {
method = a.settings.get( "method" ).getValue();
method = a.settings.get( "method" ).equals( "link" ) ? LINK : ConnectionMethod.UPLOAD;
}

for ( Entry<String, AbstractAdapterSetting> entry : a.settings.entrySet() ) {
if ( entry.getValue() instanceof AbstractAdapterSettingDirectory ) {
AbstractAdapterSettingDirectory setting = ((AbstractAdapterSettingDirectory) entry.getValue());
if ( method.equals( "link" ) ) {
if ( method == LINK ) {
Exception e = handleLinkFiles( ctx, a, setting, a.settings );
if ( e != null ) {
ctx.json( new Result( e ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class SchemaTreeRequest extends UIRequest {
public boolean views;
public int depth;
public boolean showTable;
public boolean isCrossModel;

public List<NamespaceType> dataModels;

Expand Down