dosubot[bot] commented on issue #2777: URL: https://github.com/apache/incubator-hugegraph/issues/2777#issuecomment-2908994607
<!-- Answer --> 有,官方文档中有完整的 Groovy 脚本案例,演示了如何用 PrimaryKey(主键属性)直接绑定主键值来创建顶点和边。核心流程如下: 1. 定义属性和 schema(顶点主键、边类型): ```groovy // 定义属性 schema.propertyKey("name").asText().ifNotExist().create(); schema.propertyKey("age").asInt().ifNotExist().create(); schema.propertyKey("city").asText().ifNotExist().create(); schema.propertyKey("price").asDouble().ifNotExist().create(); // 定义 person 顶点,主键为 name schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").ifNotExist().create(); // 定义 software 顶点,主键为 name schema.vertexLabel("software").properties("name", "price").primaryKeys("name").ifNotExist().create(); // 定义边类型 schema.edgeLabel("knows").sourceLabel("person").targetLabel("person").ifNotExist().create(); schema.edgeLabel("created").sourceLabel("person").targetLabel("software").ifNotExist().create(); ``` 2. 插入数据(直接用主键值作为唯一标识,无需显式指定顶点 ID): ```groovy // 插入 person 顶点 graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city", "Beijing"); graph.addVertex(T.label, "person", "name", "vadas", "age", 27, "city", "Hongkong"); // 插入 software 顶点 graph.addVertex(T.label, "software", "name", "lop", "price", 328.0); // 创建边,直接用主键值绑定 graph.addEdge(T.label, "knows", T.source, "marko", T.target, "vadas"); graph.addEdge(T.label, "created", T.source, "marko", T.target, "lop"); ``` 只要 schema 里顶点主键设置正确,创建边时直接用主键值即可,HugeGraph 会自动根据 VertexLabel + PrimaryKeyValues 生成顶点 ID 并完成边的绑定,无需手动指定 ID。 详细案例和说明可参考官方文档:[HugeGraph Loader 快速入门](https://github.com/apache/incubator-hugegraph-doc/blob/master/content/en/docs/quickstart/hugegraph-loader.md)(案例在“schema.groovy”部分)【[引用1](https://github.com/apache/incubator-hugegraph-doc/blob/master/content/en/docs/quickstart/hugegraph-loader.md)】。 如需更复杂的 schema 或多主键场景,也可以用同样方式扩展。 <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://go.dosu.dev/dosubot), mention @dosu-bot.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/758200af-1ceb-492d-9149-7b87b9f4fabc?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/758200af-1ceb-492d-9149-7b87b9f4fabc?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/758200af-1ceb-492d-9149-7b87b9f4fabc?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/758200af-1ceb-492d-9149-7b87b9f4fabc?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/758200af-1ceb-492d-9149-7b87b9f4fabc?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/758200af-1ceb-492d-9149-7b87b9f4fabc?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/758200af-1ceb-492d-9149-7b87b9f4fabc?feedback_type=other)</sup> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@hugegraph.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@hugegraph.apache.org For additional commands, e-mail: issues-h...@hugegraph.apache.org