Property Data Types

spmallette edited this page Apr 7, 2013 · 21 revisions

Rexster allows manipulation of property values on Vertex and Edge objects (i.e. Element objects). By default, these values are assumed to be string data types, but the Rexster API allows the the following data types to be set and allows for a calling client to get any results with their associated data types for proper deserialization.

Rexster supports the following data types:

  • String
  • Boolean
  • Integer
  • Long
  • Float
  • Double
  • List
  • Map

Serialization of graph elements to JSON is handled by the Blueprints GraphSONUtility.

Getting Results with Data Types

Getting results with data types attached is accomplished by adding the application/vnd.rexster-typed+json mime type to the accept header on the request.

curl -v -H "Accept:application/vnd.rexster.typed+json" http://localhost:8182/graphs/gratefulgraph/vertices/337
{
    "version": "*.*",
    "results": {
        "_type": "vertex",
        "_id": {
            "type": "string",
            "value": "337"
        },
        "keystring": {
            "type": "string",
            "value": "123"
        },
        "keymap": {
            "type": "map",
            "value": {
                "propertyb": {
                    "type": "integer",
                    "value": 321
                },
                "propertya": {
                    "type": "integer",
                    "value": 123
                }
            }
        },
        "name": {
            "type": "string",
            "value": "CHINESE BONES"
        },
        "song_type": {
            "type": "string",
            "value": "cover"
        },
        "performances": {
            "type": "integer",
            "value": 1
        },
        "keylist": {
            "type": "list",
            "value": [
                {
                    "type": "integer",
                    "value": 100
                },
                {
                    "type": "integer",
                    "value": 200
                },
                {
                    "type": "string",
                    "value": "(i,300"
                }
            ]
        },
        "type": {
            "type": "string",
            "value": "song"
        },
        "keytyped": {
            "type": "integer",
            "value": 123
        }
    },
    "queryTime": 1.092324
}

Set Properties With Data Types

By default, properties set on the URI are stored as strings. Even values that could be coerced to a different data type will be stored as a string.

http://localhost:8182/graphs/gratefulgraph/vertices/337?keyinteger=123&keystring=xyz

Both properties, keyinteger and keystring will be stored as strings even though keyinteger could be coerced to an integer value. To get Rexster to store the value using a specific data type that data type must be specified as the value in the key-value pair using the following format: (type,value).

http://localhost:8182/graphs/gratefulgraph/vertices/337?keyinteger=(integer,123)&keystring=xyz

Primitive Data Types

All values set without a data type will be defaulted to strings. If a data type is set and it does not match one of the allowable types, Rexster will assume a string value. If a data type is set and the value itself cannot be coerced to that type, Rexster will assume a string.

An integer may be specified using integer or i as the data type.

http://localhost:8182/graphs/gratefulgraph/vertices/337?x=(integer,123)&y=(i,123)

A long may be specified using long or l as the data type.

http://localhost:8182/graphs/gratefulgraph/vertices/337?x=(long,123)&y=(l,123)

A float may be specified using float or f as the data type.

http://localhost:8182/graphs/gratefulgraph/vertices/337?x=(float,123)&y=(f,123)

A double may be specified using double or d as the data type.

http://localhost:8182/graphs/gratefulgraph/vertices/337?x=(double,123)&y=(d,123)

A boolean may be specified using boolean or b as the data type.

http://localhost:8182/graphs/gratefulgraph/vertices/337?x=(boolean,true)&y=(d,true)

List Data Type

A list will store an array of objects. The objects may be all of the same data type or a mixture of different data types. Lists are defined on the URI using the list keyword and is followed by a parentheses enclosed, comma separated list of values. The values are defined in the same way that primitives are defined using the (type,value).

http://localhost:8182/graphs/gratefulgraph/vertices/337?keylist=(list,((i,100),(i,200),(i,300)))
http://localhost:8182/graphs/gratefulgraph/vertices/337?keylist=(list,((i,100),200,(d,300.5)))

Map Data Type

A map allows the storing of a key-value pair set within a property. Maps are defined on the URI using the map keyword and is followed by a key-value pair. The key is the name of the property on the map and the value is a (type,value) setting.

http://localhost:8182/graphs/gratefulgraph/vertices/337?keymap=(map,(propertya=(i,123),propertyb=(d,321.5)))

Embedded Lists and Maps

Maps and lists can embed other maps and lists within them to virtually any depth required.

http://localhost:818/graphs2/gratefulgraph/vertices/337?keylist=(list,((i,100),(i,200),(i,300),(list,(x,y,z)))
http://localhost:8182/graphs/gratefulgraph/vertices/337?keymap=(map,(propertya=(i,123),propertyb=(d,321.5),propertyc=(list,(x,y,z)),propertyd=(map,(x=xyz))))