Skip to content

Commit

Permalink
sort query results
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglei1949 committed Sep 24, 2023
1 parent d4945b3 commit f85d87b
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 56 deletions.
3 changes: 2 additions & 1 deletion flex/tests/hqps/queries/movie/query11.cypher
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
MATCH (tom:Person {name: 'Tom Hanks'})-[r:ACTED_IN]->(movie:Movie)
RETURN tom.id AS personId, movie.title as movieTitle, movie.released as movieReleased;
WITH movie.title as movieTitle, movie.released as movieReleased
return movieTitle, movieReleased ORDER BY movieReleased DESC, movieTitle ASC LIMIT 10
2 changes: 1 addition & 1 deletion flex/tests/hqps/queries/movie/query12.cypher
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MATCH (tom:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(coActor:Person)
RETURN coActor.name;
WITH DISTINCT coActor.name AS coActorName ORDER By coActorName ASC LIMIT 10 return coActorName;
2 changes: 1 addition & 1 deletion flex/tests/hqps/queries/movie/query13.cypher
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MATCH (tom:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(movie1:Movie)<-[:ACTED_IN]-(coActor:Person)-[:ACTED_IN]->(movie2:Movie)<-[:ACTED_IN]-(coCoActor:Person)
WHERE tom <> coCoActor
AND NOT (tom)-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(coCoActor)
RETURN coCoActor.name
RETURN coCoActor.name ORDER BY coCoActor.name ASC LIMIT 10;
3 changes: 2 additions & 1 deletion flex/tests/hqps/queries/movie/query15.cypher
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
MATCH (tom:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(movie1:Movie)<-[:ACTED_IN]-(coActor:Person)-[:ACTED_IN]->(movie2:Movie)<-[:ACTED_IN]-(cruise:Person {name: 'Tom Cruise'})
WHERE NOT (tom)-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(cruise)
RETURN tom.name AS actorName, movie1.title AS actedInMovie, coActor.name AS coActorName, movie2.title AS coActorActivedInMovie, cruise.name AS coCoActorName;
RETURN tom.name AS actorName, movie1.title AS movie1Title, coActor.name AS coActorName, movie2.title AS movie2Title, cruise.name AS coCoActorName
ORDER BY movie1Title, movie2Title LIMIT 10;
2 changes: 1 addition & 1 deletion flex/tests/hqps/queries/movie/query3.cypher
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MATCH (people:Person) RETURN people.name LIMIT 10;
MATCH (people:Person) RETURN people.name ORDER BY people.name ASC LIMIT 10;
3 changes: 2 additions & 1 deletion flex/tests/hqps/queries/movie/query4.cypher
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
MATCH (nineties:Movie) WHERE nineties.released >= 1990 AND nineties.released < 2000 RETURN nineties.title;
MATCH (nineties:Movie) WHERE nineties.released >= 1990 AND nineties.released < 2000 RETURN nineties.title
ORDER BY nineties.title DESC LIMIT 10;
3 changes: 2 additions & 1 deletion flex/tests/hqps/queries/movie/query5.cypher
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
MATCH (tom:Person {name: "Tom Hanks"})-[:ACTED_IN]->(tomHanksMovies)
RETURN tom.born AS bornYear,tomHanksMovies.tagline AS movieTagline, tomHanksMovies.title AS movieTitle, tomHanksMovies.released AS releaseYear;
RETURN tom.born AS bornYear,tomHanksMovies.tagline AS movieTagline, tomHanksMovies.title AS movieTitle, tomHanksMovies.released AS releaseYear
ORDER BY releaseYear DESC, movieTitle ASC LIMIT 10;
2 changes: 1 addition & 1 deletion flex/tests/hqps/queries/movie/query6.cypher
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MATCH (cloudAtlas:Movie {title: "Cloud Atlas"})<-[:DIRECTED]-(directors)
RETURN directors.name;
RETURN directors.name ORDER BY directors.name ASC LIMIT 10;
3 changes: 2 additions & 1 deletion flex/tests/hqps/queries/movie/query7.cypher
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors)
RETURN m.title AS movieTitle, m.released AS releasedYear, coActors.name AS coActor
RETURN m.title AS movieTitle, m.released AS releasedYear, coActors.name AS coActor
ORDER BY m.released DESC, movieTitle ASC LIMIT 10;
Original file line number Diff line number Diff line change
Expand Up @@ -28,61 +28,54 @@ public static QueryContext get_movie_query3_test() {
String query = "MATCH (people:Person) RETURN people.name LIMIT 10;";
List<String> expected =
Arrays.asList(
"Record<{people.name: \"Keanu Reeves\"}>",
"Record<{people.name: \"Carrie-Anne Moss\"}>",
"Record<{people.name: \"Laurence Fishburne\"}>",
"Record<{people.name: \"Hugo Weaving\"}>",
"Record<{people.name: \"Lilly Wachowski\"}>",
"Record<{people.name: \"Lana Wachowski\"}>",
"Record<{people.name: \"Joel Silver\"}>",
"Record<{people.name: \"Emil Eifrem\"}>",
"Record<{people.name: \"Charlize Theron\"}>",
"Record<{people.name: \"Al Pacino\"}>");
"Record<{people.name: \"Aaron Sorkin\"}>",
"Record<{people.name: \"Al Pacino\"}>",
"Record<{people.name: \"Angela Scope\"}>",
"Record<{people.name: \"Annabella Sciorra\"}>",
"Record<{people.name: \"Anthony Edwards\"}>",
"Record<{people.name: \"Audrey Tautou\"}>",
"Record<{people.name: \"Ben Miles\"}>",
"Record<{people.name: \"Bill Paxton\"}>",
"Record<{people.name: \"Bill Pullman\"}>",
"Record<{people.name: \"Billy Crystal\"}>");
return new QueryContext(query, expected);
}

public static QueryContext get_movie_query4_test() {
String query =
"MATCH (nineties:Movie) WHERE nineties.released >= 1990 AND nineties.released <"
+ " 2000 RETURN nineties.title LIMIT 10;";
"MATCH (nineties:Movie) WHERE nineties.released >= 1990 AND nineties.released < 2000 RETURN nineties.title\n"
+ "ORDER BY nineties.title DESC LIMIT 10;";
List<String> expected =
Arrays.asList(
"Record<{nineties.title: \"The Matrix\"}>",
"Record<{nineties.title: \"The Devil's Advocate\"}>",
"Record<{nineties.title: \"A Few Good Men\"}>",
"Record<{nineties.title: \"As Good as It Gets\"}>",
"Record<{nineties.title: \"What Dreams May Come\"}>",
"Record<{nineties.title: \"Snow Falling on Cedars\"}>",
"Record<{nineties.title: \"You've Got Mail\"}>",
"Record<{nineties.title: \"Sleepless in Seattle\"}>",
"Record<{nineties.title: \"Joe Versus the Volcano\"}>",
"Record<{nineties.title: \"When Harry Met Sally\"}>");
Arrays.asList();
return new QueryContext(query, expected);
}

public static QueryContext get_movie_query5_test() {
String query =
"MATCH (tom:Person {name: \"Tom Hanks\"})-[:ACTED_IN]->(tomHanksMovies)\n"
+ "RETURN tom.born AS bornYear, tomHanksMovies.tagline AS movieTagline,"
+ " tomHanksMovies.title AS movieTitle, tomHanksMovies.released AS"
+ " releaseYear;";
+ "RETURN tom.born AS bornYear,tomHanksMovies.tagline AS movieTagline, tomHanksMovies.title AS movieTitle, tomHanksMovies.released AS releaseYear\n"
+ "ORDER BY releaseYear DESC, movieTitle ASC LIMIT 10;";
List<String> expected = Arrays.asList();
return new QueryContext(query, expected);
}

public static QueryContext get_movie_query6_test() {
String query =
"MATCH (cloudAtlas:Movie {title: \"Cloud Atlas\"})<-[:DIRECTED]-(directors)\n"
+ "RETURN directors.name;";
List<String> expected = Arrays.asList();
+ "RETURN directors.name ORDER BY directors.name ASC LIMIT 10;";
List<String> expected = Arrays.asList(
"Record<{directors.name: \"Lana Wachowski\"}>",
"Record<{directors.name: \"Lilly Wachowski\"}>",
"Record<{directors.name: \"Tom Tykwer\"}>"
);
return new QueryContext(query, expected);
}

public static QueryContext get_movie_query7_test() {
String query =
"MATCH (tom:Person {name:\"Tom Hanks\"})-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors)\n"
+ "RETURN m.title AS movieTitle, m.released AS releasedYear, coActors.name AS"
+ " coActor";
+ "RETURN m.title AS movieTitle, m.released AS releasedYear, coActors.name AS coActor\n"
+ "ORDER BY m.released DESC, movieTitle ASC LIMIT 10;";
List<String> expected = Arrays.asList();
return new QueryContext(query, expected);
}
Expand Down Expand Up @@ -117,29 +110,49 @@ public static QueryContext get_movie_query10_test() {
public static QueryContext get_movie_query11_test() {
String query =
"MATCH (tom:Person {name: 'Tom Hanks'})-[r:ACTED_IN]->(movie:Movie)\n"
+ "RETURN tom.id AS personId, movie.title as movieTitle, movie.released as"
+ " movieReleased;";
+ "WITH movie.title as movieTitle, movie.released as movieReleased\n"
+ "return movieTitle, movieReleased ORDER BY movieReleased DESC, movieTitle ASC LIMIT 10";
List<String> expected = Arrays.asList();
return new QueryContext(query, expected);
}

public static QueryContext get_movie_query12_test() {
String query =
"MATCH (tom:Person {name: 'Tom"
+ " Hanks'})-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(coActor:Person)\n"
+ "RETURN coActor.name;";
List<String> expected = Arrays.asList();
"MATCH (tom:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(coActor:Person)\n"
+ "WITH DISTINCT coActor.name AS coActorName ORDER By coActorName ASC LIMIT 10 return coActorName;";
List<String> expected = Arrays.asList(
"Record<{name: \"Audrey Tautou\"}>",
"Record<{name: \"Bill Paxton\"}>",
"Record<{name: \"Bill Pullman\"}>",
"Record<{name: \"Bonnie Hunt\"}>",
"Record<{name: \"Charlize Theron\"}>",
"Record<{name: \"Dave Chappelle\"}>",
"Record<{name: \"David Morse\"}>",
"Record<{name: \"Ed Harris\"}>",
"Record<{name: \"Gary Sinise\"}>",
"Record<{name: \"Geena Davis\"}>"
);
return new QueryContext(query, expected);
}

public static QueryContext get_movie_query13_test() {
String query =
"MATCH (tom:Person {name: 'Tom"
+ " Hanks'})-[:ACTED_IN]->(movie1:Movie)<-[:ACTED_IN]-(coActor:Person)-[:ACTED_IN]->(movie2:Movie)<-[:ACTED_IN]-(coCoActor:Person)\n"
"MATCH (tom:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(movie1:Movie)<-[:ACTED_IN]-(coActor:Person)-[:ACTED_IN]->(movie2:Movie)<-[:ACTED_IN]-(coCoActor:Person)\n"
+ "WHERE tom <> coCoActor\n"
+ "AND NOT (tom)-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(coCoActor)\n"
+ "RETURN coCoActor.name";
List<String> expected = Arrays.asList();
+ "RETURN coCoActor.name ORDER BY coCoActor.name ASC LIMIT 10;";
List<String> expected = Arrays.asList(
"Record<{coCoActor.name: \"Aaron Sorkin\"}>",
"Record<{coCoActor.name: \"Al Pacino\"}>",
"Record<{coCoActor.name: \"Anthony Edwards\"}>",
"Record<{coCoActor.name: \"Anthony Edwards\"}>",
"Record<{coCoActor.name: \"Anthony Edwards\"}>",
"Record<{coCoActor.name: \"Ben Miles\"}>",
"Record<{coCoActor.name: \"Billy Crystal\"}>",
"Record<{coCoActor.name: \"Billy Crystal\"}>",
"Record<{coCoActor.name: \"Billy Crystal\"}>",
"Record<{coCoActor.name: \"Bruno Kirby\"}>"
);
return new QueryContext(query, expected);
}

Expand All @@ -152,19 +165,22 @@ public static QueryContext get_movie_query14_test() {
+ "RETURN coCoActor.name, count(coCoActor) as frequency\n"
+ "ORDER BY frequency DESC\n"
+ "LIMIT 5;";
List<String> expected = Arrays.asList();
List<String> expected = Arrays.asList(
"Record<{coCoActor.name: \"Tom Cruise\", frequency: 5}>",
"Record<{coCoActor.name: \"Zach Grenier\", frequency: 5}>",
"Record<{coCoActor.name: \"Cuba Gooding Jr.\", frequency: 4}>",
"Record<{coCoActor.name: \"Keanu Reeves\", frequency: 4}>",
"Record<{coCoActor.name: \"Jack Nicholson\", frequency: 3}>"
);
return new QueryContext(query, expected);
}

public static QueryContext get_movie_query15_test() {
String query =
"MATCH (tom:Person {name: 'Tom"
+ " Hanks'})-[:ACTED_IN]->(movie1:Movie)<-[:ACTED_IN]-(coActor:Person)-[:ACTED_IN]->(movie2:Movie)<-[:ACTED_IN]-(cruise:Person"
+ " {name: 'Tom Cruise'})\n"
"MATCH (tom:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(movie1:Movie)<-[:ACTED_IN]-(coActor:Person)-[:ACTED_IN]->(movie2:Movie)<-[:ACTED_IN]-(cruise:Person {name: 'Tom Cruise'})\n"
+ "WHERE NOT (tom)-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(cruise)\n"
+ "RETURN tom.name AS actorName, movie1.title AS actedInMovie, coActor.name AS"
+ " coActorName, movie2.title AS coActorActivedInMovie, cruise.name AS"
+ " coCoActorName;";
+ "RETURN tom.name AS actorName, movie1.title AS movie1Title, coActor.name AS coActorName, movie2.title AS movie2Title, cruise.name AS coCoActorName\n"
+ "ORDER BY movie1Title, movie2Title LIMIT 10;";
List<String> expected = Arrays.asList();
return new QueryContext(query, expected);
}
Expand Down

0 comments on commit f85d87b

Please sign in to comment.