1

我正在尝试在 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 正文创建顶点

{"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 数组。

4

2 回答 2

2

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

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

于 2016-03-16T14:01:18.800 回答
2

问题是您正在尝试创建数据类型为 的单个顶点属性,List<String>IBM Graph 不支持该属性(仅支持 JSON 基元类型)。要利用具有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": {}
  }
}
于 2016-03-16T17:35:07.247 回答