GafferPop Custom Functions
This page details each additional function that is available in the Gaffer Gremlin API (GafferPop). These functions may be exclusive to GafferPop so are likely not available in other databases that support the Gremlin query language.
All examples featured on this page assume the Tinkerpop modern dataset.
OpenCypher Extensions
The following are additional functions provided by the OpenCypher extensions for Gremlin.
cypherToString
Can be used to cast the input value to a String
type.
cypherToBoolean
Can be used to cast the input value to a Boolean
type. Will convert String
representations e.g. "true" or "false", otherwise return a Cypher null value.
Example
Result:
cypherToInteger
Can be used to cast the input value to an Integer
type. Note if value is
a Float
or Double
rounding may be applied.
cypherToFloat
Can be used to cast the input value to a Float
type.
cypherRound
Can be used to round numerical input values.
cypherProperties
Used to extract only the properties from the input Vertex
or Edge
.
Similar to running an elementMap()
or propertyMap()
step.
Example
Result:
cypherSize
Can be used to return the size of a Collection
or String
.
cypherPlus
Can be used to add two inputs together to act like the plus operator
in Cypher e.g. RETURN 1 + 2
.
Note this requires a slightly more complex input of pair list e.g. [1, 2]
to
use in a Gremlin query. The example below uses a project()
step to pair each
'age' with the constant 1
so that each age is incremented by 1 in the result.
Example
g.V().hasLabel('person')
.project('result')
.by(__.project('a', 'b')
.by(__.values('age'))
.by(__.constant(1))
.select(values)
.map(cypherPlus()))
Result:
cypherReverse
Can be used to reverse a Collection
or String
.
Example
Result:
cypherSubstring
Can be used to extract a substring from the result by using indexes for start and/or end point of the string.
Note requires complex input pairs by using the project step for the input string
and index. The example below cuts the first two chars off the start of the
name
.
Example
cypherTrim
Can be used to run a trim()
on a given string input, basically all leading and trailing whitespace is
removed.
Example
Result:
cypherToUpper
Can be used to uppercase the input string.
Example
Result:
cypherToLower
Can be used to lowercase the input string.
Example
Result:
cypherSplit
Can be used to split an input string based on a given character.
Note requires complex input pairs by using the project step for the input string
and split character. The example below splits on an e
.