incubator-hugegraph icon indicating copy to clipboard operation
incubator-hugegraph copied to clipboard

请问HugeGraph的Edge的sortkey是怎么使用的

Open xu0612204126 opened this issue 7 years ago • 5 comments

1.下载最新的hugeGraph版本 2.创建了strutct.json 格式如下 { "vertices": [ { "label": "person2", "input": { "type": "file", "path": "testDataHchl/hchl.csv", "format": "CSV", "header": ["sourceName", "name","stakeId","stakeName", "time"], "charset": "UTF-8" }, "mapping": { "sourceName": "vertexId", "name": "name" }, "ignored": ["stakeId","time","stakeName"] }, { "label": "stake", "input": { "type": "file", "path": "testDataHchl/hchl.csv", "format": "CSV", "header": ["sourceName", "name","stakeId","stakeName", "time"], "charset": "UTF-8" }, "mapping": { "stakeId": "stakeId", "stakeName": "stakeName" }, "ignored": ["sourceName", "name","time"] } ], "edges": [ { "label": "hchl", "source": ["sourceName"], "target": ["stakeId"], "sortKey":["time"], "input": { "type": "file", "path": "testDataHchl/hchl.csv", "header": ["sourceName", "name","stakeId","stakeName", "time"], "format": "CSV" }, "mapping": { "sourceName": "vertexId", "stakeId": "stakeId" }, "ignored": [ "name","stakeName"] } ] } 其中hchl.csv 数据如下: sourceName,name,stakeId,stakeName,time 5898565665223333331,李四,1,点1,2019/1/1 371425198903069885,张三,2,点2,2012/3/9 589856566522333333,李四,3,点3,1909/1/9 454545454545454545,张三,1,点1,2019/8/1 454545454545454545,张三,1,点1,2019/1/1 3.导入数据之后,454545454545454545 和 点1之间,只有一条边,实际数据是应该两条边的 ,请问怎么做可以实现 A 点和B点之间,同一种类型的边,但是属性不一样的,可以不被覆盖。

xu0612204126 avatar Jan 22 '19 09:01 xu0612204126

建议在写 issue 的时候用 markdown 把代码包裹起来,方便大家阅读,如下面所示:

print("Hello world!")

关于 sortKeys,其含义正是用来区分你的例子中的情况,点1和点454545454545454545之间有2条边,除了日期不同,其他属性都相同,那么如果你希望这是两条边,就需要把日期这个属性加入到 EdgeLabel 的定义中,即:

... .sortKeys("time").ifNotExist().create();

官方文档上面也有例子说明。

Best,

suesunss avatar Jan 22 '19 16:01 suesunss

我的struct.groovy的代码如下,使用graphLoader导入的数据,导入的时候报错,不明白这是什么意思? Caused by: class java.lang.IllegalArgumentException: EdgeLabel can't contain sortKeys when the cardinality property is single at com.baidu.hugegraph.exception.ServerException.fromResponse(ServerException.java:44) at com.baidu.hugegraph.client.RestClient.checkStatus(RestClient.java:63) at com.baidu.hugegraph.rest.RestClient.post(RestClient.java:119) at com.baidu.hugegraph.rest.RestClient.post(RestClient.java:79) at com.baidu.hugegraph.rest.RestClient.post(RestClient.java:74) at com.baidu.hugegraph.api.schema.EdgeLabelAPI.create(EdgeLabelAPI.java:44) at com.baidu.hugegraph.driver.SchemaManager.addEdgeLabel(SchemaManager.java:137) at com.baidu.hugegraph.structure.schema.EdgeLabel$BuilderImpl.create(EdgeLabel.java:123) at com.baidu.hugegraph.structure.schema.EdgeLabel$BuilderImpl.create(EdgeLabel.java:106) ... 15 more

struct.groovy的代码::

`schema.propertyKey("name").asText().ifNotExist().create(); schema.propertyKey("sfzh2").asText().ifNotExist().create(); schema.propertyKey("stakeId").asText().ifNotExist().create(); schema.propertyKey("stakeName").asText().ifNotExist().create();

schema.propertyKey("sourceName").asText().ifNotExist().create(); schema.propertyKey("targetName").asText().ifNotExist().create(); schema.propertyKey("time").asText().ifNotExist().create(); schema.vertexLabel("person2").properties("name", "sfzh2").primaryKeys("sfzh2").ifNotExist().create(); schema.vertexLabel("stake").properties("stakeId","stakeName").primaryKeys("stakeId").ifNotExist().create();

schema.indexLabel("personByName").onV("person2").by("name").secondary().ifNotExist().create();

schema.indexLabel("stakeByName").onV("stake").by("stakeName").ifNotExist().create();

schema.edgeLabel("hchl").sourceLabel("person2").targetLabel("stake").sortKeys("time").properties("time").ifNotExist().create();

schema.indexLabel("hchlByDate").onE("hchl").by("time").secondary().ifNotExist().create();`

xu0612204126 avatar Jan 23 '19 03:01 xu0612204126

sorry,我找到原因了,应该是 schema.edgeLabel("hchl").multiTimes().sourceLabel("person2").targetLabel("stake").sortKeys("time").properties("time").ifNotExist().create(); 这么写才对。

xu0612204126 avatar Jan 23 '19 03:01 xu0612204126

@xu0612204126 是的,我遗漏了 multiTimes()。

suesunss avatar Jan 23 '19 08:01 suesunss

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

github-actions[bot] avatar Jan 23 '22 21:01 github-actions[bot]