查询schema的成圈户数

比如A->B->C->A,怎么找到这样的圈

可以参考一下以下代码(未经测试,仅供参考),这里的圈是限定了跳数的区间范围的(比如1到4跳内,下限可以按需求来,上限可以根据图的密度特征设置,一般在10跳以内):

# 1. Create graph
CREATE GRAPH GraphName ()

# 2. Create schema_change job
CREATE SCHEMA_CHANGE JOB change_schema_of_GraphName FOR GRAPH GraphName {
  # 2.1 Create vertices
  ADD VERTEX Lender (PRIMARY_ID lender_id INT, lender_name STRING, is_black BOOL, cc_id INT) WITH PRIMARY_ID_AS_ATTRIBUTE="true";

  # 2.2 Create edges
  ADD DIRECTED EDGE LenderRecommendLender (FROM Lender, TO Lender, weight DOUBLE);
}

# 3. Run schema_change job
RUN JOB change_schema_of_GraphName

# 4. Drop schema_change job
DROP JOB change_schema_of_GraphName

# 5. Create query
CREATE QUERY q1_circle_detection(VERTEX<Lender> source, INT min_step_num, INT max_step_num) FOR GRAPH GraphName {
  ## Input Example:
  # source: 1
  # min_step_num: 1
  # max_step_num: 4
  ##
  int halfStep;
  int step;

  ListAccum<ListAccum<Edge>> @edgeList;
  ListAccum<ListAccum<Edge>> @newEdgeList;
  ListAccum<ListAccum<Edge>> @@circleEdge;
  OrAccum @receiveNewPath = False;

  //----------- 1. Initialization -----------
  X = {source};

  //----------- 2. start valid path traversal and circle detection -----------
  step = 0;
  WHILE X.size() > 0 LIMIT max_step_num DO
    X = SELECT t
        FROM   X:s -(LenderRecommendLender:e)-> Lender:t
        ACCUM  IF s.@edgeList.size() == 0 THEN
                 t.@newEdgeList += [e]
               ELSE
                 FOREACH path in s.@edgeList DO
                   t.@newEdgeList += path + [e]
                 END
               END,
               //reset receiveNewPath as false
               t.@receiveNewPath = False
        POST_ACCUM CASE WHEN t.@newEdgeList.size() > 0 THEN
                     //if it backs to start point, there is a valid circle
                     IF t.lender_id == srcId THEN
                       //step + 1 gives the current updated step
                       IF step + 1 >= min_step_num THEN
                         @@circleEdge += t.@newEdgeList
                       END
                     //else, overwrite the old @edgeTupleList, since the old one is already used
                     ELSE
                       t.@edgeList = t.@newEdgeList
                     END,
                     t.@receiveNewPath = True,
                     t.@newEdgeList.clear()
                   END
        HAVING t.lender_id != srcId
               AND t.@receiveNewPath == True
    ;
    step = step + 1;
  END;
  PRINT @@circleEdge;
}

# 6. Install query
INSTALL query *

收到,谢谢! 基于您的建议完成