apache / incubator-hugegraph

A graph database that supports more than 100+ billion data, high performance and scalability (Include OLTP Engine & REST-API & Backends)
https://hugegraph.apache.org
Apache License 2.0
2.63k stars 517 forks source link

gremlin查询语句返回No such property: values for class: Script504 #2306

Closed Zony7 closed 1 year ago

Zony7 commented 1 year ago

Problem Type (问题类型)

gremlin (结果不合预期)

Before submit

Environment (环境信息)

Your Question (问题描述)

我准备用gremlin语句实现如下两个查询: image QQ截图20230906131111

Vertex/Edge example (问题点 / 边数据举例)

两个查询语句如下:
第一个:
def calendar=java.util.Calendar.getInstance();
calendar.setTime(new Date($startDate));
calendar.add(java.util.Calendar.DAY_OF_YEAR, $durationDays);
def endDate=calendar.getTime();
result = g.V().has("Person","id", $personId)
     .sideEffect(
         __.both("Person_knows_Person").in("Post_hasCreator_Person")
         .outE("Post_hasTag_Tag").inV().limit(1).dedup().store("oldTags")
         )
.both("Person_knows_Person")
.in("Post_hasCreator_Person").as("PostNode")
.outE("Post_hasTag_Tag")
.inV().where(without("oldTags")).limit(1)
.as("TagNode")
.project("postId", "tag.name")
.by(coalesce(select("PostNode").values("id"), constant(0)))
.by(coalesce(select("TagNode").values("name"), constant("")))
.dedup()
.groupCount().by("tag.name")
.unfold().limit(10)
.order().by(values, desc).by(keys, asc)
.project("tag.name", "postCount")
.by(select(keys))
.by(select(values))
result
第二个:
result = g.V().has("Person","id",$personId)
          .repeat(both("Person_knows_Person"))
          .emit().times(2)
          .as("FriendNode")
          .in("Post_hasCreator_Person").limit(2).as("PostNode")
          .in("Forum_containerOf_Post").as("ForumNode")
          .project('forumInfo','postId')
                    .by(select('ForumNode').valueMap('id','title'))
                    .by(select('PostNode').values('id'))
                    .groupCount().by(select("forumInfo"))
                    .unfold()
                    .project("forum.id","forum.title","postCount")
                    .by(select(keys).select("id").unfold())
                    .by(select(keys).select("title").unfold())
                    .by(values)
                    .as("result")
                    .select("result")
                    .select("forum.title","postCount")
                    .limit(1)
result
但是结果均报错:
groovy.lang.MissingPropertyException: No such property: values for class: Script504
    at org.apache.hugegraph.exception.ServerException.fromResponse(ServerException.java:45)
    at org.apache.hugegraph.client.RestClient.checkStatus(RestClient.java:91)
    at org.apache.hugegraph.rest.AbstractRestClient.post(AbstractRestClient.java:232)
    at org.apache.hugegraph.rest.AbstractRestClient.post(AbstractRestClient.java:206)
    at org.apache.hugegraph.api.gremlin.GremlinAPI.post(GremlinAPI.java:39)
    at org.apache.hugegraph.driver.GremlinManager.execute(GremlinManager.java:49)
    at org.apache.hugegraph.api.gremlin.GremlinRequest$Builder.execute(GremlinRequest.java:54)
    at org.apache.snb.impls.workloads.hugegraph.gremlin.operationhandlers.HugegraphListOperationHandler.executeOperation(HugegraphListOperationHandler.java:108)
    at org.apache.snb.impls.workloads.hugegraph.gremlin.operationhandlers.HugegraphListOperationHandler.executeOperation(HugegraphListOperationHandler.java:39)
    at org.ldbcouncil.snb.driver.validation.ValidationParamsGenerator.doNext(ValidationParamsGenerator.java:101)
    at org.ldbcouncil.snb.driver.validation.ValidationParamsGenerator.doNext(ValidationParamsGenerator.java:31)
    at org.ldbcouncil.snb.driver.generator.Generator.hasNext(Generator.java:26)
    at org.ldbcouncil.snb.driver.validation.ValidationParamsToCsvRows.hasNext(ValidationParamsToCsvRows.java:36)
    at org.ldbcouncil.snb.driver.client.CreateValidationParamsMode.startExecutionAndAwaitCompletion(CreateValidationParamsMode.java:163)
    at org.ldbcouncil.snb.driver.Client.main(Client.java:65)
Caused by: [groovy.lang.MissingPropertyException]

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

