Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.3' into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mats-SX committed Nov 20, 2015
2 parents ce03d77 + 30e8b1a commit d528248
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,26 @@
*/
package org.neo4j.cypher.internal.compiler.v3_0.planner.execution

import org.mockito.Mockito.{verify, when, atLeastOnce}
import org.neo4j.cypher.internal.compiler.v3_0.ast.convert.commands.ExpressionConverters._
import org.neo4j.cypher.internal.frontend.v3_0.SemanticDirection
import org.neo4j.cypher.internal.frontend.v3_0.ast.{Collection, Expression, SignedDecimalIntegerLiteral}
import org.neo4j.cypher.internal.compiler.v3_0.commands.expressions.Literal
import org.neo4j.cypher.internal.compiler.v3_0.commands.predicates.True
import org.neo4j.cypher.internal.compiler.v3_0.commands.values.KeyToken.Resolved
import org.neo4j.cypher.internal.compiler.v3_0.commands.values.TokenType
import org.neo4j.cypher.internal.compiler.v3_0.commands.{expressions => legacy}
import org.neo4j.cypher.internal.compiler.v3_0.executionplan.PipeInfo
import org.neo4j.cypher.internal.compiler.v3_0.pipes._
import org.neo4j.cypher.internal.compiler.v3_0.planner._
import org.neo4j.cypher.internal.compiler.v3_0.planner.logical.plans._
import org.neo4j.cypher.internal.compiler.v3_0.spi.PlanContext
import org.neo4j.cypher.internal.frontend.v3_0.SemanticDirection
import org.neo4j.cypher.internal.frontend.v3_0.ast._
import org.neo4j.cypher.internal.frontend.v3_0.test_helpers.CypherFunSuite
import org.neo4j.helpers.Clock

class PipeExecutionPlanBuilderAcceptanceTest extends CypherFunSuite with LogicalPlanningTestSupport {

implicit val planContext = newMockedPlanContext
implicit val planContext: PlanContext = newMockedPlanContext
implicit val pipeMonitor = mock[PipeMonitor]
implicit val LogicalPlanningContext = newMockedLogicalPlanningContext(planContext)
implicit val pipeBuildContext = newMockedPipeExecutionPlanBuilderContext
Expand Down Expand Up @@ -185,4 +189,25 @@ class PipeExecutionPlanBuilderAcceptanceTest extends CypherFunSuite with Logical
ExpandAllPipe( AllNodesScanPipe("c")(), "c", "r2", "b", SemanticDirection.INCOMING, LazyTypes.empty)()
)())
}

test("Aggregation on top of Projection => DistinctPipe with resolved expressions") {
// GIVEN
val token = 42
when(planContext.getOptPropertyKeyId("prop")).thenReturn(Some(token))
val allNodesScan = AllNodesScan("n", Set.empty)(solved)
val expressions = Map("n.prop" -> Property(Variable("n")(pos), PropertyKeyName("prop")(pos))(pos))
val projection = Projection(allNodesScan, expressions)(solved)
val aggregation = Aggregation(projection, expressions, Map.empty) _

// WHEN
val pipe = build(aggregation).pipe

// THEN
verify(planContext, atLeastOnce()).getOptPropertyKeyId("prop")
pipe should equal(
DistinctPipe(
AllNodesScanPipe("n")(),
Map("n.prop" -> legacy.Property(legacy.Variable("n"),
Resolved("prop", token, TokenType.PropertyKey))))())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,18 @@ class ProfilerAcceptanceTest extends ExecutionEngineFunSuite with CreateTempFile
assertRows(1)(result)("NodeByLabelScan")
}

test("distinct should not look up properties every time") {
// GIVEN
createNode("prop"-> 42)
createNode("prop"-> 42)

// WHEN
val result = profileWithAllPlanners("MATCH (n) RETURN DISTINCT n.prop")

// THEN
assertDbHits(2)(result)("Distinct")
}

