From fcd37de8c12eaa77f32502773e759b14637e9952 Mon Sep 17 00:00:00 2001 From: shirly121 Date: Fri, 8 Sep 2023 18:00:37 +0800 Subject: [PATCH] parent 6ab796e5721e5c58f9c0665c609eabf22b84821a author shirly121 1694167237 +0800 committer xiaolei.zl 1695348300 +0800 parent 6ab796e5721e5c58f9c0665c609eabf22b84821a author shirly121 1694167237 +0800 committer xiaolei.zl 1695348286 +0800 [GIE Compiler] fix bugs of columnId in schema refactor(flex): Replace the Adhoc csv reader with Arrow CSV reader (#3154) 1. Use Arrow CSV Reader to replace current adhoc csv reader, to support more configurable options in `bulk_load.yaml`. 2. Introduce `CSVFragmentLoader`, `BasicFragmentLoader` for `MutablePropertyFragment`. With this PR merged, `MutablePropertyFragment` will support loading fragment from csv with options: - delimeter: default '|' - header_row: default true - quoting: default false - quoting_char: default '"' - escaping: default false - escaping_char: default'\\' - batch_size: the batch size of when reading file into memory, default 1MB. - batch_reader: default false. If set to true, `arrow::csv::StreamingReader` will be used to parse the input file. Otherwise, `arrow::TableReader` will be used. With this PR merged, the performance of graph loading will be improved. The Adhoc Reader denote the current implemented csv parser, 1,2,4,8 denotes the parallelism of graph loading, i.e. how many labels of vertex/edge are concurrently processed. Note that TableReader is around 10x faster than StreamingReader. The possible reason could be the multi-threading is used. See [arrow-csv-doc](https://arrow.apache.org/docs/cpp/csv.html) for details. | Reader | Phase | 1 | 2 | 4 | 8 | | --------- | -------------- | ---------- |---------- |---------- |---------- | | Adhoc Reader | ReadFile\+LoadGraph |805s| 468s| 349s| 313s| | Adhoc Reader | Serialization | 126s| 126s| 126s| 126s| | Adhoc Reader | **Total** |931s| 594s| 475s| 439s| | Table Reader | ReadFile | 9s |9s |9s| 9s| | Table Reader | LoadGraph |455s| 280s| 211s| 182s| | Table Reader |Serialization |126s| 126s| 126s| 126s| | Table Reader | **Total** | 600s| 415s| 346s| 317s| | Streaming Reader | ReadFile |91s| 91s| 91s| 91s| | Streaming Reader | LoadGraph | 555s| 289s| 196s| 149s| | Streaming Reader | Serialization |126s| 126s| 126s| 126s| | Streaming Reader | **Total** | 772s| 506s| 413s| 366s| | Reader | Phase | 1 | 2 | 4 | 8 | | --------- | -------------- | ---------- |---------- |---------- |---------- | | Adhoc Reader | ReadFile\+LoadGraph |2720s| 1548s| 1176s| 948s| | Adhoc Reader | Serialization | 409s| 409s| 409s| 409s| | Adhoc Reader | **Total** | 3129s| 1957s| 1585s| 1357s| | Table Reader | ReadFile |24s| 24s| 24s| 24s| | Table Reader | LoadGraph |1576s| 949s| 728s| 602s| | Table Reader |Serialization |409s| 409s| 409s| 409s| | Table Reader | **Total** | 2009s| 1382s| 1161s| 1035s| | Streaming Reader | ReadFile |300s| 300s| 300s| 300s| | Streaming Reader | LoadGraph | 1740s| 965s| 669s| 497s| | Streaming Reader | Serialization | 409s| 409s| 409s| 409s| | Streaming Reader | **Total** | 2539s| 1674s| 1378s| 1206s| | Reader | Phase | 1 | 2 | 4 | 8 | | --------- | -------------- | ---------- |---------- |---------- |---------- | | Adhoc Reader | ReadFile\+LoadGraph | 8260s| 4900s |3603s |2999s| | Adhoc Reader | Serialization | 1201s | 1201s| 1201s |1201s| | Adhoc Reader | **Total** | 9461s| 6101s | 4804s |4200s| | Table Reader | ReadFile | 73s |73s| 96s| 96s| | Table Reader | LoadGraph |4650s| 2768s| 2155s |1778s| | Table Reader |Serialization | 1201s | 1201s| 1201s |1201s| | Table Reader | **Total** | 5924s| 4042s| 3452s| 3075s| | Streaming Reader | ReadFile | 889s |889s | 889s| 889s| | Streaming Reader | LoadGraph | 5589s| 3005s| 2200s| 1712s| | Streaming Reader | Serialization | 1201s| 1201s| 1201s |1201s | | Streaming Reader | **Total** | 7679s | 5095s |4290s| 3802s| FIx #3116 minor fix and move modern graph fix grin test todo: do_start fix fix stash fix fix make rules unique dockerfile stash minor change remove plugin-dir fix minor fix debug debug fix fix fix bulk_load.yaml bash format some fix fix format fix grin test some fi check ci fix ci set fix ci fix dd f disable tmate fix some bug fix fix refactor fix fix fix minor some fix fix support default src_dst primarykey mapping in bulk load fix fix fix fix Ci rename fix java and add get_person_name.cypher [GIE Compiler] minor fix use graphscope gstest format add movie queries dd debug add movie test format format fix script debug fix test script minor sort query results minor minor format --- .github/workflows/hqps-db-ci.yml | 40 +++- .../modern_graph/get_person_name.cypher | 2 +- flex/tests/hqps/hqps_cypher_test.sh | 79 ++++--- flex/tests/hqps/queries/movie/query1.cypher | 1 + flex/tests/hqps/queries/movie/query10.cypher | 4 + flex/tests/hqps/queries/movie/query11.cypher | 4 + flex/tests/hqps/queries/movie/query12.cypher | 2 + flex/tests/hqps/queries/movie/query13.cypher | 4 + flex/tests/hqps/queries/movie/query14.cypher | 6 + flex/tests/hqps/queries/movie/query15.cypher | 4 + flex/tests/hqps/queries/movie/query2.cypher | 1 + flex/tests/hqps/queries/movie/query3.cypher | 1 + flex/tests/hqps/queries/movie/query4.cypher | 2 + flex/tests/hqps/queries/movie/query5.cypher | 3 + flex/tests/hqps/queries/movie/query6.cypher | 3 + flex/tests/hqps/queries/movie/query7.cypher | 3 + flex/tests/hqps/queries/movie/query8.cypher | 2 + flex/tests/hqps/queries/movie/query9.cypher | 2 + interactive_engine/compiler/pom.xml | 1 + .../integration/suite/ldbc/MovieQueries.java | 199 ++++++++++++++++++ .../cypher/integration/movie/MovieTest.java | 115 ++++++++++ 21 files changed, 443 insertions(+), 35 deletions(-) create mode 100644 flex/tests/hqps/queries/movie/query1.cypher create mode 100644 flex/tests/hqps/queries/movie/query10.cypher create mode 100644 flex/tests/hqps/queries/movie/query11.cypher create mode 100644 flex/tests/hqps/queries/movie/query12.cypher create mode 100644 flex/tests/hqps/queries/movie/query13.cypher create mode 100644 flex/tests/hqps/queries/movie/query14.cypher create mode 100644 flex/tests/hqps/queries/movie/query15.cypher create mode 100644 flex/tests/hqps/queries/movie/query2.cypher create mode 100644 flex/tests/hqps/queries/movie/query3.cypher create mode 100644 flex/tests/hqps/queries/movie/query4.cypher create mode 100644 flex/tests/hqps/queries/movie/query5.cypher create mode 100644 flex/tests/hqps/queries/movie/query6.cypher create mode 100644 flex/tests/hqps/queries/movie/query7.cypher create mode 100644 flex/tests/hqps/queries/movie/query8.cypher create mode 100644 flex/tests/hqps/queries/movie/query9.cypher create mode 100644 interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/integration/suite/ldbc/MovieQueries.java create mode 100644 interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/integration/movie/MovieTest.java diff --git a/.github/workflows/hqps-db-ci.yml b/.github/workflows/hqps-db-ci.yml index 08b52da99ffd..1bbb9142cf07 100644 --- a/.github/workflows/hqps-db-ci.yml +++ b/.github/workflows/hqps-db-ci.yml @@ -87,10 +87,13 @@ jobs: INTERACTIVE_WORKSPACE: /tmp/interactive_workspace run: | # download dataset - git clone -b master --single-branch --depth=1 https://github.com/GraphScope/gstest.git ${GS_TEST_DIR} + #git clone -b master --single-branch --depth=1 https://github.com/GraphScope/gstest.git ${GS_TEST_DIR} + git clone -b master --single-branch --depth=1 https://github.com/zhanglei1949/gstest.git ${GS_TEST_DIR} mkdir -p ${INTERACTIVE_WORKSPACE}/data/ldbc GRAPH_SCHEMA_YAML=${GS_TEST_DIR}/flex/ldbc-sf01-long-date/audit_graph_schema.yaml cp ${GRAPH_SCHEMA_YAML} ${INTERACTIVE_WORKSPACE}/data/ldbc/graph.yaml + mkdir -p ${INTERACTIVE_WORKSPACE}/data/movies + cp ${GS_TEST_DIR}/flex/movies/movies_schema.yaml ${INTERACTIVE_WORKSPACE}/data/movies/graph.yaml - name: Sample Query test env: @@ -131,7 +134,20 @@ jobs: eval ${cmd} done - - name: Run End-to-End cypher adhoc query test + # test movie graph, 8,9,10 are not supported now + # change the default_graph config in ${GS_TEST_DIR}/flex/ldbc-sf01-long-date/engine_config.yaml to movies + sed -i 's/default_graph: ldbc/default_graph: movies/g' ${GS_TEST_DIR}/flex/ldbc-sf01-long-date/engine_config.yaml + for i in 1 2 3 4 5 6 7 11 12 13 14 15; + do + cmd="./load_plan_and_gen.sh -e=hqps -i=../tests/hqps/queries/movie/query${i}.cypher -w=/tmp/codgen/" + cmd=${cmd}" -o=/tmp/plugin --ir_conf=${GS_TEST_DIR}/flex/ldbc-sf01-long-date/engine_config.yaml " + cmd=${cmd}" --graph_schema_path=${INTERACTIVE_WORKSPACE}/data/movies/graph.yaml" + cmd=${cmd}" --gie_home=${GIE_HOME}" + echo $cmd + eval ${cmd} + done + + - name: Run End-to-End cypher adhoc ldbc query test env: GS_TEST_DIR: ${{ github.workspace }}/gstest HOME : /home/graphscope/ @@ -140,5 +156,23 @@ jobs: cd ${GITHUB_WORKSPACE}/flex/tests/hqps/ export FLEX_DATA_DIR=${GS_TEST_DIR}/flex/ldbc-sf01-long-date export ENGINE_TYPE=hiactor - bash hqps_cypher_test.sh ${GS_TEST_DIR} ${INTERACTIVE_WORKSPACE} + # change the default_graph config in ${GS_TEST_DIR}/flex/ldbc-sf01-long-date/engine_config.yaml to ldbc + sed -i 's/default_graph: movies/default_graph: ldbc/g' ${GS_TEST_DIR}/flex/ldbc-sf01-long-date/engine_config.yaml + bash hqps_cypher_test.sh ${INTERACTIVE_WORKSPACE} ldbc ${GS_TEST_DIR}/flex/ldbc-sf01-long-date/audit_bulk_load.yaml \ + ${GS_TEST_DIR}/flex/ldbc-sf01-long-date/engine_config.yaml + + - name: Run End-to-End cypher adhoc movie query test + env: + GS_TEST_DIR: ${{ github.workspace }}/gstest + HOME : /home/graphscope/ + INTERACTIVE_WORKSPACE: /tmp/interactive_workspace + run: | + cd ${GITHUB_WORKSPACE}/flex/tests/hqps/ + export FLEX_DATA_DIR=../../interactive/examples/movies/ + export ENGINE_TYPE=hiactor + # change the default_graph config in ${GS_TEST_DIR}/flex/ldbc-sf01-long-date/engine_config.yaml to movies + sed -i 's/default_graph: ldbc/default_graph: movies/g' ${GS_TEST_DIR}/flex/ldbc-sf01-long-date/engine_config.yaml + bash hqps_cypher_test.sh ${INTERACTIVE_WORKSPACE} movies ${GS_TEST_DIR}/flex/movies/movies_import.yaml \ + ${GS_TEST_DIR}/flex/ldbc-sf01-long-date/engine_config.yaml + diff --git a/flex/interactive/examples/modern_graph/get_person_name.cypher b/flex/interactive/examples/modern_graph/get_person_name.cypher index f8c9f275ae4e..fbb3197f3849 100644 --- a/flex/interactive/examples/modern_graph/get_person_name.cypher +++ b/flex/interactive/examples/modern_graph/get_person_name.cypher @@ -1 +1 @@ -MATCH(p : person {id: $personId}) RETURN p.name; \ No newline at end of file +MATCH(p : person {id: $personId}) RETURN p.name; diff --git a/flex/tests/hqps/hqps_cypher_test.sh b/flex/tests/hqps/hqps_cypher_test.sh index 1cb4837dfccf..fbb77456da24 100644 --- a/flex/tests/hqps/hqps_cypher_test.sh +++ b/flex/tests/hqps/hqps_cypher_test.sh @@ -19,47 +19,50 @@ SERVER_BIN=${FLEX_HOME}/build/bin/sync_server GIE_HOME=${FLEX_HOME}/../interactive_engine/ # -if [ $# -lt 2 ]; then - echo "only receives: $# args, need 2" - echo "Usage: $0 " +if [ ! $# -eq 4 ]; then + echo "only receives: $# args, need 4" + echo "Usage: $0 " exit 1 fi -GS_TEST_DIR=$1 -INTERACTIVE_WORKSPACE=$2 -if [ ! -d ${GS_TEST_DIR} ]; then - echo "GS_TEST_DIR: ${GS_TEST_DIR} not exists" - exit 1 -fi +INTERACTIVE_WORKSPACE=$1 +GRAPH_NAME=$2 +GRAPH_BULK_LOAD_YAML=$3 +ENGINE_CONFIG_PATH=$4 if [ ! -d ${INTERACTIVE_WORKSPACE} ]; then echo "INTERACTIVE_WORKSPACE: ${INTERACTIVE_WORKSPACE} not exists" exit 1 fi - -ENGINE_CONFIG_PATH=${GS_TEST_DIR}/flex/ldbc-sf01-long-date/engine_config.yaml -ORI_GRAPH_SCHEMA_YAML=${GS_TEST_DIR}/flex/ldbc-sf01-long-date/audit_graph_schema.yaml -GRAPH_SCHEMA_YAML=${INTERACTIVE_WORKSPACE}/data/ldbc/graph.yaml -GRAPH_BULK_LOAD_YAML=${GS_TEST_DIR}/flex/ldbc-sf01-long-date/audit_bulk_load.yaml -COMPILER_GRAPH_SCHEMA=${GS_TEST_DIR}/flex/ldbc-sf01-long-date/audit_graph_schema.yaml -GRAPH_CSR_DATA_DIR=${HOME}/csr-data-dir/ -# check if GRAPH_SCHEMA_YAML exists -if [ ! -f ${GRAPH_SCHEMA_YAML} ]; then - echo "GRAPH_SCHEMA_YAML: ${GRAPH_SCHEMA_YAML} not found" +# check graph is ldbc or movies +if [ ${GRAPH_NAME} != "ldbc" ] && [ ${GRAPH_NAME} != "movies" ]; then + echo "GRAPH_NAME: ${GRAPH_NAME} not supported, use movies or ldbc" + exit 1 +fi +if [ ! -d ${INTERACTIVE_WORKSPACE}/data/${GRAPH_NAME} ]; then + echo "GRAPH: ${GRAPH_NAME} not exists" + exit 1 +fi +if [ ! -f ${INTERACTIVE_WORKSPACE}/data/${GRAPH_NAME}/graph.yaml ]; then + echo "GRAPH_SCHEMA_FILE: ${BULK_LOAD_FILE} not exists" exit 1 fi - -# check if GRAPH_BULK_LOAD_YAML exists if [ ! -f ${GRAPH_BULK_LOAD_YAML} ]; then - echo "GRAPH_BULK_LOAD_YAML: ${GRAPH_BULK_LOAD_YAML} not found" + echo "GRAPH_BULK_LOAD_YAML: ${GRAPH_BULK_LOAD_YAML} not exists" exit 1 fi - -# check if COMPILER_GRAPH_SCHEMA exists -if [ ! -f ${COMPILER_GRAPH_SCHEMA} ]; then - echo "COMPILER_GRAPH_SCHEMA: ${COMPILER_GRAPH_SCHEMA} not found" +if [ ! -f ${ENGINE_CONFIG_PATH} ]; then + echo "ENGINE_CONFIG: ${ENGINE_CONFIG_PATH} not exists" exit 1 fi +GRAPH_SCHEMA_YAML=${INTERACTIVE_WORKSPACE}/data/${GRAPH_NAME}/graph.yaml +GRAPH_CSR_DATA_DIR=${HOME}/csr-data-dir/ +# rm data dir if exists +if [ -d ${GRAPH_CSR_DATA_DIR} ]; then + rm -rf ${GRAPH_CSR_DATA_DIR} +fi + + RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color @@ -92,8 +95,6 @@ start_engine_service(){ err "SERVER_BIN not found" exit 1 fi - # export FLEX_DATA_DIR - export FLEX_DATA_DIR=${GS_TEST_DIR}/flex/ldbc-sf01-long-date/ cmd="${SERVER_BIN} -c ${ENGINE_CONFIG_PATH} -g ${GRAPH_SCHEMA_YAML} " cmd="${cmd} --data-path ${GRAPH_CSR_DATA_DIR} -l ${GRAPH_BULK_LOAD_YAML} " @@ -112,7 +113,7 @@ start_engine_service(){ start_compiler_service(){ echo "try to start compiler service" pushd ${GIE_HOME}/compiler - cmd="make run graph.schema=${COMPILER_GRAPH_SCHEMA} config.path=${ENGINE_CONFIG_PATH}" + cmd="make run graph.schema=${GRAPH_SCHEMA_YAML} config.path=${ENGINE_CONFIG_PATH}" echo "Start compiler service with command: ${cmd}" ${cmd} & sleep 5 @@ -142,11 +143,27 @@ run_simple_test(){ popd } +run_movie_test(){ + echo "run movie test" + pushd ${GIE_HOME}/compiler + cmd="mvn test -Dtest=com.alibaba.graphscope.cypher.integration.movie.MovieTest" + echo "Start movie test: ${cmd}" + ${cmd} + info "Finish movie test" + popd +} + kill_service start_engine_service start_compiler_service -run_ldbc_test -run_simple_test +# if GRAPH_NAME equals ldbc +if [ "${GRAPH_NAME}" == "ldbc" ]; then + run_ldbc_test + run_simple_test +else + run_movie_test +fi + kill_service diff --git a/flex/tests/hqps/queries/movie/query1.cypher b/flex/tests/hqps/queries/movie/query1.cypher new file mode 100644 index 000000000000..d08ec9d27a68 --- /dev/null +++ b/flex/tests/hqps/queries/movie/query1.cypher @@ -0,0 +1 @@ +MATCH (tom:Person) WHERE tom.name = "Tom Hanks" RETURN tom.born AS bornYear,tom.name AS personName; \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query10.cypher b/flex/tests/hqps/queries/movie/query10.cypher new file mode 100644 index 000000000000..4787fc5f03ec --- /dev/null +++ b/flex/tests/hqps/queries/movie/query10.cypher @@ -0,0 +1,4 @@ +MATCH p=shortestPath( + (bacon:Person {name:"Kevin Bacon"})-[*]-(meg:Person {name:"Meg Ryan"}) +) +RETURN p; \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query11.cypher b/flex/tests/hqps/queries/movie/query11.cypher new file mode 100644 index 000000000000..f4e32e1b70f8 --- /dev/null +++ b/flex/tests/hqps/queries/movie/query11.cypher @@ -0,0 +1,4 @@ +MATCH (tom:Person {name: 'Tom Hanks'})-[r:ACTED_IN]->(movie:Movie) +WITH movie.title as movieTitle, movie.released as movieReleased +ORDER BY movieReleased DESC, movieTitle ASC LIMIT 10 +return movieTitle, movieReleased; \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query12.cypher b/flex/tests/hqps/queries/movie/query12.cypher new file mode 100644 index 000000000000..9d70234aa885 --- /dev/null +++ b/flex/tests/hqps/queries/movie/query12.cypher @@ -0,0 +1,2 @@ +MATCH (tom:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(coActor:Person) +WITH DISTINCT coActor.name AS coActorName ORDER BY coActorName ASC LIMIT 10 return coActorName; \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query13.cypher b/flex/tests/hqps/queries/movie/query13.cypher new file mode 100644 index 000000000000..11dcdc709eee --- /dev/null +++ b/flex/tests/hqps/queries/movie/query13.cypher @@ -0,0 +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 ORDER BY coCoActor.name ASC LIMIT 10; \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query14.cypher b/flex/tests/hqps/queries/movie/query14.cypher new file mode 100644 index 000000000000..c872529024b2 --- /dev/null +++ b/flex/tests/hqps/queries/movie/query14.cypher @@ -0,0 +1,6 @@ +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, count(coCoActor) as frequency +ORDER BY frequency DESC +LIMIT 5; \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query15.cypher b/flex/tests/hqps/queries/movie/query15.cypher new file mode 100644 index 000000000000..ecaa4128e585 --- /dev/null +++ b/flex/tests/hqps/queries/movie/query15.cypher @@ -0,0 +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) +ORDER BY movie1.title ASC, movie2.title ASC LIMIT 10 +RETURN tom.name AS actorName, movie1.title AS movie1Title, coActor.name AS coActorName, movie2.title AS movie2Title, cruise.name AS coCoActorName; \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query2.cypher b/flex/tests/hqps/queries/movie/query2.cypher new file mode 100644 index 000000000000..f5a2260cb74e --- /dev/null +++ b/flex/tests/hqps/queries/movie/query2.cypher @@ -0,0 +1 @@ +MATCH (cloudAtlas:Movie {title: "Cloud Atlas"}) RETURN cloudAtlas.tagline AS tagline, cloudAtlas.released AS releasedYear,cloudAtlas.title AS title; \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query3.cypher b/flex/tests/hqps/queries/movie/query3.cypher new file mode 100644 index 000000000000..3db95c2962b7 --- /dev/null +++ b/flex/tests/hqps/queries/movie/query3.cypher @@ -0,0 +1 @@ +MATCH (people:Person) ORDER BY people.name ASC LIMIT 10 RETURN people.name; \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query4.cypher b/flex/tests/hqps/queries/movie/query4.cypher new file mode 100644 index 000000000000..b68320012d03 --- /dev/null +++ b/flex/tests/hqps/queries/movie/query4.cypher @@ -0,0 +1,2 @@ +MATCH (nineties:Movie) WHERE nineties.released >= 1990 AND nineties.released < 2000 ORDER BY nineties.title DESC LIMIT 10 +RETURN nineties.title; \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query5.cypher b/flex/tests/hqps/queries/movie/query5.cypher new file mode 100644 index 000000000000..cd6a477fc145 --- /dev/null +++ b/flex/tests/hqps/queries/movie/query5.cypher @@ -0,0 +1,3 @@ +MATCH (tom:Person {name: "Tom Hanks"})-[:ACTED_IN]->(tomHanksMovies) +ORDER BY tomHanksMovies.released DESC, tomHanksMovies.title ASC LIMIT 10 +RETURN tom.born AS bornYear,tomHanksMovies.tagline AS movieTagline, tomHanksMovies.title AS movieTitle, tomHanksMovies.released AS releaseYear; \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query6.cypher b/flex/tests/hqps/queries/movie/query6.cypher new file mode 100644 index 000000000000..4684b06d441a --- /dev/null +++ b/flex/tests/hqps/queries/movie/query6.cypher @@ -0,0 +1,3 @@ +MATCH (cloudAtlas:Movie {title: "Cloud Atlas"})<-[:DIRECTED]-(directors) +ORDER BY directors.name ASC LIMIT 10 +RETURN directors.name; \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query7.cypher b/flex/tests/hqps/queries/movie/query7.cypher new file mode 100644 index 000000000000..391fa965711c --- /dev/null +++ b/flex/tests/hqps/queries/movie/query7.cypher @@ -0,0 +1,3 @@ +MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors) +ORDER BY m.released DESC, m.title ASC LIMIT 10 +RETURN m.title AS movieTitle, m.released AS releasedYear, coActors.name AS coActor; \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query8.cypher b/flex/tests/hqps/queries/movie/query8.cypher new file mode 100644 index 000000000000..3335a4621dfd --- /dev/null +++ b/flex/tests/hqps/queries/movie/query8.cypher @@ -0,0 +1,2 @@ +MATCH (people:Person)-[relatedTo]-(:Movie {title: "Cloud Atlas"}) +RETURN people.name, type(relatedTo), relatedTo \ No newline at end of file diff --git a/flex/tests/hqps/queries/movie/query9.cypher b/flex/tests/hqps/queries/movie/query9.cypher new file mode 100644 index 000000000000..951cef1edf3c --- /dev/null +++ b/flex/tests/hqps/queries/movie/query9.cypher @@ -0,0 +1,2 @@ +MATCH (bacon:Person {name:"Kevin Bacon"})-[*1..3]-(hollywood) +RETURN DISTINCT bacon, hollywood \ No newline at end of file diff --git a/interactive_engine/compiler/pom.xml b/interactive_engine/compiler/pom.xml index 1af1b5bb93bb..590a7928cccf 100644 --- a/interactive_engine/compiler/pom.xml +++ b/interactive_engine/compiler/pom.xml @@ -253,6 +253,7 @@ **/IrLdbcTest.java **/SimpleMatchTest.java **/IrPatternTest.java + **/MovieTest.java diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/integration/suite/ldbc/MovieQueries.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/integration/suite/ldbc/MovieQueries.java new file mode 100644 index 000000000000..dad4e55d6913 --- /dev/null +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/cypher/integration/suite/ldbc/MovieQueries.java @@ -0,0 +1,199 @@ +package com.alibaba.graphscope.cypher.integration.suite.ldbc; + +import java.util.Arrays; +import java.util.List; + +public class MovieQueries { + public static QueryContext get_movie_query1_test() { + String query = + "MATCH (tom:Person) WHERE tom.name = \"Tom Hanks\" RETURN tom.born AS" + + " bornYear,tom.name AS personName;"; + List expected = + Arrays.asList("Record<{bornYear: 1956, personName: \"Tom Hanks\"}>"); + return new QueryContext(query, expected); + } + + public static QueryContext get_movie_query2_test() { + String query = + "MATCH (cloudAtlas:Movie {title: \"Cloud Atlas\"}) RETURN cloudAtlas.tagline AS" + + " tagLine, cloudAtlas.release AS releasedYear,cloudAtlas.title AS title;"; + List expected = + Arrays.asList( + "Record<{tagline: \"Everything is connected\", releasedYear: 2012, title:" + + " \"Cloud Atlas\"}>"); + return new QueryContext(query, expected); + } + + public static QueryContext get_movie_query3_test() { + String query = + "MATCH (people:Person) ORDER BY people.name ASC LIMIT 10 RETURN people.name;"; + List expected = + Arrays.asList( + "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 ORDER BY nineties.title DESC LIMIT 10\n" + + "RETURN nineties.title;"; + List expected = 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" + + "ORDER BY tomHanksMovies.released DESC, tomHanksMovies.title ASC LIMIT 10\n" + + "RETURN tom.born AS bornYear,tomHanksMovies.tagline AS movieTagline," + + " tomHanksMovies.title AS movieTitle, tomHanksMovies.released AS" + + " releaseYear;"; + List 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" + + "ORDER BY directors.name ASC LIMIT 10\n" + + "RETURN directors.name;"; + List 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" + + "ORDER BY m.released DESC, m.title ASC LIMIT 10\n" + + "RETURN m.title AS movieTitle, m.released AS releasedYear, coActors.name AS" + + " coActor;"; + List expected = Arrays.asList(); + return new QueryContext(query, expected); + } + + public static QueryContext get_movie_query8_test() { + String query = + "MATCH (people:Person)-[relatedTo]-(:Movie {title: \"Cloud Atlas\"})\n" + + "RETURN people.name, type(relatedTo), relatedTo"; + List expected = Arrays.asList(); + return new QueryContext(query, expected); + } + + public static QueryContext get_movie_query9_test() { + String query = + "MATCH (bacon:Person {name:\"Kevin Bacon\"})-[*1..3]-(hollywood)\n" + + "RETURN DISTINCT bacon, hollywood"; + List expected = Arrays.asList(); + return new QueryContext(query, expected); + } + + public static QueryContext get_movie_query10_test() { + String query = + "MATCH p=shortestPath(\n" + + " (bacon:Person {name:\"Kevin Bacon\"})-[*]-(meg:Person {name:\"Meg" + + " Ryan\"})\n" + + ")\n" + + "RETURN p;"; + List expected = Arrays.asList(); + return new QueryContext(query, expected); + } + + public static QueryContext get_movie_query11_test() { + String query = + "MATCH (tom:Person {name: 'Tom Hanks'})-[r:ACTED_IN]->(movie:Movie)\n" + + "WITH movie.title as movieTitle, movie.released as movieReleased\n" + + "ORDER BY movieReleased DESC, movieTitle ASC LIMIT 10\n" + + "return movieTitle, movieReleased;"; + List 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" + + "WITH DISTINCT coActor.name AS coActorName ORDER BY coActorName ASC LIMIT 10" + + " return coActorName;"; + List 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" + + "WHERE tom <> coCoActor\n" + + "AND NOT (tom)-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(coCoActor)\n" + + "RETURN coCoActor.name ORDER BY coCoActor.name ASC LIMIT 10;"; + List 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); + } + + public static QueryContext get_movie_query14_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" + + "WHERE tom <> coCoActor\n" + + "AND NOT (tom)-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(coCoActor)\n" + + "RETURN coCoActor.name, count(coCoActor) as frequency\n" + + "ORDER BY frequency DESC\n" + + "LIMIT 5;"; + List 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" + + "WHERE NOT (tom)-[:ACTED_IN]->(:Movie)<-[:ACTED_IN]-(cruise)\n" + + "ORDER BY movie1.title ASC, movie2.title ASC LIMIT 10\n" + + "RETURN tom.name AS actorName, movie1.title AS movie1Title, coActor.name AS" + + " coActorName, movie2.title AS movie2Title, cruise.name AS coCoActorName;"; + List expected = Arrays.asList(); + return new QueryContext(query, expected); + } +} diff --git a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/integration/movie/MovieTest.java b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/integration/movie/MovieTest.java new file mode 100644 index 000000000000..96b9dac6e904 --- /dev/null +++ b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/cypher/integration/movie/MovieTest.java @@ -0,0 +1,115 @@ +package com.alibaba.graphscope.cypher.integration.movie; + +import com.alibaba.graphscope.cypher.integration.suite.ldbc.MovieQueries; +import com.alibaba.graphscope.cypher.integration.suite.ldbc.QueryContext; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.neo4j.driver.GraphDatabase; +import org.neo4j.driver.Result; +import org.neo4j.driver.Session; + +public class MovieTest { + + private static Session session; + + @BeforeClass + public static void beforeClass() { + String neo4jServerUrl = + System.getProperty("neo4j.bolt.server.url", "neo4j://localhost:7687"); + session = GraphDatabase.driver(neo4jServerUrl).session(); + } + + @Test + public void run_movie_query1_test() { + QueryContext testQuery = MovieQueries.get_movie_query1_test(); + Result result = session.run(testQuery.getQuery()); + Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString()); + } + + @Test + public void run_movie_query2_test() { + QueryContext testQuery = MovieQueries.get_movie_query2_test(); + Result result = session.run(testQuery.getQuery()); + Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString()); + } + + @Test + public void run_movie_query3_test() { + QueryContext testQuery = MovieQueries.get_movie_query3_test(); + Result result = session.run(testQuery.getQuery()); + Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString()); + } + + @Test + public void run_movie_query4_test() { + QueryContext testQuery = MovieQueries.get_movie_query4_test(); + Result result = session.run(testQuery.getQuery()); + Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString()); + } + + @Test + public void run_movie_query5_test() { + QueryContext testQuery = MovieQueries.get_movie_query5_test(); + Result result = session.run(testQuery.getQuery()); + Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString()); + } + + @Test + public void run_movie_query6_test() { + QueryContext testQuery = MovieQueries.get_movie_query6_test(); + Result result = session.run(testQuery.getQuery()); + Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString()); + } + + @Test + public void run_movie_query7_test() { + QueryContext testQuery = MovieQueries.get_movie_query7_test(); + Result result = session.run(testQuery.getQuery()); + Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString()); + } + + @Test + public void run_movie_query11_test() { + QueryContext testQuery = MovieQueries.get_movie_query11_test(); + Result result = session.run(testQuery.getQuery()); + Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString()); + } + + @Test + public void run_movie_query12_test() { + QueryContext testQuery = MovieQueries.get_movie_query12_test(); + Result result = session.run(testQuery.getQuery()); + Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString()); + } + + @Test + public void run_movie_query13_test() { + QueryContext testQuery = MovieQueries.get_movie_query13_test(); + Result result = session.run(testQuery.getQuery()); + Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString()); + } + + @Test + public void run_movie_query14_test() { + QueryContext testQuery = MovieQueries.get_movie_query14_test(); + Result result = session.run(testQuery.getQuery()); + Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString()); + } + + @Test + public void run_movie_query15_test() { + QueryContext testQuery = MovieQueries.get_movie_query15_test(); + Result result = session.run(testQuery.getQuery()); + Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString()); + } + + @AfterClass + public static void afterClass() { + if (session != null) { + session.close(); + } + } +}