Skip to content

Commit

Permalink
Merge pull request #5925 from pontusmelke/2.2-gh-5902
Browse files Browse the repository at this point in the history
Correct status code when using hint with no index
  • Loading branch information
craigtaverner committed Nov 27, 2015
2 parents 293a88d + 9ab18a7 commit 598b1c1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ class UnknownLabelException(labelName: String) extends CypherException(s"The pro

class HintException( message: String)
extends CypherException(message) {
val status = Status.Schema.NoSuchIndex
val status = Status.Statement.ExecutionFailure
}

class IndexHintException(identifier: String, label: String, property: String, message: String)
extends CypherException(s"$message\nLabel: `$label`\nProperty name: `$property`") {
val status = Status.Statement.ExecutionFailure
val status = Status.Schema.NoSuchIndex
}

class LabelScanHintException(identifier: String, label: String, message: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.neo4j.cypher

import org.neo4j.kernel.api.exceptions.Status

class UsingAcceptanceTest extends ExecutionEngineFunSuite with NewPlannerTestSupport {

Expand Down Expand Up @@ -221,4 +222,39 @@ class UsingAcceptanceTest extends ExecutionEngineFunSuite with NewPlannerTestSup
result.toList should be(empty)
}

test("when failing to support all hints we should provide an understandable error message") {
// GIVEN
graph.createIndex("LocTag", "id")

// WHEN
val query = """MATCH (t1:LocTag {id:1642})-[:Child*0..]->(:LocTag)
| <-[:Tagged]-(s1:Startup)<-[r1:Role]-(u:User)
| -[r2:Role]->(s2:Startup)-[:Tagged]->(:LocTag)
| <-[:Child*0..]-(t2:LocTag {id:1642})
|USING INDEX t1:LocTag(id)
|USING INDEX t2:LocTag(id)
|RETURN count(u)""".stripMargin


val error = intercept[HintException](executeWithAllPlanners(query))

error.getMessage should equal("The current planner cannot satisfy all hints in the query, please try removing hints or try with another planner")
error.status should equal(Status.Statement.ExecutionFailure)
}

test("correct status code when no index") {

// GIVEN
val query = """MATCH (n:Test)
|USING INDEX n:Test(foo)
|WHERE n.foo = {foo}
|RETURN n""".stripMargin

// WHEN
val error = intercept[IndexHintException](executeWithAllPlanners(query))

// THEN
error.status should equal(Status.Schema.NoSuchIndex)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
package org.neo4j.server.rest.transactional.integration;

import org.codehaus.jackson.JsonNode;
import org.junit.Test;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
Expand All @@ -31,9 +34,6 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.codehaus.jackson.JsonNode;
import org.junit.Test;

import org.neo4j.graphdb.DynamicLabel;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
Expand All @@ -54,7 +54,6 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import static org.neo4j.helpers.collection.IteratorUtil.asSet;
import static org.neo4j.server.rest.domain.JsonHelper.jsonNode;
import static org.neo4j.server.rest.transactional.integration.TransactionMatchers.containsNoErrors;
Expand Down Expand Up @@ -823,7 +822,7 @@ public void restFormattedNodesShouldHaveSensibleUrisWhenUsingXForwardHeader() th
// given
final String hostname = "dummy.example.org";
final String scheme = "http";

// when
Response rs = http.withHeaders( XForwardUtil.X_FORWARD_HOST_HEADER_KEY, hostname )
.POST( "/db/data/transaction/commit", quotedJson(
Expand Down Expand Up @@ -853,6 +852,15 @@ public void restFormattedNodesShouldHaveSensibleUrisWhenUsingXForwardHeader() th
"/node/\\d+/relationships/in/\\{-list\\|&\\|types\\}", hostname, scheme );
}

@Test
public void correctStatusCodeWhenUsingHintWithoutAnyIndex() throws Exception
{
// begin and execute and commit
Response begin = http.POST( "/db/data/transaction/commit", quotedJson( "{ 'statements': [ { 'statement': " +
"'MATCH (n:Test) USING INDEX n:Test(foo) WHERE n.foo = 42 RETURN n.foo' } ] }" ) );
assertThat( begin, hasErrors( Status.Request.Schema.NoSuchIndex ) );
}

private void assertPath( JsonNode jsonURIString, String path, String hostname, final String scheme )
{
assertTrue( "Expected a uri matching '" + scheme + "://" + hostname + ":\\d+/db/data" + path + "', " +
Expand Down

0 comments on commit 598b1c1

Please sign in to comment.