From d01636fe8f2d9212a565a9b93af5065c656234ce Mon Sep 17 00:00:00 2001 From: Sascha Peukert Date: Fri, 12 Oct 2018 15:25:01 +0200 Subject: [PATCH] Final changes to procedure signature and structure --- .../BuiltInSchemaProceduresIT.java | 150 ++++++++++-------- .../integrationtest/BuiltInProceduresIT.java | 9 +- .../builtinprocs/BuiltInProcedures.java | 4 +- .../NodePropertySchemaInfoResult.java | 11 +- .../RelationshipPropertySchemaInfoResult.java | 4 +- .../kernel/builtinprocs/SchemaCalculator.java | 23 ++- .../builtinprocs/BuiltInProceduresTest.java | 12 +- 7 files changed, 120 insertions(+), 93 deletions(-) diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInSchemaProceduresIT.java b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInSchemaProceduresIT.java index a47b19f9c0ae6..c4632c06dffb4 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInSchemaProceduresIT.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInSchemaProceduresIT.java @@ -43,8 +43,27 @@ public class BuiltInSchemaProceduresIT extends KernelIntegrationTest { - private final String[] nodesProcedureName = {"db", "schema", "nodeProperties"}; - private final String[] relsProcedureName = {"db", "schema", "edgeProperties"}; + private final String[] nodesProcedureName = {"db", "schema", "nodeTypeProperties"}; + private final String[] relsProcedureName = {"db", "schema", "relTypeProperties"}; + + @Test + public void testWeirdLabelName() throws Throwable + { + // Given + + // Node1: (:`This:is_a:label` {color: "red"}) + + createNode( Arrays.asList( "`This:is_a:label`" ), Arrays.asList( "color" ), Arrays.asList( Values.stringValue( "red" ) ) ); + + // When + RawIterator stream = + procs().procedureCallRead( procs().procedureGet( procedureName( nodesProcedureName ) ).id(), new Object[0] ); + + // Then + assertThat( asList( stream ), containsInAnyOrder( + equalTo( nodeEntry(":``This:is_a:label``", Arrays.asList( "`This:is_a:label`" ), "color", Arrays.asList( "String" ), true) ) ) ); +// printStream( stream ); + } @Test public void testNodePropertiesRegardlessOfCreationOrder1() throws Throwable @@ -63,9 +82,9 @@ public void testNodePropertiesRegardlessOfCreationOrder1() throws Throwable // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("A", "color", Arrays.asList( "String" ), false) ), - equalTo( entry("A", "size", Arrays.asList( "String" ), false) ), - equalTo( entry("A", "origin", Arrays.asList( "String" ), false) ) ) ); + equalTo( nodeEntry(":`A`", Arrays.asList( "A" ), "color", Arrays.asList( "String" ), false) ), + equalTo( nodeEntry(":`A`", Arrays.asList( "A" ), "size", Arrays.asList( "String" ), false) ), + equalTo( nodeEntry(":`A`", Arrays.asList( "A" ), "origin", Arrays.asList( "String" ), false) ) ) ); // printStream( stream ); } @@ -86,9 +105,9 @@ public void testNodePropertiesRegardlessOfCreationOrder2() throws Throwable // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("B", "color", Arrays.asList( "String" ), false) ), - equalTo( entry("B", "size", Arrays.asList( "String" ), false) ), - equalTo( entry("B", "origin", Arrays.asList( "String" ), false) ) ) ); + equalTo( nodeEntry(":`B`", Arrays.asList( "B" ), "color", Arrays.asList( "String" ), false) ), + equalTo( nodeEntry(":`B`", Arrays.asList( "B" ), "size", Arrays.asList( "String" ), false) ), + equalTo( nodeEntry(":`B`", Arrays.asList( "B" ), "origin", Arrays.asList( "String" ), false) ) ) ); // printStream( stream ); } @@ -110,10 +129,10 @@ public void testNodePropertiesRegardlessOfCreationOrder3() throws Throwable // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("C", "color", Arrays.asList( "String" ), false) ), - equalTo( entry("C", "size", Arrays.asList( "String" ), false) ), - equalTo( entry("C", "origin", Arrays.asList( "String" ), false) ), - equalTo( entry("C", "active", Arrays.asList( "Boolean" ), false) ) ) ); + equalTo( nodeEntry(":`C`", Arrays.asList( "C" ), "color", Arrays.asList( "String" ), false) ), + equalTo( nodeEntry(":`C`", Arrays.asList( "C" ), "size", Arrays.asList( "String" ), false) ), + equalTo( nodeEntry(":`C`", Arrays.asList( "C" ), "origin", Arrays.asList( "String" ), false) ), + equalTo( nodeEntry(":`C`", Arrays.asList( "C" ), "active", Arrays.asList( "Boolean" ), false) ) ) ); // printStream( stream ); } @@ -138,9 +157,9 @@ public void testRelsPropertiesRegardlessOfCreationOrder1() throws Throwable // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("R", "color", Arrays.asList( "String" ), false) ), - equalTo( entry("R", "size", Arrays.asList( "String" ), false) ), - equalTo( entry("R", "origin", Arrays.asList( "String" ), false) ) ) ); + equalTo( relEntry(":`R`", "color", Arrays.asList( "String" ), false) ), + equalTo( relEntry(":`R`", "size", Arrays.asList( "String" ), false) ), + equalTo( relEntry(":`R`", "origin", Arrays.asList( "String" ), false) ) ) ); // printStream( stream ); } @@ -164,9 +183,9 @@ public void testRelsPropertiesRegardlessOfCreationOrder2() throws Throwable // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("R", "color", Arrays.asList( "String" ), false) ), - equalTo( entry("R", "size", Arrays.asList( "String" ), false) ), - equalTo( entry("R", "origin", Arrays.asList( "String" ), false) ) ) ); + equalTo( relEntry(":`R`", "color", Arrays.asList( "String" ), false) ), + equalTo( relEntry(":`R`", "size", Arrays.asList( "String" ), false) ), + equalTo( relEntry(":`R`", "origin", Arrays.asList( "String" ), false) ) ) ); // printStream( stream ); } @@ -192,10 +211,10 @@ public void testRelsPropertiesRegardlessOfCreationOrder3() throws Throwable // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("R", "color", Arrays.asList( "String" ), false) ), - equalTo( entry("R", "size", Arrays.asList( "String" ), false) ), - equalTo( entry("R", "origin", Arrays.asList( "String" ), false) ), - equalTo( entry("R", "active", Arrays.asList( "Boolean" ), false))) ); + equalTo( relEntry(":`R`", "color", Arrays.asList( "String" ), false) ), + equalTo( relEntry(":`R`", "size", Arrays.asList( "String" ), false) ), + equalTo( relEntry(":`R`", "origin", Arrays.asList( "String" ), false) ), + equalTo( relEntry(":`R`", "active", Arrays.asList( "Boolean" ), false))) ); // printStream( stream ); } @@ -216,8 +235,9 @@ public void testNodesShouldNotDependOnOrderOfCreationWithOverlap() throws Throwa procs().procedureCallRead( procs().procedureGet( procedureName( nodesProcedureName ) ).id(), new Object[0] ); // Then - assertThat( asList( stream ), containsInAnyOrder( equalTo( new Object[]{"B", "type", Arrays.asList( "String" ), true} ), - equalTo( entry("B", "size", Arrays.asList( "Integer" ), false) ) ) ); + assertThat( asList( stream ), containsInAnyOrder( + equalTo( nodeEntry(":`B`", Arrays.asList( "B" ), "type", Arrays.asList( "String" ), true) ), + equalTo( nodeEntry(":`B`", Arrays.asList( "B" ), "size", Arrays.asList( "Integer" ), false) ) ) ); // printStream( stream ); } @@ -239,8 +259,8 @@ public void testNodesShouldNotDependOnOrderOfCreationWithOverlap2() throws Throw // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( new Object[]{"B", "type", Arrays.asList( "String" ), true} ), - equalTo( entry("B", "size", Arrays.asList( "Integer" ), false) ) ) ); + equalTo( nodeEntry(":`B`", Arrays.asList( "B" ), "type", Arrays.asList( "String" ), true) ), + equalTo( nodeEntry(":`B`", Arrays.asList( "B" ), "size", Arrays.asList( "Integer" ), false) ) ) ); // printStream( stream ); } @@ -264,8 +284,8 @@ public void testRelsShouldNotDependOnOrderOfCreationWithOverlap() throws Throwab // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("B", "type", Arrays.asList( "String" ), true) ), - equalTo( entry("B", "size", Arrays.asList( "Integer" ), false) ) ) ); + equalTo( relEntry(":`B`", "type", Arrays.asList( "String" ), true) ), + equalTo( relEntry(":`B`", "size", Arrays.asList( "Integer" ), false) ) ) ); // printStream( stream ); } @@ -289,8 +309,8 @@ public void testRelsShouldNotDependOnOrderOfCreationWithOverlap2() throws Throwa // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("B", "type", Arrays.asList( "String" ), true) ), - equalTo( entry("B", "size", Arrays.asList( "Integer" ), false) ) ) ); + equalTo( relEntry(":`B`", "type", Arrays.asList( "String" ), true) ), + equalTo( relEntry(":`B`", "size", Arrays.asList( "Integer" ), false) ) ) ); // printStream( stream ); } @@ -316,11 +336,11 @@ public void testWithAllDifferentNodes() throws Throwable // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("A:B", "prop1", Arrays.asList( "String" ), true) ), - equalTo( entry("A:B", "prop2", Arrays.asList( "Integer" ), true) ), - equalTo( entry("B", "prop1", Arrays.asList( "Boolean" ), true) ), - equalTo( entry("C", "prop1", Arrays.asList( "StringArray" ), true) ), - equalTo( entry("", null, null, false) ) ) ); + equalTo( nodeEntry(":`A`:`B`", Arrays.asList( "A", "B" ), "prop1", Arrays.asList( "String" ), true) ), + equalTo( nodeEntry(":`A`:`B`", Arrays.asList( "A", "B" ), "prop2", Arrays.asList( "Integer" ), true) ), + equalTo( nodeEntry(":`B`", Arrays.asList( "B" ), "prop1", Arrays.asList( "Boolean" ), true) ), + equalTo( nodeEntry(":`C`", Arrays.asList( "C" ), "prop1", Arrays.asList( "StringArray" ), true) ), + equalTo( nodeEntry("", Arrays.asList(), null, null, false) ) ) ); // printStream( stream ); } @@ -341,7 +361,8 @@ public void testWithSimilarNodes() throws Throwable procs().procedureCallRead( procs().procedureGet( procedureName( nodesProcedureName ) ).id(), new Object[0] ); // Then - assertThat( asList( stream ), contains( equalTo( entry("A", "prop1", Arrays.asList( "String" ), true) ) ) ); + assertThat( asList( stream ), contains( + equalTo( nodeEntry(":`A`", Arrays.asList("A"), "prop1", Arrays.asList( "String" ), true) ) ) ); // printStream( stream ); } @@ -367,9 +388,9 @@ public void testWithSimilarNodesHavingDifferentPropertyValueTypes() throws Throw // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("", "prop1", Arrays.asList( "String" ), true) ), - equalTo( entry("", "prop2", Arrays.asList( "Integer", "Float" ), false) ), - equalTo( entry("", "prop3", Arrays.asList( "String", "Boolean" ), false) ) ) ); + equalTo( nodeEntry("", Arrays.asList(), "prop1", Arrays.asList( "String" ), true) ), + equalTo( nodeEntry("", Arrays.asList(), "prop2", Arrays.asList( "Integer", "Float" ), false) ), + equalTo( nodeEntry("", Arrays.asList(), "prop3", Arrays.asList( "String", "Boolean" ), false) ) ) ); // printStream( stream ); } @@ -395,9 +416,9 @@ public void testWithSimilarNodesShouldNotDependOnOrderOfCreation() throws Throwa // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("", "prop1", Arrays.asList( "String" ), false) ), - equalTo( entry("", "prop2", Arrays.asList( "Integer", "Float" ), false) ), - equalTo( entry("", "prop3", Arrays.asList( "String", "Boolean" ), false) ) ) ); + equalTo( nodeEntry("", Arrays.asList(), "prop1", Arrays.asList( "String" ), false) ), + equalTo( nodeEntry("", Arrays.asList(), "prop2", Arrays.asList( "Integer", "Float" ), false) ), + equalTo( nodeEntry("", Arrays.asList(), "prop3", Arrays.asList( "String", "Boolean" ), false) ) ) ); // printStream( stream ); } @@ -424,10 +445,10 @@ public void testWithAllDifferentRelationships() throws Throwable // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("R", "prop1", Arrays.asList( "String" ), true) ), - equalTo( entry("R", "prop2", Arrays.asList( "Integer" ), true) ), - equalTo( entry("X", "prop1", Arrays.asList( "Boolean" ), true) ), - equalTo( entry("Z", null, null, false) ) ) ); + equalTo( relEntry(":`R`", "prop1", Arrays.asList( "String" ), true) ), + equalTo( relEntry(":`R`", "prop2", Arrays.asList( "Integer" ), true) ), + equalTo( relEntry(":`X`", "prop1", Arrays.asList( "Boolean" ), true) ), + equalTo( relEntry(":`Z`", null, null, false) ) ) ); // printStream( stream ); } @@ -452,7 +473,7 @@ public void testWithSimilarRelationships() throws Throwable // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("R", "prop1", Arrays.asList( "String" ), true ) ) ) ); + equalTo( relEntry(":`R`", "prop1", Arrays.asList( "String" ), true ) ) ) ); //printStream( stream ); } @@ -477,9 +498,9 @@ public void testSchemaWithRelationshipWithoutProperties() throws Throwable // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("R", "prop1", Arrays.asList( "String" ), false) ), - equalTo( entry("R", "prop2", Arrays.asList( "Integer" ), false) ), - equalTo( entry("R", "prop3", Arrays.asList( "Boolean" ), false) ) ) ); + equalTo( relEntry(":`R`", "prop1", Arrays.asList( "String" ), false) ), + equalTo( relEntry(":`R`", "prop2", Arrays.asList( "Integer" ), false) ), + equalTo( relEntry(":`R`", "prop3", Arrays.asList( "Boolean" ), false) ) ) ); //printStream( stream ); } @@ -507,9 +528,9 @@ public void testWithSimilarRelationshipsHavingDifferentPropertyValueTypes() thro // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("R", "prop1", Arrays.asList( "String" ), true) ), - equalTo( entry("R", "prop2", Arrays.asList( "Integer", "Float" ), false) ), - equalTo( entry("R", "prop3", Arrays.asList( "String", "Boolean" ), false) ) ) ); + equalTo( relEntry(":`R`", "prop1", Arrays.asList( "String" ), true) ), + equalTo( relEntry(":`R`", "prop2", Arrays.asList( "Integer", "Float" ), false) ), + equalTo( relEntry(":`R`", "prop3", Arrays.asList( "String", "Boolean" ), false) ) ) ); //printStream( stream ); } @@ -538,9 +559,9 @@ public void testWithSimilarRelationshipsShouldNotDependOnOrderOfCreation() throw // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("R", "prop1", Arrays.asList( "String" ), false) ), - equalTo( entry("R", "prop2", Arrays.asList( "Integer", "Float" ), false) ), - equalTo( entry("R", "prop3", Arrays.asList( "String", "Boolean" ), false) ) ) ); + equalTo( relEntry(":`R`", "prop1", Arrays.asList( "String" ), false) ), + equalTo( relEntry(":`R`", "prop2", Arrays.asList( "Integer", "Float" ), false) ), + equalTo( relEntry(":`R`", "prop3", Arrays.asList( "String", "Boolean" ), false) ) ) ); //printStream( stream ); } @@ -569,16 +590,21 @@ public void testWithNullableProperties() throws Throwable // Then assertThat( asList( stream ), containsInAnyOrder( - equalTo( entry("A", "prop1", Arrays.asList( "String" ), true) ), - equalTo( entry("A", "prop2", Arrays.asList( "Integer" ), false) ), - equalTo( entry("A", "prop3", Arrays.asList( "Boolean" ), false) ), - equalTo( entry("B", "prop1", Arrays.asList( "String" ), false) ), - equalTo( entry("B", "prop2", Arrays.asList( "Integer" ), false) ) ) ); + equalTo( nodeEntry(":`A`", Arrays.asList("A"), "prop1", Arrays.asList( "String" ), true) ), + equalTo( nodeEntry(":`A`", Arrays.asList("A"), "prop2", Arrays.asList( "Integer" ), false) ), + equalTo( nodeEntry(":`A`", Arrays.asList("A"), "prop3", Arrays.asList( "Boolean" ), false) ), + equalTo( nodeEntry(":`B`", Arrays.asList("B"), "prop1", Arrays.asList( "String" ), false) ), + equalTo( nodeEntry(":`B`", Arrays.asList("B"), "prop2", Arrays.asList( "Integer" ), false) ) ) ); //printStream( stream ); } - private Object[] entry( String labelsOrRelType, String propertyName, List propertyValueTypes, Boolean mandatory ) + private Object[] nodeEntry( String escapedLabels, List labels, String propertyName, List propertyValueTypes, Boolean mandatory ) + { + return new Object[]{escapedLabels, labels, propertyName, propertyValueTypes, mandatory}; + } + + private Object[] relEntry( String labelsOrRelType, String propertyName, List propertyValueTypes, Boolean mandatory ) { return new Object[]{labelsOrRelType, propertyName, propertyValueTypes, mandatory}; } diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/impl/api/integrationtest/BuiltInProceduresIT.java b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/impl/api/integrationtest/BuiltInProceduresIT.java index f40c2871eeafc..9aa62c5b56c72 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/impl/api/integrationtest/BuiltInProceduresIT.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/impl/api/integrationtest/BuiltInProceduresIT.java @@ -149,11 +149,12 @@ public void listProcedures() throws Throwable "Show the schema of the data.", "READ" ), proc( "db.schema.visualization","() :: (nodes :: LIST? OF NODE?, relationships :: LIST? OF RELATIONSHIP?)", "Visualize the schema of the data. Replaces db.schema.", "READ" ), - proc( "db.schema.nodeProperties", "() :: (nodeType :: STRING?, propertyName :: STRING?, " + - "propertyTypes :: LIST? OF STRING?, mandatory :: BOOLEAN?)", "Show the derived property schema of the nodes in tabular form.", - "READ" ), - proc( "db.schema.edgeProperties", "() :: (relationshipType :: STRING?, propertyName :: STRING?, " + + proc( "db.schema.nodeTypeProperties", + "() :: (nodeType :: STRING?, nodeLabels :: LIST? OF STRING?, propertyName :: STRING?, " + "propertyTypes :: LIST? OF STRING?, mandatory :: BOOLEAN?)", + "Show the derived property schema of the nodes in tabular form.", "READ" ), + proc( "db.schema.relTypeProperties", "() :: (relType :: STRING?, " + + "propertyName :: STRING?, propertyTypes :: LIST? OF STRING?, mandatory :: BOOLEAN?)", "Show the derived property schema of the relationships in tabular form.", "READ" ), proc( "db.relationshipTypes", "() :: (relationshipType :: " + "STRING?)", "List all relationship types in the database.", "READ" ), diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInProcedures.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInProcedures.java index 42657c8f8c2ff..42f856097a751 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInProcedures.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInProcedures.java @@ -215,14 +215,14 @@ public void resampleOutdatedIndexes() } } - @Procedure( name = "db.schema.nodeProperties", mode = Mode.READ ) + @Procedure( name = "db.schema.nodeTypeProperties", mode = Mode.READ ) @Description( "Show the derived property schema of the nodes in tabular form." ) public Stream nodePropertySchema() { return new SchemaCalculator( tx ).calculateTabularResultStreamForNodes(); } - @Procedure( name = "db.schema.edgeProperties", mode = Mode.READ ) + @Procedure( name = "db.schema.relTypeProperties", mode = Mode.READ ) @Description( "Show the derived property schema of the relationships in tabular form." ) public Stream relationshipPropertySchema() { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/NodePropertySchemaInfoResult.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/NodePropertySchemaInfoResult.java index a7fd81fe867cb..94d92ef89f37b 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/NodePropertySchemaInfoResult.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/NodePropertySchemaInfoResult.java @@ -24,10 +24,14 @@ public class NodePropertySchemaInfoResult { /** - * A combination of labels interleaved by ":" + * A combination of escaped label names interleaved by ":" */ public final String nodeType; + /** + * A list of label names + */ + public final List nodeLabels; /** * A property name that occurs on the given label combination or null */ @@ -43,9 +47,10 @@ public class NodePropertySchemaInfoResult */ public final boolean mandatory; - public NodePropertySchemaInfoResult( String nodeLabels, String propertyName, List cypherTypes, boolean mandatory ) + public NodePropertySchemaInfoResult( String nodeType, List nodeLabelsList, String propertyName, List cypherTypes, boolean mandatory ) { - this.nodeType = nodeLabels; + this.nodeType = nodeType; + this.nodeLabels = nodeLabelsList; this.propertyName = propertyName; this.propertyTypes = cypherTypes; this.mandatory = mandatory; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/RelationshipPropertySchemaInfoResult.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/RelationshipPropertySchemaInfoResult.java index a7bf69740b81d..37abf79b5e74c 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/RelationshipPropertySchemaInfoResult.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/RelationshipPropertySchemaInfoResult.java @@ -26,7 +26,7 @@ public class RelationshipPropertySchemaInfoResult /** * A relationship type */ - public final String relationshipType; + public final String relType; /** * A property name that occurs on the given relationship type or null @@ -45,7 +45,7 @@ public class RelationshipPropertySchemaInfoResult public RelationshipPropertySchemaInfoResult( String relType, String propertyName, List cypherTypes, boolean mandatory ) { - this.relationshipType = relType; + this.relType = relType; this.propertyName = propertyName; this.propertyTypes = cypherTypes; this.mandatory = mandatory; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaCalculator.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaCalculator.java index b316eebb55c94..ab4b7b4ca5cfa 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaCalculator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaCalculator.java @@ -86,7 +86,7 @@ public Stream calculateTabularResultStreamForNodes // go through all labels to get actual names addNamesToCollection( tokenRead.labelsGetAllTokens(), nodeMappings.labelIdToLabelName ); - return produceResultsForNodes(nodeMappings).stream(); + return produceResultsForNodes( nodeMappings ).stream(); } public Stream calculateTabularResultStreamForRels() @@ -107,6 +107,7 @@ private List produceResultsForRelationship { // lookup typ name String name = relMappings.relationshipTypIdToRelationshipName.get( typeId ); + name = ":`" + name + "`"; // escaping // lookup property value types MutableIntSet propertyIds = relMappings.relationshipTypeIdToPropertyKeys.get( typeId ); @@ -116,18 +117,19 @@ private List produceResultsForRelationship } else { + String finalName = name; propertyIds.forEach( propId -> { // lookup propId name and valueGroup String propName = propertyIdToPropertyNameMapping.get( propId ); ValueTypeListHelper valueTypeListHelper = relMappings.relationshipTypeIdANDPropertyTypeIdToValueType.get( Pair.of( typeId, propId ) ); if ( relMappings.nullableRelationshipTypes.contains( typeId ) ) { - results.add( new RelationshipPropertySchemaInfoResult( name, propName, valueTypeListHelper.getCypherTypesList(), + results.add( new RelationshipPropertySchemaInfoResult( finalName, propName, valueTypeListHelper.getCypherTypesList(), false ) ); } else { - results.add( new RelationshipPropertySchemaInfoResult( name, propName, valueTypeListHelper.getCypherTypesList(), + results.add( new RelationshipPropertySchemaInfoResult( finalName, propName, valueTypeListHelper.getCypherTypesList(), valueTypeListHelper.isMandatory() ) ); } } ); @@ -152,14 +154,7 @@ private List produceResultsForNodes( NodeMappings StringBuilder labelsConcatenator = new StringBuilder(); for ( String item : labelNames ) { - if ( labelsConcatenator.toString().equals( "" ) ) - { - labelsConcatenator.append( item ); - } - else - { - labelsConcatenator.append( ":" ).append( item ); - } + labelsConcatenator.append( ":`" ).append( item ).append( "`" ); } String labels = labelsConcatenator.toString(); @@ -167,7 +162,7 @@ private List produceResultsForNodes( NodeMappings MutableIntSet propertyIds = nodeMappings.labelSetToPropertyKeys.get( labelSet ); if ( propertyIds.size() == 0 ) { - results.add( new NodePropertySchemaInfoResult( labels, null, null, false ) ); + results.add( new NodePropertySchemaInfoResult( labels, labelNames, null, null, false ) ); } else { @@ -177,11 +172,11 @@ private List produceResultsForNodes( NodeMappings ValueTypeListHelper valueTypeListHelper = nodeMappings.labelSetANDNodePropertyKeyIdToValueType.get( Pair.of( labelSet, propId ) ); if ( nodeMappings.nullableLabelSets.contains( labelSet ) ) { - results.add( new NodePropertySchemaInfoResult( labels, propName, valueTypeListHelper.getCypherTypesList(), false ) ); + results.add( new NodePropertySchemaInfoResult( labels, labelNames, propName, valueTypeListHelper.getCypherTypesList(), false ) ); } else { - results.add( new NodePropertySchemaInfoResult( labels, propName, valueTypeListHelper.getCypherTypesList(), + results.add( new NodePropertySchemaInfoResult( labels, labelNames, propName, valueTypeListHelper.getCypherTypesList(), valueTypeListHelper.isMandatory() ) ); } } ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInProceduresTest.java b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInProceduresTest.java index 1145ca8d8a89f..4af598a39185f 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInProceduresTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInProceduresTest.java @@ -289,13 +289,13 @@ public void shouldListCorrectBuiltinProcedures() throws Throwable record( "db.schema.visualization", "db.schema.visualization() :: (nodes :: LIST? OF NODE?, relationships :: LIST? OF RELATIONSHIP?)", "Visualize the schema of the data. Replaces db.schema.", "READ" ), - record( "db.schema.nodeProperties", - "db.schema.nodeProperties() :: (nodeType :: STRING?, propertyName :: STRING?," + - " propertyTypes :: LIST? OF STRING?, mandatory :: BOOLEAN?)", - "Show the derived property schema of the nodes in tabular form.", "READ" ), - record( "db.schema.edgeProperties", - "db.schema.edgeProperties() :: (relationshipType :: STRING?, propertyName :: STRING?, " + + record( "db.schema.nodeTypeProperties", + "db.schema.nodeTypeProperties() :: (nodeType :: STRING?, nodeLabels :: LIST? OF STRING?, propertyName :: STRING?, " + "propertyTypes :: LIST? OF STRING?, mandatory :: BOOLEAN?)", + "Show the derived property schema of the nodes in tabular form.", "READ" ), + record( "db.schema.relTypeProperties", + "db.schema.relTypeProperties() :: (relType :: STRING?, propertyName :: STRING?, propertyTypes :: LIST? OF STRING?," + + " mandatory :: BOOLEAN?)", "Show the derived property schema of the relationships in tabular form.", "READ" ), record( "db.index.explicit.searchNodes", "db.index.explicit.searchNodes(indexName :: STRING?, query :: ANY?) :: (node :: NODE?, weight :: FLOAT?)",