private def assertRows(expectedRows: Int)(result: InternalExecutionResult)(names: String*) {
getPlanDescriptions(result, names).foreach {
plan => assert(expectedRows === getArgument[Rows](plan).value, s" wrong row count for plan: ${plan.name}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.neo4j.cluster.member.ClusterMemberAvailability;
import org.neo4j.cluster.member.ClusterMemberEvents;
import org.neo4j.cluster.member.ClusterMemberListener;
import org.neo4j.com.ServerUtil;
import org.neo4j.com.monitor.RequestMonitor;
import org.neo4j.com.storecopy.StoreCopyServer;
import org.neo4j.function.Supplier;
Expand Down Expand Up @@ -244,7 +245,7 @@ private ClusterMemberAvailability getClusterMemberAvailability() {
}

private URI createBackupURI() {
String hostString = server.getSocketAddress().getHostString();
String hostString = ServerUtil.getHostString( server.getSocketAddress() );
String host = hostString.contains( INADDR_ANY ) ? me.getHost() : hostString;
int port = server.getSocketAddress().getPort();
return URI.create("backup://" + host + ":" + port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,19 @@ public void receive( Message message )

private URI getURI( InetSocketAddress address )
{
// Socket.toString() already prepends a '/'
String uri = CLUSTER_SCHEME + "://" + address.getHostString() + ":" + address.getPort();
String uri;

// Add name if given
if ( config.name() != null )
if ( address.getAddress().getHostAddress().startsWith( "0" ) )
uri = CLUSTER_SCHEME + "://0.0.0.0:" + address.getPort(); // Socket.toString() already prepends a /
else
{
uri += "/?name=" + config.name();
uri = CLUSTER_SCHEME + "://" + address.getAddress().getHostName() + ":" + address.getPort(); // Socket
}
// .toString() already prepends a /

// Add name if given
if (config.name() != null)
uri += "/?name="+config.name();

return URI.create( uri );
}
Expand Down
46 changes: 46 additions & 0 deletions enterprise/com/src/main/java/org/neo4j/com/ServerUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2002-2015 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.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 Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.com;

import java.net.InetSocketAddress;

public class ServerUtil
{

/**
* Figure out the host string of a given socket address, similar to the Java 7 InetSocketAddress.getHostString().
*
* Calls to this should be replace once Neo4j is Java 7 only.
*
* @param socketAddress
* @return
*/
public static String getHostString( InetSocketAddress socketAddress )
{
if ( socketAddress.isUnresolved() )
{
return socketAddress.getHostName();
}
else
{
return socketAddress.getAddress().getHostAddress();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.neo4j.cluster.ClusterSettings;
import org.neo4j.cluster.InstanceId;
import org.neo4j.cluster.member.ClusterMemberAvailability;
import org.neo4j.com.ServerUtil;
import org.neo4j.function.BiFunction;
import org.neo4j.function.Factory;
import org.neo4j.function.Supplier;
Expand Down Expand Up @@ -122,9 +123,9 @@ public URI switchToMaster( LifeSupport haCommunicationLife, URI me )

private URI getMasterUri( URI me, MasterServer masterServer )
{
String hostname = config.get( HaSettings.ha_server ).getHost(
masterServer.getSocketAddress().getHostString().contains( "0.0.0.0" ) ? me.getHost()
: masterServer.getSocketAddress().getHostString() );
String hostname = config.get( HaSettings.ha_server ).getHost( ServerUtil.getHostString( masterServer.getSocketAddress() ).contains( "0.0.0.0" ) ?
me.getHost() :
ServerUtil.getHostString( masterServer.getSocketAddress() ));

int port = masterServer.getSocketAddress().getPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.neo4j.com.RequestContext;
import org.neo4j.com.Response;
import org.neo4j.com.Server;
import org.neo4j.com.ServerUtil;
import org.neo4j.com.storecopy.StoreCopyClient;
import org.neo4j.com.storecopy.StoreWriter;
import org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker;
Expand Down Expand Up @@ -506,7 +507,7 @@ private boolean catchUpWithMaster( UpdatePuller updatePuller ) throws IllegalArg

private URI createHaURI( URI me, Server<?,?> server )
{
String hostString = server.getSocketAddress().getHostString();
String hostString = ServerUtil.getHostString( server.getSocketAddress() );
int port = server.getSocketAddress().getPort();
InstanceId serverId = config.get( ClusterSettings.server_id );
String host = hostString.contains( HighAvailabilityModeSwitcher.INADDR_ANY ) ? me.getHost() : hostString;
Expand Down

0 comments on commit d528248

Please sign in to comment.