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 f722917613e8..a46aa11dfefc 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 @@ -61,6 +61,7 @@ import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.procedure.Context; import org.neo4j.procedure.Description; +import org.neo4j.procedure.Mode; import org.neo4j.procedure.Name; import org.neo4j.procedure.Procedure; @@ -193,6 +194,21 @@ public void resampleOutdatedIndexes() } } + @Procedure( name = "db.schemaAsTable", mode = Mode.READ ) // I am open about a better name for this. Something like db.propertySchema maybe? + @Description( "Show the schema of the data in tabular form." ) + public Stream schemaAsTable() + { + return new SchemaCalculator( tx ).calculateTabularResultStream(); + } + + // TODO: Next step -> graph with more info then db.schema currently has +// @Procedure( value = "db.schema.graph", mode = Mode.READ ) +// @Description( "Show the schema of the data." ) // old description +// public Stream schemaAsGraph() +// { +// return new SchemaCalculator( db, tx ).calculateGraphResultStream(); +// } + @Description( "Show the schema of the data." ) @Procedure( name = "db.schema", mode = READ ) public Stream metaGraph() diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInSchemaProcedures.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInSchemaProcedures.java deleted file mode 100644 index ede659073506..000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInSchemaProcedures.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2002-2018 "Neo4j," - * Neo4j Sweden AB [http://neo4j.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.neo4j.kernel.builtinprocs; - -import java.util.List; -import java.util.stream.Stream; - -import org.neo4j.kernel.api.KernelTransaction; -import org.neo4j.kernel.internal.GraphDatabaseAPI; -import org.neo4j.procedure.Context; -import org.neo4j.procedure.Description; -import org.neo4j.procedure.Mode; -import org.neo4j.procedure.Procedure; - -public class BuiltInSchemaProcedures -{ - @Context - public GraphDatabaseAPI db; - - @Context - public KernelTransaction tx; - - @Procedure( name = "db.schemaAsTable", mode = Mode.READ ) - @Description( "Show the schema of the data in tabular form." ) - public Stream schemaAsTable() - { - return new SchemaCalculator( tx ).calculateTabularResultStream(); - } - - // TODO: Next step -// @Procedure( value = "db.schema.graph", mode = Mode.READ ) // TODO: Change to db.schema when ready to completely replace old one (if possible) -// @Description( "Show the schema of the data." ) // old description -// public Stream schemaAsGraph() -// { -// return new SchemaCalculator( db, tx ).calculateGraphResultStream(); -// } - - public static class SchemaInfoResult - { - /** - * Indicates whether the entry is a node or a relationship - */ - public final String type; - /** - * A combination of labels or a relationship - */ - public final List nodeLabelsOrRelType; - /** - * A property that occurs on the given label combination / relationship type - */ - public final String property; - /** - * The CypherType of the given property on the given label combination / relationship type - */ - public final String cypherType; - - public SchemaInfoResult( String type, List nodeLabelsOrRelType, String property, String cypherType ) - { - this.type = type; - this.nodeLabelsOrRelType = nodeLabelsOrRelType; - this.property = property; - this.cypherType = cypherType; - } - } -} 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 5fc0378b6722..38bba8d6bb19 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 @@ -76,20 +76,20 @@ public class SchemaCalculator this.ktx = ktx; } - public Stream calculateTabularResultStream() + public Stream calculateTabularResultStream() { calculateSchema(); - List results = new ArrayList<>(); + List results = new ArrayList<>(); results.addAll( produceResultsForNodes() ); results.addAll( produceResultsForRelationships() ); return results.stream(); } - private List produceResultsForRelationships() + private List produceResultsForRelationships() { - List results = new ArrayList<>(); + List results = new ArrayList<>(); for ( Integer typeId : relationshipTypeIdToPropertyKeysMapping.keySet() ) { // lookup typ name @@ -99,7 +99,7 @@ private List produceResultsForRelation Set propertyIds = relationshipTypeIdToPropertyKeysMapping.get( typeId ); if ( propertyIds.size() == 0 ) { - results.add( new BuiltInSchemaProcedures.SchemaInfoResult( RELATIONSHIP, Collections.singletonList( name ), null, null ) ); + results.add( new SchemaInfoResult( RELATIONSHIP, Collections.singletonList( name ), null, null ) ); } else { @@ -108,7 +108,7 @@ private List produceResultsForRelation // lookup propId name and valueGroup String propName = propertyIdToPropertylNameMapping.get( propId ); ValueTypeDecider valueTypeDecider = relationshipTypeIdANDPropertyTypeIdToValueTypeMapping.get( Pair.of( typeId, propId ) ); - results.add( new BuiltInSchemaProcedures.SchemaInfoResult( RELATIONSHIP, Collections.singletonList( name ), propName, + results.add( new SchemaInfoResult( RELATIONSHIP, Collections.singletonList( name ), propName, valueTypeDecider.getCypherTypeString() ) ); } } @@ -116,9 +116,9 @@ private List produceResultsForRelation return results; } - private List produceResultsForNodes() + private List produceResultsForNodes() { - List results = new ArrayList<>(); + List results = new ArrayList<>(); for ( LabelSet labelSet : labelSetToPropertyKeysMapping.keySet() ) { // lookup label names and produce list of names @@ -133,7 +133,7 @@ private List produceResultsForNodes() Set propertyIds = labelSetToPropertyKeysMapping.get( labelSet ); if ( propertyIds.size() == 0 ) { - results.add( new BuiltInSchemaProcedures.SchemaInfoResult( NODE, labelNames, null, null ) ); + results.add( new SchemaInfoResult( NODE, labelNames, null, null ) ); } else { @@ -142,7 +142,7 @@ private List produceResultsForNodes() // lookup propId name and valueGroup String propName = propertyIdToPropertylNameMapping.get( propId ); ValueTypeDecider valueTypeDecider = labelSetANDNodePropertyKeyIdToValueTypeMapping.get( Pair.of( labelSet, propId ) ); - results.add( new BuiltInSchemaProcedures.SchemaInfoResult( NODE, labelNames, propName, valueTypeDecider.getCypherTypeString() ) ); + results.add( new SchemaInfoResult( NODE, labelNames, propName, valueTypeDecider.getCypherTypeString() ) ); } } } @@ -222,7 +222,7 @@ private void scanEverythingBelongingToRelationships( Read dataRead, CursorFactor { // we can and need to skip this if we found the empty set oldPropertyKeySet.removeAll( propertyIds ); - oldPropertyKeySet.forEach( ( id ) -> { + oldPropertyKeySet.forEach( id -> { Pair key = Pair.of( typeId, id ); relationshipTypeIdANDPropertyTypeIdToValueTypeMapping.get( key ).setNullable(); } ); @@ -264,7 +264,7 @@ private void scanEverythingBelongingToNodes( Read dataRead, CursorFactory cursor { // we can and need (!) to skip this if we found the empty set oldPropertyKeySet.removeAll( propertyIds ); - oldPropertyKeySet.forEach( ( id ) -> { + oldPropertyKeySet.forEach( id -> { Pair key = Pair.of( labels, id ); labelSetANDNodePropertyKeyIdToValueTypeMapping.get( key ).setNullable(); } ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaInfoResult.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaInfoResult.java new file mode 100644 index 000000000000..d873d1096c28 --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaInfoResult.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2002-2018 "Neo4j," + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.kernel.builtinprocs; + +import java.util.List; + +public class SchemaInfoResult +{ + /** + * Indicates whether the entry is a node or a relationship + */ + public final String type; + /** + * A combination of labels or a relationship + */ + public final List nodeLabelsOrRelType; + /** + * A property that occurs on the given label combination / relationship type + */ + public final String property; + /** + * The CypherType of the given property on the given label combination / relationship type + */ + public final String cypherType; + + public SchemaInfoResult( String type, List nodeLabelsOrRelType, String property, String cypherType ) + { + this.type = type; + this.nodeLabelsOrRelType = nodeLabelsOrRelType; + this.property = property; + this.cypherType = cypherType; + } +} 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 231407821aca..7e89f35fb51f 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 @@ -204,6 +204,7 @@ public void shouldEscapeLabelNameContainingColons() throws Throwable @Test public void shouldListCorrectBuiltinProcedures() throws Throwable { + // TODO: Add new schema procedure here (once its name is decided) // When/Then assertThat( call( "dbms.procedures" ), containsInAnyOrder( record( "dbms.listConfig", @@ -502,7 +503,6 @@ public void setup() throws Exception new SpecialBuiltInProcedures( "1.3.37", Edition.enterprise.toString() ).accept( procs ); procs.registerProcedure( BuiltInProcedures.class ); procs.registerProcedure( BuiltInDbmsProcedures.class ); - procs.registerProcedure( BuiltInSchemaProcedures.class ); when( tx.acquireStatement() ).thenReturn( statement ); when( tx.tokenRead() ).thenReturn( tokens );