diff --git a/core/src/main/codegen/PolyAlgParser.jj b/core/src/main/codegen/PolyAlgParser.jj index 08a8c4eae5..99fc757db5 100644 --- a/core/src/main/codegen/PolyAlgParser.jj +++ b/core/src/main/codegen/PolyAlgParser.jj @@ -394,14 +394,9 @@ PolyValue PolyNode() : [t = {name = new PolyString( t.image );}] - [ + ( t = {labels.add(new PolyString( t.image ));} - | - ( - t = {labels.add(new PolyString( t.image ));} - ( t = {labels.add(new PolyString( t.image ));})* - ) - ] + )* [[ key = ( diff --git a/core/src/main/java/org/polypheny/db/algebra/polyalg/PolyAlgUtils.java b/core/src/main/java/org/polypheny/db/algebra/polyalg/PolyAlgUtils.java index 53cfa6c7f8..1722afc045 100644 --- a/core/src/main/java/org/polypheny/db/algebra/polyalg/PolyAlgUtils.java +++ b/core/src/main/java/org/polypheny/db/algebra/polyalg/PolyAlgUtils.java @@ -549,10 +549,7 @@ private String visitPolyEdge( PolyEdge edge, boolean withPrefix ) { private String visitGraphLabelProps( PolyList lbls, PolyDictionary props, PolyString varName ) { String name = varName.isNull() ? "" : varName.toString(); - String labels = lbls.toString(); - if ( lbls.size() < 2 ) { - labels = labels.substring( 1, labels.length() - 1 ); - } + String labels = String.join(":", lbls.stream().map( PolyString::toString ).toList()); String properties = props.map.toString(); if ( properties.equals( "{}" ) ) { properties = ""; diff --git a/core/src/main/java/org/polypheny/db/algebra/polyalg/arguments/EntityArg.java b/core/src/main/java/org/polypheny/db/algebra/polyalg/arguments/EntityArg.java index 5ad8cdd595..aded733642 100644 --- a/core/src/main/java/org/polypheny/db/algebra/polyalg/arguments/EntityArg.java +++ b/core/src/main/java/org/polypheny/db/algebra/polyalg/arguments/EntityArg.java @@ -25,9 +25,11 @@ import org.polypheny.db.algebra.AlgNode; import org.polypheny.db.algebra.polyalg.PolyAlgDeclaration.ParamType; import org.polypheny.db.catalog.entity.Entity; +import org.polypheny.db.catalog.entity.logical.LogicalGraph.SubstitutionGraph; import org.polypheny.db.catalog.entity.logical.LogicalNamespace; import org.polypheny.db.catalog.logistic.DataModel; import org.polypheny.db.catalog.snapshot.Snapshot; +import org.polypheny.db.type.entity.PolyString; public class EntityArg implements PolyAlgArg { @@ -46,8 +48,12 @@ public EntityArg( Entity entity, Snapshot snapshot, DataModel model ) { this.entity = entity; if ( model == DataModel.GRAPH || entity.dataModel == DataModel.GRAPH ) { - // origin or target data model is graph -> only namespaceName is relevant - this.entityName = null; + // origin or target data model is graph + if ( entity instanceof SubstitutionGraph sub && !sub.names.isEmpty() ) { + this.entityName = String.join( ".", sub.names.stream().map( PolyString::toString ).toList() ); + } else { + this.entityName = null; + } } else { this.entityName = entity.getName(); } diff --git a/core/src/main/java/org/polypheny/db/algebra/polyalg/parser/PolyAlgToAlgConverter.java b/core/src/main/java/org/polypheny/db/algebra/polyalg/parser/PolyAlgToAlgConverter.java index 7168d2fd7e..1a2cc01cb9 100644 --- a/core/src/main/java/org/polypheny/db/algebra/polyalg/parser/PolyAlgToAlgConverter.java +++ b/core/src/main/java/org/polypheny/db/algebra/polyalg/parser/PolyAlgToAlgConverter.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; import java.math.BigDecimal; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -161,7 +162,7 @@ private PolyAlgArgs buildArgs( PolyAlgDeclaration decl, List new AggArg( convertAggCall( exp, alias, ctx ) ); case LAX_AGGREGATE -> new LaxAggArg( convertLaxAggCall( exp, alias, ctx ) ); - case ENTITY -> new EntityArg( convertEntity( exp ), snapshot, ctx.dataModel ); + case ENTITY -> new EntityArg( convertEntity( exp, ctx ), snapshot, ctx.dataModel ); case JOIN_TYPE_ENUM -> new EnumArg<>( exp.toEnum( JoinAlgType.class ), pType ); case SEMI_JOIN_TYPE_ENUM -> new EnumArg<>( exp.toEnum( SemiJoinType.class ), pType ); case MODIFY_OP_ENUM -> new EnumArg<>( exp.toEnum( Modify.Operation.class ), pType ); @@ -361,8 +362,8 @@ private RexNode convertRexLiteral( PolyAlgLiteral literal, AlgDataType type, Con } - private Entity convertEntity( PolyAlgExpression exp ) { - String[] names = exp.toIdentifier().split( "\\.", 3 ); + private Entity convertEntity( PolyAlgExpression exp, Context ctx ) { + String[] names = exp.toIdentifier().split( "\\.", 2 ); GenericRuntimeException exception = new GenericRuntimeException( "Invalid entity name: " + String.join( ".", names ) ); String namespaceName; String entityName = null; @@ -374,12 +375,14 @@ private Entity convertEntity( PolyAlgExpression exp ) { } else { throw exception; } - LogicalNamespace ns = snapshot.getNamespace( namespaceName ).orElseThrow( () -> new GenericRuntimeException( "no namespace named " + namespaceName ) ); return switch ( ns.dataModel ) { case RELATIONAL -> { if ( entityName == null ) { yield new SubstitutionGraph( ns.id, "sub", false, ns.caseSensitive, List.of() ); + } else if ( ctx.dataModel == DataModel.GRAPH ) { + List subNames = Arrays.asList( entityName.split( "\\." ) ); + yield new SubstitutionGraph( ns.id, "sub", false, ns.caseSensitive, subNames.stream().map( PolyString::of ).toList() ); } yield snapshot.rel().getTable( ns.id, entityName ).orElseThrow( () -> exception ); } diff --git a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java index 215d43d924..5071c62157 100644 --- a/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java +++ b/dbms/src/main/java/org/polypheny/db/processing/AbstractQueryProcessor.java @@ -256,7 +256,9 @@ private void attachQueryPlans( AlgRoot logicalRoot ) { AlgOptUtil.dumpPlan( "Logical Query Plan", logicalRoot.alg, ExplainFormat.JSON, ExplainLevel.ALL_ATTRIBUTES ) ); queryAnalyzer.registerInformation( informationQueryPlan ); - testPolyAlgParserDuringDevelopment(logicalRoot.alg); // TODO: Delete as soon as PolyAlgParser is working + + attachPolyAlgPlan(logicalRoot.alg); + //testPolyAlgParserDuringDevelopment(logicalRoot.alg); // TODO: Delete as soon as PolyAlgParser is working } private void testPolyAlgParserDuringDevelopment(AlgNode alg) { @@ -264,8 +266,6 @@ private void testPolyAlgParserDuringDevelopment(AlgNode alg) { AlgCluster cluster = AlgCluster.create( new VolcanoPlanner(), new RexBuilder( factory ), null, null ); Snapshot snapshot = Catalog.snapshot(); - attachPolyAlgPlan(alg); - StringBuilder sb = new StringBuilder(); alg.buildPolyAlgebra( sb, "" ); @@ -304,12 +304,10 @@ private void testPolyAlgParserDuringDevelopment(AlgNode alg) { } private void attachPolyAlgPlan(AlgNode alg) { - System.out.println( "===== Logical Query Plan as JSON =====" ); ObjectMapper objectMapper = new ObjectMapper(); ObjectNode objectNode = alg.serializePolyAlgebra(objectMapper); try { String jsonString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); - System.out.println(jsonString); InformationManager queryAnalyzer = statement.getTransaction().getQueryAnalyzer(); InformationPage page = new InformationPage( "PolyAlg Query Plan" ).setLabel( "plans" ); diff --git a/webui/src/main/java/org/polypheny/db/webui/Crud.java b/webui/src/main/java/org/polypheny/db/webui/Crud.java index 8bd4a8910e..a4f0ae4b77 100644 --- a/webui/src/main/java/org/polypheny/db/webui/Crud.java +++ b/webui/src/main/java/org/polypheny/db/webui/Crud.java @@ -2955,6 +2955,7 @@ public void buildPlanFromPolyAlg( final Context ctx ) { AlgNode node = PolyPlanBuilder.buildFromPolyAlg( request.polyAlg ).alg; ctx.json( node.serializePolyAlgebra( new ObjectMapper() ) ); } catch ( Exception e ) { + e.printStackTrace(); // TODO: remove after when PolyAlg is finished ctx.json( Map.of( "errorMsg", e.getMessage() ) ); ctx.status( 400 ); }