Ryan Baxter
Ryan Baxter

Reputation: 1257

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

I am trying to create a new vertex in the Bluemix Graph DB service. The schema of my DB is as follows.

{"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}]} I am trying to create the vertex with the following 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"}

However this results in the following error

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

The languages property has a cardinality of SET, what is the right way to create a property for a SET dataType? I would have assumed it was a JSON array.

Upvotes: 1

Views: 126

Answers (2)

Alaa Mahmoud
Alaa Mahmoud

Reputation: 743

Ryan, SET isn't a data type. You could also make languages a string with delimited values.

The only types that are supported in the Beta release are : String,Integer,Boolean,Float

Upvotes: 2

Benjamin Anderson
Benjamin Anderson

Reputation: 334

The issue is that you're attempting to create a single vertex property with a data type of List<String>, which is not supported in IBM Graph (only JSON-primitive types are supported). To take advantage of a property with a SET data type you'll need to create multiple vertex properties.

It turns out that the distinction between cardinalities and data types in TinkerPop can be a bit of a confusing. Here's an example that should clarify things:

$ 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": {}
  }
}

Upvotes: 2

Related Questions