Skip to content

Commit

Permalink
Second part of feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
SaschaPeukert committed Jul 26, 2018
1 parent a924bbd commit e897df4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 39 deletions.
Expand Up @@ -41,8 +41,7 @@
import org.neo4j.internal.kernel.api.RelationshipScanCursor; import org.neo4j.internal.kernel.api.RelationshipScanCursor;
import org.neo4j.internal.kernel.api.SchemaRead; import org.neo4j.internal.kernel.api.SchemaRead;
import org.neo4j.internal.kernel.api.TokenRead; import org.neo4j.internal.kernel.api.TokenRead;
import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.internal.kernel.api.Transaction;
import org.neo4j.kernel.api.Statement;
import org.neo4j.values.storable.Value; import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.ValueGroup; import org.neo4j.values.storable.ValueGroup;


Expand All @@ -52,7 +51,7 @@


public class SchemaCalculator public class SchemaCalculator
{ {
private KernelTransaction ktx; private org.neo4j.internal.kernel.api.Transaction ktx;


private Map<LabelSet,Set<Integer>> labelSetToPropertyKeysMapping; private Map<LabelSet,Set<Integer>> labelSetToPropertyKeysMapping;
private Map<Pair<LabelSet,Integer>,ValueTypeDecider> labelSetANDNodePropertyKeyIdToValueTypeMapping; private Map<Pair<LabelSet,Integer>,ValueTypeDecider> labelSetANDNodePropertyKeyIdToValueTypeMapping;
Expand All @@ -69,7 +68,7 @@ public class SchemaCalculator
private final String NODE = "Node"; private final String NODE = "Node";
private final String RELATIONSHIP = "Relationship"; private final String RELATIONSHIP = "Relationship";


SchemaCalculator( KernelTransaction ktx ) SchemaCalculator( Transaction ktx )
{ {
this.ktx = ktx; this.ktx = ktx;
} }
Expand Down Expand Up @@ -159,35 +158,32 @@ public Stream<SchemaProcedure.GraphResult> calculateGraphResultStream()
private void calculateSchema() private void calculateSchema()
{ {
// this one does most of the work // this one does most of the work
try ( Statement ignore = ktx.acquireStatement() ) Read dataRead = ktx.dataRead();
{ TokenRead tokenRead = ktx.tokenRead();
Read dataRead = ktx.dataRead(); SchemaRead schemaRead = ktx.schemaRead();
TokenRead tokenRead = ktx.tokenRead(); CursorFactory cursors = ktx.cursors();
SchemaRead schemaRead = ktx.schemaRead();
CursorFactory cursors = ktx.cursors(); // setup mappings

int labelCount = tokenRead.labelCount();
// setup mappings int relationshipTypeCount = tokenRead.relationshipTypeCount();
int labelCount = tokenRead.labelCount(); labelSetToPropertyKeysMapping = new HashMap<>( labelCount );
int relationshipTypeCount = tokenRead.relationshipTypeCount(); labelIdToLabelNameMapping = new HashMap<>( labelCount );
labelSetToPropertyKeysMapping = new HashMap<>( labelCount ); propertyIdToPropertylNameMapping = new HashMap<>( tokenRead.propertyKeyCount() );
labelIdToLabelNameMapping = new HashMap<>( labelCount ); relationshipTypIdToRelationshipNameMapping = new HashMap<>( relationshipTypeCount );
propertyIdToPropertylNameMapping = new HashMap<>( tokenRead.propertyKeyCount() ); relationshipTypeIdToPropertyKeysMapping = new HashMap<>( relationshipTypeCount );
relationshipTypIdToRelationshipNameMapping = new HashMap<>( relationshipTypeCount ); labelSetANDNodePropertyKeyIdToValueTypeMapping = new HashMap<>();
relationshipTypeIdToPropertyKeysMapping = new HashMap<>( relationshipTypeCount ); relationshipTypeIdANDPropertyTypeIdToValueTypeMapping = new HashMap<>();
labelSetANDNodePropertyKeyIdToValueTypeMapping = new HashMap<>();
relationshipTypeIdANDPropertyTypeIdToValueTypeMapping = new HashMap<>(); scanEverythingBelongingToNodes( dataRead, cursors );

scanEverythingBelongingToRelationships( dataRead, cursors );
scanEverythingBelongingToNodes( dataRead, cursors );
scanEverythingBelongingToRelationships( dataRead, cursors ); // OTHER:

// go through all labels
// OTHER: addNamesToCollection( tokenRead.labelsGetAllTokens(), labelIdToLabelNameMapping );
// go through all labels // go through all propertyKeys
addNamesToCollection( tokenRead.labelsGetAllTokens(), labelIdToLabelNameMapping ); addNamesToCollection( tokenRead.propertyKeyGetAllTokens(), propertyIdToPropertylNameMapping );
// go through all propertyKeys // go through all relationshipTypes
addNamesToCollection( tokenRead.propertyKeyGetAllTokens(), propertyIdToPropertylNameMapping ); addNamesToCollection( tokenRead.relationshipTypesGetAllTokens(), relationshipTypIdToRelationshipNameMapping );
// go through all relationshipTypes
addNamesToCollection( tokenRead.relationshipTypesGetAllTokens(), relationshipTypIdToRelationshipNameMapping );
}
} }


private void scanEverythingBelongingToRelationships( Read dataRead, CursorFactory cursors ) private void scanEverythingBelongingToRelationships( Read dataRead, CursorFactory cursors )
Expand Down Expand Up @@ -303,7 +299,6 @@ private class ValueTypeDecider
private ValueGroup valueGroup; private ValueGroup valueGroup;
private ValueStatus valueStatus; private ValueStatus valueStatus;
private Boolean isNullable = false; private Boolean isNullable = false;
private String nullableSuffix = "";


ValueTypeDecider( Value v ) ValueTypeDecider( Value v )
{ {
Expand All @@ -319,7 +314,6 @@ private class ValueTypeDecider
private void setNullable( ) private void setNullable( )
{ {
isNullable = true; isNullable = true;
nullableSuffix = NULLABLE;
} }


/* /*
Expand All @@ -330,10 +324,10 @@ String getCypherTypeString()
switch ( valueStatus ) switch ( valueStatus )
{ {
case VALUE: case VALUE:
return isNullable ? concreteValue.getTypeName().toUpperCase() + nullableSuffix return isNullable ? concreteValue.getTypeName().toUpperCase() + NULLABLE
: concreteValue.getTypeName().toUpperCase(); : concreteValue.getTypeName().toUpperCase();
case VALUE_GROUP: case VALUE_GROUP:
return isNullable ? valueGroup.name() + nullableSuffix return isNullable ? valueGroup.name() + NULLABLE
: valueGroup.name(); : valueGroup.name();
case ANY: case ANY:
return isNullable ? NULLABLE_ANYVALUE return isNullable ? NULLABLE_ANYVALUE
Expand Down
Expand Up @@ -32,11 +32,11 @@ public class SchemaInfoResult
*/ */
public final List<String> nodeLabelsOrRelType; public final List<String> nodeLabelsOrRelType;
/** /**
* A property that occurs on the given label combination / relationship type * A property that occurs on the given label combination / relationship type or null
*/ */
public final String property; public final String property;
/** /**
* The CypherType of the given property on the given label combination / relationship type * The CypherType of the given property on the given label combination / relationship type or null
*/ */
public final String cypherType; public final String cypherType;


Expand Down

0 comments on commit e897df4

Please sign in to comment.