在 Bluemix Graph DB 中使用集合 属性 创建顶点的正确方法是什么?

What is the proper way to create a vertex with a set property in Bluemix Graph DB?

我正在尝试在 Bluemix Graph DB 服务中创建一个新顶点。我的数据库的架构如下。

{"propertyKeys":[{"name":"name","dataType":"String","cardinality":"SINGLE"},{"name":"languages","dataType":"String","cardinality":"SET"},{"name":"picture","dataType":"String","cardinality":"SINGLE"},{"name":"preferred_language","dataType":"String","cardinality":"SINGLE"},{"name":"bytes","dataType":"Integer","cardinality":"SINGLE"},{"name":"github_id","dataType":"String","cardinality":"SINGLE"},{"name":"twitter_id","dataType":"String","cardinality":"SINGLE"},{"name":"language_percentage","dataType":"Float","cardinality":"SINGLE"}],"vertexLabels":[{"name":"person"},{"name":"language"}],"edgeLabels":[{"name":"codes_in","multiplicity":"MULTI"},{"name":"used_by","multiplicity":"MULTI"}],"vertexIndexes":[{"name":"vByName","propertyKeys":["name"],"composite":true,"unique":false},{"name":"vByPreferredLang","propertyKeys":["preferred_language"],"composite":true,"unique":false},{"name":"vByLanguages","propertyKeys":["languages"],"composite":false,"unique":false}],"edgeIndexes":[{"name":"eByName","propertyKeys":["name"],"composite":true,"unique":false},{"name":"eByLanguagePercentage","propertyKeys":["language_percentage"],"composite":true,"unique":false}]} 我正在尝试使用以下 POST body

创建顶点

{"name":"Bob","languages":["Node","Python"],"picture":"https://en.gravatar.com/userimage/12148147/46ccae88e5aae747d53e0b1863f72a4e.jpg?size=200","preferred_language":"Node","github_id":"Bob","twitter_id":"Bob"}

但是这会导致以下错误

{"code":"BadRequestError","message":"Property 'languages' with meta properties need to have a 'val'"}

语言 属性 的基数为 SET,为 SET 数据类型创建 属性 的正确方法是什么?我会假设它是一个 JSON 数组。

Ryan,SET 不是数据类型。您还可以使语言成为具有分隔值的字符串。

Beta 版本中唯一支持的类型是:String、Integer、Boolean、Float

问题是您正在尝试创建数据类型为 List<String> 的单个顶点 属性,这在 IBM Graph 中不受支持(仅 JSON-primitive支持类型)。要利用具有 SET 数据类型的 属性,您需要创建多个顶点属性。

事实证明,TinkerPop 中基数和数据类型之间的区别可能有点令人困惑。这是一个应该澄清事情的例子:

$ curl https://ibmgraph/11/g/schema -XPOST -Hcontent-type:application/json -d '{"propertyKeys":[{"name":"languages","dataType":"String","cardinality":"SET"}]}' | jq .
{
  "requestId": "9e0ea947-f9a1-407b-ab1a-cd9b7fd5d561",
  "status": {
    "message": "",
    "code": 200,
    "attributes": {}
  },
  "result": {
    "data": [
      {
        "propertyKeys": [
          {
            "name": "languages",
            "dataType": "String",
            "cardinality": "SET"
          }
        ],
        "vertexLabels": [],
        "edgeLabels": [],
        "vertexIndexes": [],
        "edgeIndexes": []
      }
    ],
    "meta": {}
  }
}
$ curl https://ibmgraph/11/g/vertices -XPOST | jq .
{
  "requestId": "2ce85907-2aca-4630-876f-31775e74e1de",
  "status": {
    "message": "",
    "code": 200,
    "attributes": {}
  },
  "result": {
    "data": [
      {
        "id": 4112,
        "label": "vertex",
        "type": "vertex",
        "properties": {}
      }
    ],
    "meta": {}
  }
}
$ curl https://ibmgraph/11/g/vertices/4112 -XPOST -Hcontent-type:application/json -d '{"languages":"Node"}' | jq .
{
  "requestId": "52ad6d49-46c9-41aa-9928-5a567099d773",
  "status": {
    "message": "",
    "code": 200,
    "attributes": {}
  },
  "result": {
    "data": [
      {
        "id": 4112,
        "label": "vertex",
        "type": "vertex",
        "properties": {
          "languages": [
            {
              "id": "si-368-sl",
              "value": "Node"
            }
          ]
        }
      }
    ],
    "meta": {}
  }
}
$ curl https://ibmgraph/11/g/vertices/4112 -XPOST -Hcontent-type:application/json -d '{"languages":"Python"}' | jq .
{
  "requestId": "19886949-6328-4e19-8cac-8fdab37ef2a5",
  "status": {
    "message": "",
    "code": 200,
    "attributes": {}
  },
  "result": {
    "data": [
      {
        "id": 4112,
        "label": "vertex",
        "type": "vertex",
        "properties": {
          "languages": [
            {
              "id": "si-368-sl",
              "value": "Node"
            },
            {
              "id": "16q-368-sl",
              "value": "Python"
            }
          ]
        }
      }
    ],
    "meta": {}
  }
}