diff --git a/community/cypher/cypher/src/main/java/org/neo4j/cypher/export/SubGraphExporter.java b/community/cypher/cypher/src/main/java/org/neo4j/cypher/export/SubGraphExporter.java index 63c6adadad2d..f488a08ae790 100644 --- a/community/cypher/cypher/src/main/java/org/neo4j/cypher/export/SubGraphExporter.java +++ b/community/cypher/cypher/src/main/java/org/neo4j/cypher/export/SubGraphExporter.java @@ -90,12 +90,13 @@ private Collection exportIndexes() { throw new IllegalStateException( "Indexes should have at least one property key" ); } - String key = quote( propertyKeys.next() ); + String id = propertyKeys.next(); if ( propertyKeys.hasNext() ) { throw new RuntimeException( "Exporting compound indexes is not implemented yet" ); } + String key = quote( id ); String label = quote( index.getLabel().name() ); result.add( "create index on :" + label + "(" + key + ")" ); } @@ -106,8 +107,21 @@ private Collection exportIndexes() private Collection exportConstraints() { - final List result = new ArrayList<>(); - for ( ConstraintDefinition constraint : graph.getConstraints() ) + Iterable constraints = graph.getConstraints(); + int count = 0; + if ( constraints instanceof Collection ) + { + count = ((Collection) constraints).size(); + } + else + { + for ( ConstraintDefinition ignored : constraints ) + { + count++; + } + } + final List result = new ArrayList<>( count ); + for ( ConstraintDefinition constraint : constraints ) { if ( !constraint.isConstraintType( ConstraintType.UNIQUENESS ) ) { @@ -119,12 +133,13 @@ private Collection exportConstraints() { throw new IllegalStateException( "Constraints should have at least one property key" ); } - String key = quote( propertyKeys.next() ); + String id = propertyKeys.next(); if ( propertyKeys.hasNext() ) { throw new RuntimeException( "Exporting compound constraints is not implemented yet" ); } + String key = quote( id ); String label = quote( constraint.getLabel().name() ); result.add( "create constraint on (n:" + label + ") assert n." + key + " is unique" ); } @@ -132,7 +147,7 @@ private Collection exportConstraints() return result; } - private String quote( String id ) + private static String quote( String id ) { return "`" + id + "`"; } @@ -149,7 +164,7 @@ private String labelString( Node node ) while ( labels.hasNext() ) { Label next = labels.next(); - result.append( ":" ).append( quote( next.name() ) ); + result.append( ':' ).append( quote( next.name() ) ); } return result.toString(); } @@ -249,7 +264,7 @@ private String formatProperties( PropertyContainer pc ) { result.append( ", " ); } - result.append( quote( prop ) ).append( ":" ); + result.append( quote( prop ) ).append( ':' ); Object value = pc.getProperty( prop ); result.append( toString( value ) ); } @@ -286,7 +301,7 @@ private String arrayToString( Object value ) return "[" + result + "]"; } - private String escapeString( String value ) + private static String escapeString( String value ) { return "\"" + value.replaceAll( "\\\\", "\\\\\\\\" ).replaceAll( "\"", "\\\\\"" ) + "\""; } diff --git a/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/codegen/CompiledConversionUtils.java b/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/codegen/CompiledConversionUtils.java index 1069b4fa4f19..6184856bcaf2 100644 --- a/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/codegen/CompiledConversionUtils.java +++ b/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/codegen/CompiledConversionUtils.java @@ -765,7 +765,8 @@ public Object next() { throw new NoSuchElementException(); } - return Array.get( array, position++ ); + int offset = position++; + return Array.get( array, offset ); } } } diff --git a/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/codegen/ParameterConverter.java b/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/codegen/ParameterConverter.java index 1a721ed2ab55..2a3f8460c6bf 100644 --- a/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/codegen/ParameterConverter.java +++ b/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/codegen/ParameterConverter.java @@ -83,58 +83,57 @@ private void writeValue( Object value ) } @Override - public void writeNodeReference( long nodeId ) throws RuntimeException + public void writeNodeReference( long nodeId ) { writeValue( new NodeIdWrapperImpl( nodeId ) ); } @Override - public void writeNode( long nodeId, TextArray ignore, MapValue properties ) throws RuntimeException + public void writeNode( long nodeId, TextArray ignore, MapValue properties ) { writeValue( new NodeIdWrapperImpl( nodeId ) ); } @Override - public void writeRelationshipReference( long relId ) throws RuntimeException + public void writeRelationshipReference( long relId ) { writeValue( new RelationshipIdWrapperImpl( relId ) ); } @Override public void writeRelationship( long relId, long startNodeId, long endNodeId, TextValue type, MapValue properties ) - throws RuntimeException { writeValue( new RelationshipIdWrapperImpl( relId ) ); } @Override - public void beginMap( int size ) throws RuntimeException + public void beginMap( int size ) { stack.push( new MapWriter( size ) ); } @Override - public void endMap() throws RuntimeException + public void endMap() { assert !stack.isEmpty(); writeValue( stack.pop().value() ); } @Override - public void beginList( int size ) throws RuntimeException + public void beginList( int size ) { stack.push( new ListWriter( size ) ); } @Override - public void endList() throws RuntimeException + public void endList() { assert !stack.isEmpty(); writeValue( stack.pop().value() ); } @Override - public void writePath( NodeValue[] nodes, RelationshipValue[] relationships ) throws RuntimeException + public void writePath( NodeValue[] nodes, RelationshipValue[] relationships ) { assert nodes != null; assert nodes.length > 0; @@ -274,128 +273,128 @@ public void remove() } @Override - public void writeNull() throws RuntimeException + public void writeNull() { writeValue( null ); } @Override - public void writeBoolean( boolean value ) throws RuntimeException + public void writeBoolean( boolean value ) { writeValue( value ); } @Override - public void writeInteger( byte value ) throws RuntimeException + public void writeInteger( byte value ) { writeValue( (long) value ); } @Override - public void writeInteger( short value ) throws RuntimeException + public void writeInteger( short value ) { writeValue( (long) value ); } @Override - public void writeInteger( int value ) throws RuntimeException + public void writeInteger( int value ) { writeValue( (long) value ); } @Override - public void writeInteger( long value ) throws RuntimeException + public void writeInteger( long value ) { writeValue( value ); } @Override - public void writeFloatingPoint( float value ) throws RuntimeException + public void writeFloatingPoint( float value ) { writeValue( (double) value ); } @Override - public void writeFloatingPoint( double value ) throws RuntimeException + public void writeFloatingPoint( double value ) { writeValue( value ); } @Override - public void writeString( String value ) throws RuntimeException + public void writeString( String value ) { writeValue( value ); } @Override - public void writeString( char value ) throws RuntimeException + public void writeString( char value ) { writeValue( value ); } @Override - public void beginArray( int size, ArrayType arrayType ) throws RuntimeException + public void beginArray( int size, ArrayType arrayType ) { stack.push( new ArrayWriter( size, arrayType ) ); } @Override - public void endArray() throws RuntimeException + public void endArray() { assert !stack.isEmpty(); writeValue( stack.pop().value() ); } @Override - public void writeByteArray( byte[] value ) throws RuntimeException + public void writeByteArray( byte[] value ) { writeValue( value ); } @Override - public void writePoint( CoordinateReferenceSystem crs, double[] coordinate ) throws RuntimeException + public void writePoint( CoordinateReferenceSystem crs, double[] coordinate ) { writeValue( Values.pointValue( crs, coordinate ) ); } @Override - public void writeDuration( long months, long days, long seconds, int nanos ) throws RuntimeException + public void writeDuration( long months, long days, long seconds, int nanos ) { writeValue( DurationValue.duration( months, days, seconds, nanos ) ); } @Override - public void writeDate( long epochDay ) throws RuntimeException + public void writeDate( long epochDay ) { writeValue( LocalDate.ofEpochDay( epochDay ) ); } @Override - public void writeLocalTime( long nanoOfDay ) throws RuntimeException + public void writeLocalTime( long nanoOfDay ) { writeValue( LocalTime.ofNanoOfDay( nanoOfDay ) ); } @Override - public void writeTime( long nanosOfDayUTC, int offsetSeconds ) throws RuntimeException + public void writeTime( long nanosOfDayUTC, int offsetSeconds ) { writeValue( OffsetTime.of( LocalTime.ofNanoOfDay( nanosOfDayUTC ), ZoneOffset.ofTotalSeconds( offsetSeconds ) ) ); } @Override - public void writeLocalDateTime( long epochSecond, int nano ) throws RuntimeException + public void writeLocalDateTime( long epochSecond, int nano ) { writeValue( LocalDateTime.ofInstant( Instant.ofEpochSecond(epochSecond, nano), UTC ) ); } @Override - public void writeDateTime( long epochSecondUTC, int nano, int offsetSeconds ) throws RuntimeException + public void writeDateTime( long epochSecondUTC, int nano, int offsetSeconds ) { writeValue( ZonedDateTime.ofInstant( Instant.ofEpochSecond(epochSecondUTC, nano), ZoneOffset.ofTotalSeconds( offsetSeconds ) ) ); } @Override - public void writeDateTime( long epochSecondUTC, int nano, String zoneId ) throws RuntimeException + public void writeDateTime( long epochSecondUTC, int nano, String zoneId ) { writeValue( ZonedDateTime.ofInstant( Instant.ofEpochSecond(epochSecondUTC, nano), ZoneId.of( zoneId ) ) ); } @@ -501,7 +500,8 @@ private static class ArrayWriter implements Writer @Override public void write( Object value ) { - Array.set( array, index++, value ); + Array.set( array, index, value ); + index++; } @Override diff --git a/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/tracing/TimingCompilationTracer.java b/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/tracing/TimingCompilationTracer.java index ea25f77c4ae5..4c3072fe4e47 100644 --- a/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/tracing/TimingCompilationTracer.java +++ b/community/cypher/cypher/src/main/java/org/neo4j/cypher/internal/tracing/TimingCompilationTracer.java @@ -117,27 +117,27 @@ final Clock clock() private static class Query extends Event implements QueryEvent, QueryCompilationEvent { - private final String query; + private final String queryString; private final EventListener listener; private final List phases = new ArrayList<>(); Query( Clock clock, String query, EventListener listener ) { super( clock ); - this.query = query; + this.queryString = query; this.listener = listener; } @Override public String toString() { - return getClass().getSimpleName() + "[" + query + "]"; + return getClass().getSimpleName() + "[" + queryString + "]"; } @Override public CompilationPhaseEvent beginPhase( CompilationPhase phase ) { - Phase event = new Phase( clock(), phase ); + Phase event = new Phase( super.clock(), phase ); phases.add( event ); return event; } @@ -151,7 +151,7 @@ void done() @Override public String query() { - return query; + return queryString; } @Override @@ -163,24 +163,24 @@ public List phases() private static class Phase extends Event implements PhaseEvent, CompilationPhaseTracer.CompilationPhaseEvent { - private final CompilationPhaseTracer.CompilationPhase phase; + private final CompilationPhaseTracer.CompilationPhase compilationPhase; Phase( Clock clock, CompilationPhaseTracer.CompilationPhase phase ) { super( clock ); - this.phase = phase; + this.compilationPhase = phase; } @Override public String toString() { - return getClass().getSimpleName() + "[" + phase + "]"; + return getClass().getSimpleName() + "[" + compilationPhase + "]"; } @Override public CompilationPhaseTracer.CompilationPhase phase() { - return phase; + return compilationPhase; } @Override diff --git a/enterprise/cypher/cypher/src/main/java/org/neo4j/cypher/internal/codegen/DefaultTopTable.java b/enterprise/cypher/cypher/src/main/java/org/neo4j/cypher/internal/codegen/DefaultTopTable.java index 903d6c7dc994..390b405a7d9e 100644 --- a/enterprise/cypher/cypher/src/main/java/org/neo4j/cypher/internal/codegen/DefaultTopTable.java +++ b/enterprise/cypher/cypher/src/main/java/org/neo4j/cypher/internal/codegen/DefaultTopTable.java @@ -124,7 +124,8 @@ public T next() { throw new NoSuchElementException(); } - return (T) array[--cursor]; + --cursor; + return (T) array[cursor]; } }; } diff --git a/enterprise/cypher/cypher/src/main/java/org/neo4j/cypher/internal/v3_4/codegen/profiling/ProfilingTracer.java b/enterprise/cypher/cypher/src/main/java/org/neo4j/cypher/internal/v3_4/codegen/profiling/ProfilingTracer.java index 7c5c93f83fac..a6dfc6e095a7 100644 --- a/enterprise/cypher/cypher/src/main/java/org/neo4j/cypher/internal/v3_4/codegen/profiling/ProfilingTracer.java +++ b/enterprise/cypher/cypher/src/main/java/org/neo4j/cypher/internal/v3_4/codegen/profiling/ProfilingTracer.java @@ -91,12 +91,13 @@ public long rowsOf( Id query ) @Override public QueryExecutionEvent executeOperator( Id queryId ) { - Data data = this.data.get( queryId ); - if ( data == null && queryId != null ) + Data queryData = this.data.get( queryId ); + if ( queryData == null && queryId != null ) { - this.data.put( queryId, data = new Data() ); + queryData = new Data(); + this.data.put( queryId, queryData ); } - return new ExecutionEvent( clock, statisticProvider, data ); + return new ExecutionEvent( clock, statisticProvider, queryData ); } private static class ExecutionEvent implements QueryExecutionEvent diff --git a/enterprise/cypher/cypher/src/test/java/org/neo4j/cypher/internal/codegen/SetStaticFieldTest.java b/enterprise/cypher/cypher/src/test/java/org/neo4j/cypher/internal/codegen/SetStaticFieldTest.java index 2873984eadce..622002de79ff 100644 --- a/enterprise/cypher/cypher/src/test/java/org/neo4j/cypher/internal/codegen/SetStaticFieldTest.java +++ b/enterprise/cypher/cypher/src/test/java/org/neo4j/cypher/internal/codegen/SetStaticFieldTest.java @@ -34,7 +34,7 @@ public void shouldAssignFields() setStaticField.apply( Apa.class, "X", "HELLO WORLD!" ); // then - assertEquals( Apa.X, "HELLO WORLD!" ); + assertEquals( "HELLO WORLD!", Apa.X ); } public static class Apa diff --git a/enterprise/cypher/slotted-runtime/src/main/java/org/neo4j/cypher/internal/compatibility/v3_4/runtime/slotted/DefaultComparatorTopTable.java b/enterprise/cypher/slotted-runtime/src/main/java/org/neo4j/cypher/internal/compatibility/v3_4/runtime/slotted/DefaultComparatorTopTable.java index b0744d270fed..9735292c823c 100644 --- a/enterprise/cypher/slotted-runtime/src/main/java/org/neo4j/cypher/internal/compatibility/v3_4/runtime/slotted/DefaultComparatorTopTable.java +++ b/enterprise/cypher/slotted-runtime/src/main/java/org/neo4j/cypher/internal/compatibility/v3_4/runtime/slotted/DefaultComparatorTopTable.java @@ -126,7 +126,9 @@ public T next() { throw new NoSuchElementException(); } - return (T) array[--cursor]; + + int offset = --cursor; + return (T) array[offset]; } }; }