schema结构:
schema.propertyKey("creationDate").asLong().ifNotExist().create();
schema.propertyKey("id").asLong().ifNotExist().create();
schema.propertyKey("locationIP").asText().ifNotExist().create();
schema.propertyKey("browserUsed").asText().ifNotExist().create();
schema.propertyKey("content").asText().ifNotExist().create();
schema.propertyKey("length").asInt().ifNotExist().create();
//schema.propertyKey("CreatorPersonId").asLong().ifNotExist().create();
//schema.propertyKey("LocationCountryId").asLong().ifNotExist().create();
//schema.propertyKey("ParentPostId").asLong().ifNotExist().create();
//schema.propertyKey("ParentCommentId").asLong().ifNotExist().create();
// Forum
schema.propertyKey("title").asText().ifNotExist().create();
//schema.propertyKey("ModeratorPersonId").asLong().ifNotExist().create();
// Person
schema.propertyKey("firstName").asText().ifNotExist().create();
schema.propertyKey("lastName").asText().ifNotExist().create();
schema.propertyKey("gender").asText().ifNotExist().create();
schema.propertyKey("birthday").asLong().ifNotExist().create();
schema.propertyKey("language").asText().ifNotExist().create();
schema.propertyKey("LocationCityId").asLong().ifNotExist().create();
schema.propertyKey("email").asText().ifNotExist().create();
schema.propertyKey("classYear").asInt().ifNotExist().create();
schema.propertyKey("workFrom").asInt().ifNotExist().create();
// Post
schema.propertyKey("imageFile").asText().ifNotExist().create();
//schema.propertyKey("ContainerForumId").asLong().ifNotExist().create();
//Organisation
schema.propertyKey("type").asText().ifNotExist().create();
schema.propertyKey("name").asText().ifNotExist().create();
schema.propertyKey("url").asText().ifNotExist().create();
//Place
//schema.propertyKey("PartOfPlaceId").asInt().ifNotExist().create();
//Tag
//schema.propertyKey("TypeTagClassId").asInt().ifNotExist().create();
//TagClass
//schema.propertyKey("SubclassOfTagClassId").asInt().ifNotExist().create();
//edge_properties
schema.propertyKey("joinDate").asLong().ifNotExist().create();
schema.propertyKey("classYear").asInt().ifNotExist().create();
schema.propertyKey("workFrom").asInt().ifNotExist().create();

// vertex

schema.vertexLabel("Comment")
        .properties("id", "creationDate", "locationIP", "browserUsed", "content", "length")
        .nullableKeys("creationDate", "locationIP", "browserUsed", "content", "length")
        .primaryKeys("id")
        .ifNotExist()
        .create();

schema.vertexLabel("Forum")
        .properties("id", "title", "creationDate")
        .nullableKeys("title", "creationDate")
        .primaryKeys("id")
        .ifNotExist()
        .create();

schema.vertexLabel("Person")
        .properties("id", "firstName", "lastName", "gender", "birthday", "creationDate", "locationIP",
                "browserUsed", "language", "email")
        .nullableKeys("firstName", "lastName", "gender", "birthday", "creationDate", "locationIP",
                "browserUsed", "language", "email")
        .primaryKeys("id")
        .ifNotExist()
        .create();

schema.vertexLabel("Post")
        .properties("id", "imageFile", "creationDate", "locationIP", "browserUsed", "language", "content", "length")
        .nullableKeys("imageFile", "creationDate", "locationIP", "browserUsed", "language", "content", "length")
        .primaryKeys("id")
        .ifNotExist()
        .create();

schema.vertexLabel("Organisation")
        .properties("id", "type", "name", "url")
        .nullableKeys("type", "name", "url")
        .primaryKeys("id")
        .ifNotExist()
        .create();

schema.vertexLabel("Place")
        .properties("id", "name", "url", "type")
        .nullableKeys("name", "url", "type")
        .primaryKeys("id")
        .ifNotExist()
        .create();

schema.vertexLabel("Tag")
        .properties("id", "name", "url")
        .nullableKeys("name", "url")
        .primaryKeys("id")
        .ifNotExist()
        .create();

schema.vertexLabel("TagClass")
        .properties("id", "name", "url")
        .nullableKeys( "name", "url")
        .primaryKeys("id")
        .ifNotExist()
        .create();

// edge
schema.edgeLabel("Comment_hasCreator_Person")
        .sourceLabel("Comment")
        .targetLabel("Tag")
        .ifNotExist()
        .create();

schema.edgeLabel("Comment_hasTag_Tag")
        .sourceLabel("Comment")
        .targetLabel("Tag")
        .ifNotExist()
        .create();

schema.edgeLabel("Comment_isLocatedIn_Country")
        .sourceLabel("Comment")
        .targetLabel("Place")
        .ifNotExist()
        .create();

schema.edgeLabel("Comment_replyOf_Comment")
        .sourceLabel("Comment")
        .targetLabel("Comment")
        .ifNotExist()
        .create();

schema.edgeLabel("Comment_replyOf_Post")
        .sourceLabel("Comment")
        .targetLabel("Post")
        .ifNotExist()
        .create();

