This chapter explains the complete reference of different types of functions in OrientDB. The following table defines the list of functions, which are categorized by their functionality.
Graph Functions
Sr.No.
Function Name & Description
1
Out():
Gets the adjacent outgoing vertices starting from the current record as Vertex.
Syntax − out([<label-1>][,<label-n>]*)
2
In():
Gets the adjacent incoming vertices starting from the current record as Vertex.
Syntax − in([<label-1>][,<label-n>]*)
3
Both():
Gets the adjacent outgoing and incoming vertices starting from the current record as Vertex.
Syntax − both([<label1>][,<label-n>]*)
4
outE():
Gets the adjacent outgoing edges starting from the current record as Vertex.
Syntax − outE([<label1>][,<label-n>]*)
5
inE():
Gets the adjacent incoming edges starting from the current record as Vertex.
Syntax − inE([<label1>][,<label-n>]*)
6
bothE():
Gets the adjacent outgoing and incoming edges starting from the current record as Vertex.
Syntax − bothE([<label1>][,<label-n>]*)
7
outV():
Gets the outgoing vertices starting from the current record as Edge.
Syntax − outV()
8
inV():
Get the incoming vertices from the current record as Edge.
Syntax − inV()
9
traversedElement():
Returns the traversed element(s) in Traverse commands.
Syntax − traversedElement(<index> [,<items>])
10
traversedVertex():
Return the traversed vertex(es) in Traverse commands.
Syntax − traversedVertex(<index> [,<items>])
11
traversedEdge():
Returns the traversed edge(s) in Traverse commands.
Syntax − traversedEdge(<index> [,<items>])
12
shortestPath():
Returns the shortest path between two vertices. Direction can be OUT (default), IN or BOTH.
Adds a value to a set. If the value is a collection, then it is merged with the set, otherwise <value> is added.
Syntax − set(<field>)
2
map():
Adds a value to a map the first time the map is created. If <value> is a map, then it is merged with the map, otherwise the pair <key> and <value> is added to map as new entry.
Syntax − map(<key>, <value>)
3
ist():
Adds a value to list the first time the list is created. If <value> is a collection, then it is merged with the list, otherwise <value> is added to list.
Syntax − list(<field>)
4
difference():
Works as aggregate or inline. If only one argument is passed then aggregates, otherwise executes, and returns the DIFFERENCE between the collections received as parameters.
Syntax − difference(<field> [,<field-n>]*)
5
first():
Retrieves only the first item of multi-value fields (arrays, collections and maps). For non-multi-value types just returns the value.
Syntax − first(<field>)
6
intersect():
Works as aggregate or inline. If only one argument is passed then aggregates, otherwise executes, and returns, the INTERACTION of the collections received as parameters.
Syntax − intersect(<field> [,<field-n>]*)
7
distinct():
Retrieves only unique data entries depending on the field you have specified as argument. The main difference compared to standard SQL DISTINCT is that with OrientDB, a function with parenthesis and only one field can be specified.
Syntax − distinct(<field>)
8
expand():
This function has two meanings−
When used on a collection field, it unwinds the collection in the field and uses it as result.
When used on a link (RID) field, it expands the document pointed by that link.
Syntax − expand(<field>)
9
unionall():
Works as aggregate or inline. If only one argument is passed then aggregates, otherwise executes and returns a UNION of all the collections received as parameters. Also works with no collection values.
Syntax − unionall(<field> [,<field-n>]*)
10
flatten():
Extracts the collection in the field and uses it as result. It is deprecated, use expand() instead.
Syntax − flatten(<field>)
11
last():
Retrieves only the last item of multi-value fields (arrays, collections and maps). For non-multi-value types just returns the value.
Syntax − last(<field>)
12
symmetricDifference():
Works as aggregate or inline. If only one argument is passed then aggregates, otherwise executes, and returns, the SYMMETRIC DIFFERENCE between the collections received as parameters.
Try some Misc functions using the following queries.
Execute the following query to learn how to execute if expression.
orientdb {db = demo}> SELECT if(eval("name = 'satish'"), "My name is satish",
"My name is not satish") FROM Employee
If the above query is executed successfully, you will get the following output.
----+--------+-----------------------
# |@CLASS | IF
----+--------+-----------------------
0 |null |My name is satish
1 |null |My name is not satish
2 |null |My name is not satish
3 |null |My name is not satish
4 |null |My name is not satish
----+--------+------------------------
Execute the following query to get system date.
orientdb {db = demo}> SELECT SYSDATE() FROM Employee
If the above query is executed successfully, you will get the following output.