# Each statement's operation type is either ControlFlow, DML, or other.# Each statement's syntax type is either queryBodyStmt or DMLSubStmt.CREATE QUERY stmtTypes (parameterList) FOR GRAPH g [other queryBodyStmt1;ControlFlow queryBodyStmt2 # ControlFlow inside top level.other queryBodyStmt2.1; # subStmts in ControlFlow are queryBody unless inside DML.ControlFlow queryBodyStmt2.2 # ControlFlow inside ControlFlow inside top levelother queryBodyStmt2.2.1;other queryBodyStmt2.2.2;END;DML queryBodyStmt2.3 # DML inside ControlFlow inside top-levelother DMLSubStmt2.3.1,# switch to DMLSubStmtother DMLSubStmt2.3.2;END;DML queryBodyStmt3 # DML inside top level.other DMLSubStmt3.1,# All subStmts in DML must be DMLSubStmt typeControlFlow DMLSubStmt3.2 # ControlFlow inside DML inside top levelother DMLSubStmt3.2.1,other DMLSubStmt3.2.2,DML DMLsubStmt3.3other DMLSubStmt3.3.1,other DMLSubStmt3.3.2;other queryBodyStmt4;
以下是查询主体层语句的说明:
以下是DML子句中的说明:
安装一个查询
installQuery :=INSTALL QUERY [installOptions] ( "*"| ALL | name [, name]* )
CREATE QUERY query1... INSTALL QUERY query1 RUN QUERY query1(...) ... INSTALL QUERY -OPTIMIZE # (optional) optimizes run time performance for query1 and query2 RUN QUERY query1(...) # runs faster than before
curl -X GET "http://localhost:9000/query/testGraph/RunQueryEx?p1=1&p2=test&p3=3.14"curl -d @RunQueryExPara.dat -X GET "http://localhost:9000/query/testGraph/RunQueryEx"
其中RunQueryExPara.dat具有与第一个链接地址中的查询字符串完全相同的字符串。
RunQueryExPara.dat
p1=1&p2=test&p3=3.14
要查看用户已经安装了的GSQL查询的参数名称和类型列表,请运行以下REST ++请求:
curl -X GET "http://localhost:9000/endpoints?dynamic=true"
# 1. SET or BAGCREATE QUERY RunQueryEx2(SET<INT> p1) FOR GRAPH testGraph{ .... }# To run this query (either RUN QUERY or curl):GSQL >RUN QUERY RunQueryEx2([1,5,10])curl -X GET "http://localhost:9000/query/testGraph/RunQueryEx2?p1=1&p1=5&p1=10"# 2. VERTEX.# First parameter is any vertex; second parameter must be a person type.CREATE QUERY printOneVertex(VERTEX va, VERTEX<person> vp) FOR GRAPH socialNet { PRINT va, vp;}# To run this query:GSQL >RUN QUERY printOneVertex(("person1","person"),"person2")# 1st param must give type: (vertex_id, vertex_type)curl -X GET 'http://localhost:9000/query/socialNet/printOneVertex?va=person1&va.type=person&vp=person2'# 3. BAG or SET of VERTEX, any typeCREATE QUERY printOneBagVertices(BAG<VERTEX> va) FOR GRAPH socialNet { PRINT va;}# To run this query:GSQL > RUN QUERY printOneBagVertices([("person1","person"), ("11","post")]) # [(vertex_1_id, vertex_1_type), (vertex_2_id, vertex_2_type), ...]
curl -X GET 'http://localhost:9000/query/socialNet/printOneBagVertices?va\[0\]=person1&va\[0\].type=person&va\[1\]=11&va\[1\].type=post'
curl -g -X GET 'http://localhost:9000/query/socialNet/printOneBagVertices?va[0]=person1&va[0].type=person&va[1]=11&va[1].type=post'
# 4. BAG or SET of VERTEX, pre-specified typeCREATE QUERY printOneSetVertices(SET<VERTEX<person>> vp) FOR GRAPH socialNet { PRINT vp;}# To run this query:GSQL >RUN QUERY printOneSetVertices(["person3","person4"])# [vertex_1_id, vertex_2_id, ...]curl -X GET 'http://localhost:9000/query/socialNet/printOneSetVertices?vp=person3&vp=person4'
GSQL >RUN QUERY -av test()## In a curl URL call。Note the use of both single and double underscores.curl -X GET 'http://localhost:9000/query/graphname/queryname?__GQUERY__USING_ALL_ACTIVE_MODE=true'
GSQL >RUN QUERY -d test()## In a curl URL call。Note the use of both single and double underscores.curl -X GET 'http://localhost:9000/query/graphname/queryname?__GQUERY__monitor=true'
生成日志文件的地址会作为输出消息的一部分。下面的例子展示了输出的样式:
Query Block Start (#6) start at 11:52:06.415284Query Block Start (#6) end at 11:52:06.415745 (takes 0.000442 s)Query test takes totally 0.001 s (restpp's pre/post process time not included)---------------- Summary (sort by total_time desc) ----------------Query Block Start on Line 6---------------------------------------------------------- total iterations count : 1 avg iterations stats : 0.000442s max iterations stats : 0.000442s min iterations stats : 0.000442s total activated vertex count : 2 max activated vertex count : 2 min activated vertex count : 2