schema.edgeLabel("Forum_containerOf_Post")
        .sourceLabel("Forum")
        .targetLabel("Post")
        .ifNotExist()
        .create();

schema.edgeLabel("Forum_hasMember_Person")
        .sourceLabel("Forum")
        .targetLabel("Person")
        .properties("joinDate")
        .ifNotExist()
        .create();

schema.edgeLabel("Forum_hasModerator_Person")
        .sourceLabel("Forum")
        .targetLabel("Person")
        .ifNotExist()
        .create();

schema.edgeLabel("Forum_hasTag_Tag")
        .sourceLabel("Forum")
        .targetLabel("Tag")
        .ifNotExist()
        .create();

schema.edgeLabel("Person_hasInterest_Tag")
        .sourceLabel("Person")
        .targetLabel("Tag")
        .ifNotExist()
        .create();

schema.edgeLabel("Person_isLocatedIn_City")
        .sourceLabel("Person")
        .targetLabel("Place")
        .ifNotExist()
        .create();

schema.edgeLabel("Person_knows_Person")
        .sourceLabel("Person")
        .targetLabel("Person")
        .properties("creationDate")
        .ifNotExist()
        .create();

schema.edgeLabel("Person_likes_Comment")
        .sourceLabel("Person")
        .targetLabel("Comment")
        .properties("creationDate")
        .ifNotExist()
        .create();

schema.edgeLabel("Person_likes_Post")
        .sourceLabel("Person")
        .targetLabel("Post")
        .properties("creationDate")
        .ifNotExist()
        .create();

schema.edgeLabel("Person_studyAt_University")
        .sourceLabel("Person")
        .targetLabel("Organisation")
        .properties("classYear")
        .ifNotExist()
        .create();

schema.edgeLabel("Person_workAt_Company")
        .sourceLabel("Person")
        .targetLabel("Organisation")
        .properties("workFrom")
        .ifNotExist()
        .create();

schema.edgeLabel("Post_hasCreator_Person")
        .sourceLabel("Post")
        .targetLabel("Person")
        .ifNotExist()
        .create();

schema.edgeLabel("Post_hasTag_Tag")
        .sourceLabel("Post")
        .targetLabel("Tag")
        .ifNotExist()
        .create();

schema.edgeLabel("Post_isLocatedIn_Country")
        .sourceLabel("Post")
        .targetLabel("Place")
        .ifNotExist()
        .create();

schema.edgeLabel("Company_isLocatedIn_Country")
        .sourceLabel("Organisation")
        .targetLabel("Place")
        .ifNotExist()
        .create();

schema.edgeLabel("City_isPartOf_Country")
        .sourceLabel("Place")
        .targetLabel("Place")
        .ifNotExist()
        .create();

schema.edgeLabel("Tag_hasType_TagClass")
        .sourceLabel("Tag")
        .targetLabel("TagClass")
        .ifNotExist()
        .create();

schema.edgeLabel("TagClass_isSubclassOf_TagClass")
        .sourceLabel("TagClass")
        .targetLabel("TagClass")
        .ifNotExist()
        .create();
JackyYangPassion commented 1 year ago

There is a line

 .order().by(values, desc).by(keys, asc)

in the gremlin you provided. but there is no such attribute in the provided schema

Zony7 commented 1 year ago

There is a line

 .order().by(values, desc).by(keys, asc)

in the gremlin you provided. but there is no such attribute in the provided schema

In this statement I wrote, "values" and "keys" are attribute names used for sorting. In this context, they are extracted from the previous results, specifically corresponding to the key and value used in the

.groupCount().by("tag.name")`

step, rather than referring to specific properties in the schema statement.

A similar query that also makes use of "values" can function correctly, as shown below: image

result = g.V().has("Person","id",$personId).repeat(both("Person_knows_Person"))
          .emit().times(2)
          .dedup().has("id", neq($personId))
          .as("friends")
          .in("Post_hasCreator_Person")
          .where(
           __.out("Post_hasTag_Tag").has("name",$tagName)
           )
          .as("Post")
          .out("Post_hasTag_Tag")
          .has("name", neq($tagName))
          .as('Tag')
          .project("postId","tagName")
          .by(select("Post").values("id"))
          .by(select("Tag").values("name"))
          .dedup()
          .groupCount().by(select("tagName"))
          .unfold()
          .order().by(values, desc).by(keys, asc)
          .limit(10)
          .project("otherTag.name","postCount")
          .by(select(keys))
          .by(select(values))
result

So,I think it is not that problem,thank u

github-actions[bot] commented 1 year ago

Due to the lack of activity, the current issue is marked as stale and will be closed after 20 days, any update will remove the stale label

Drawlone commented 3 weeks ago

@Zony7 Did you solve this problem?