mirror of https://gitee.com/bigwinds/arangodb
slightly improved AQL documentation
Conflicts: Documentation/UserManual/Aql.md
This commit is contained in:
parent
a1dc22e11b
commit
87284a47f9
|
@ -1154,14 +1154,14 @@ AQL supports the following functions to operate on list values:
|
||||||
@LIT{UNION_DISTINCT} function or apply the @LIT{UNIQUE} on the result of @LIT{union}.
|
@LIT{UNION_DISTINCT} function or apply the @LIT{UNIQUE} on the result of @LIT{union}.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
RETURN UNION(
|
RETURN UNION(
|
||||||
[ 1, 2, 3 ],
|
[ 1, 2, 3 ],
|
||||||
[ 1, 2 ]
|
[ 1, 2 ]
|
||||||
)
|
)
|
||||||
|
|
||||||
will produce:
|
will produce:
|
||||||
|
|
||||||
[ [ 1, 2, 3, 1, 2 ] ]
|
[ [ 1, 2, 3, 1, 2 ] ]
|
||||||
|
|
||||||
with duplicate removal:
|
with duplicate removal:
|
||||||
|
@ -1174,7 +1174,7 @@ AQL supports the following functions to operate on list values:
|
||||||
)
|
)
|
||||||
|
|
||||||
will produce:
|
will produce:
|
||||||
|
|
||||||
[ [ 1, 2, 3 ] ]
|
[ [ 1, 2, 3 ] ]
|
||||||
|
|
||||||
- @FN{UNION_DISTINCT(@FA{list1, list2, ...})}: returns the union of distinct values of
|
- @FN{UNION_DISTINCT(@FA{list1, list2, ...})}: returns the union of distinct values of
|
||||||
|
@ -1219,11 +1219,12 @@ AQL supports the following functions to operate on document values:
|
||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
|
|
||||||
RETURN MATCHES({ "test" : 1 }, [
|
RETURN MATCHES(
|
||||||
{ "test" : 1, "foo" : "bar" },
|
{ "test" : 1 }, [
|
||||||
{ "foo" : 1 },
|
{ "test" : 1, "foo" : "bar" },
|
||||||
{ "test : 1 }
|
{ "foo" : 1 },
|
||||||
], true)
|
{ "test : 1 }
|
||||||
|
], true)
|
||||||
|
|
||||||
This will return `2`, because the third example matches, and because the
|
This will return `2`, because the third example matches, and because the
|
||||||
`return-index` flag is set to `true`.
|
`return-index` flag is set to `true`.
|
||||||
|
@ -1235,21 +1236,27 @@ AQL supports the following functions to operate on document values:
|
||||||
|
|
||||||
For example, two documents with distinct attribute names can easily be merged into one:
|
For example, two documents with distinct attribute names can easily be merged into one:
|
||||||
|
|
||||||
RETURN MERGE(
|
RETURN MERGE(
|
||||||
{ "user1" : { "name" : "J" } },
|
{ "user1" : { "name" : "J" } },
|
||||||
{ "user2" : { "name" : "T" } }
|
{ "user2" : { "name" : "T" } }
|
||||||
)
|
)
|
||||||
[ { "user1" : { "name" : "J" },
|
|
||||||
"user2" : { "name" : "T" } } ]
|
[
|
||||||
|
{ "user1" : { "name" : "J" },
|
||||||
|
"user2" : { "name" : "T" } }
|
||||||
|
]
|
||||||
|
|
||||||
When merging documents with identical attribute names, the attribute values of the
|
When merging documents with identical attribute names, the attribute values of the
|
||||||
latter documents will be used in the end result:
|
latter documents will be used in the end result:
|
||||||
|
|
||||||
return MERGE(
|
RETURN MERGE(
|
||||||
{ "users" : { "name" : "J" } },
|
{ "users" : { "name" : "J" } },
|
||||||
{ "users" : { "name" : "T" } }
|
{ "users" : { "name" : "T" } }
|
||||||
)
|
)
|
||||||
[ { "users" : { "name" : "T" } } ]
|
|
||||||
|
[
|
||||||
|
{ "users" : { "name" : "T" } }
|
||||||
|
]
|
||||||
|
|
||||||
Please note that merging will only be done for top-level attributes. If you wish to
|
Please note that merging will only be done for top-level attributes. If you wish to
|
||||||
merge sub-attributes, you should consider using `MERGE_RECURSIVE` instead.
|
merge sub-attributes, you should consider using `MERGE_RECURSIVE` instead.
|
||||||
|
@ -1261,11 +1268,14 @@ AQL supports the following functions to operate on document values:
|
||||||
|
|
||||||
For example, two documents with distinct attribute names can easily be merged into one:
|
For example, two documents with distinct attribute names can easily be merged into one:
|
||||||
|
|
||||||
RETURN MERGE_RECURSIVE(
|
RETURN MERGE_RECURSIVE(
|
||||||
{ "user-1" : { "name" : "J", "livesIn" : { "city" : "LA" } } },
|
{ "user-1" : { "name" : "J", "livesIn" : { "city" : "LA" } } },
|
||||||
{ "user-1" : { "age" : 42, "livesIn" : { "state" : "CA" } } }
|
{ "user-1" : { "age" : 42, "livesIn" : { "state" : "CA" } } }
|
||||||
)
|
)
|
||||||
[ { "user-1" : { "name" : "J", "livesIn" : { "city" : "LA", "state" : "CA" }, "age" : 42 } } ]
|
|
||||||
|
[
|
||||||
|
{ "user-1" : { "name" : "J", "livesIn" : { "city" : "LA", "state" : "CA" }, "age" : 42 } }
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
- @FN{HAS(@FA{document}, @FA{attributename})}: returns `true` if @FA{document} has an
|
- @FN{HAS(@FA{document}, @FA{attributename})}: returns `true` if @FA{document} has an
|
||||||
|
@ -1282,14 +1292,14 @@ AQL supports the following functions to operate on document values:
|
||||||
Multiple attribute names can be specified by either passing multiple individual string argument
|
Multiple attribute names can be specified by either passing multiple individual string argument
|
||||||
names, or by passing a list of attribute names:
|
names, or by passing a list of attribute names:
|
||||||
|
|
||||||
RETURN UNSET(doc, '_id', '_key', [ 'foo', 'bar' ])
|
RETURN UNSET(doc, '_id', '_key', [ 'foo', 'bar' ])
|
||||||
|
|
||||||
- @FN{KEEP(@FA{document}, @FA{attributename}, ...)}: keeps only the attributes @FA{attributename}
|
- @FN{KEEP(@FA{document}, @FA{attributename}, ...)}: keeps only the attributes @FA{attributename}
|
||||||
(can be one or many) from @FA{document}. All other attributes will be removed from the result.
|
(can be one or many) from @FA{document}. All other attributes will be removed from the result.
|
||||||
Multiple attribute names can be specified by either passing multiple individual string argument
|
Multiple attribute names can be specified by either passing multiple individual string argument
|
||||||
names, or by passing a list of attribute names:
|
names, or by passing a list of attribute names:
|
||||||
|
|
||||||
RETURN KEEP(doc, 'firstname', 'name', 'likes')
|
RETURN KEEP(doc, 'firstname', 'name', 'likes')
|
||||||
|
|
||||||
- @FN{PARSE_IDENTIFIER(@FA{document-handle})}: parses the document handle specified in
|
- @FN{PARSE_IDENTIFIER(@FA{document-handle})}: parses the document handle specified in
|
||||||
@FA{document-handle} and returns a the handle's individual parts a separate attributes.
|
@FA{document-handle} and returns a the handle's individual parts a separate attributes.
|
||||||
|
@ -1298,11 +1308,17 @@ AQL supports the following functions to operate on document values:
|
||||||
identifier string (e.g. `_users/1234`). Passing either a non-string or a non-document or a
|
identifier string (e.g. `_users/1234`). Passing either a non-string or a non-document or a
|
||||||
document without an `_id` attribute will result in an error.
|
document without an `_id` attribute will result in an error.
|
||||||
|
|
||||||
RETURN PARSE_IDENTIFIER('_users/my-user')
|
RETURN PARSE_IDENTIFIER('_users/my-user')
|
||||||
[ { "collection" : "_users", "key" : "my-user" } ]
|
|
||||||
|
|
||||||
RETURN PARSE_IDENTIFIER({ "_id" : "mycollection/mykey", "value" : "some value" })
|
[
|
||||||
[ { "collection" : "mycollection", "key" : "mykey" } ]
|
{ "collection" : "_users", "key" : "my-user" }
|
||||||
|
]
|
||||||
|
|
||||||
|
RETURN PARSE_IDENTIFIER({ "_id" : "mycollection/mykey", "value" : "some value" })
|
||||||
|
|
||||||
|
[
|
||||||
|
{ "collection" : "mycollection", "key" : "mykey" }
|
||||||
|
]
|
||||||
|
|
||||||
@subsubsection AqlFunctionsGeo Geo functions
|
@subsubsection AqlFunctionsGeo Geo functions
|
||||||
|
|
||||||
|
@ -1411,13 +1427,13 @@ AQL has the following functions to traverse graphs:
|
||||||
- `source`: start vertex of path
|
- `source`: start vertex of path
|
||||||
- `destination`: destination vertex of path
|
- `destination`: destination vertex of path
|
||||||
|
|
||||||
Example calls:
|
Example calls:
|
||||||
|
|
||||||
PATHS(friends, friendrelations, "outbound", false)
|
PATHS(friends, friendrelations, "outbound", false)
|
||||||
|
|
||||||
FOR p IN PATHS(friends, friendrelations, "outbound")
|
FOR p IN PATHS(friends, friendrelations, "outbound")
|
||||||
FILTER p.source._id == "123456/123456" && LENGTH(p.edges) == 2
|
FILTER p.source._id == "123456/123456" && LENGTH(p.edges) == 2
|
||||||
RETURN p.vertices[*].name
|
RETURN p.vertices[*].name
|
||||||
|
|
||||||
- @FN{TRAVERSAL(@FA{vertexcollection}, @FA{edgecollection}, @FA{startVertex}, @FA{direction}, @FA{options})}:
|
- @FN{TRAVERSAL(@FA{vertexcollection}, @FA{edgecollection}, @FA{startVertex}, @FA{direction}, @FA{options})}:
|
||||||
traverses the graph described by @FA{vertexcollection} and @FA{edgecollection},
|
traverses the graph described by @FA{vertexcollection} and @FA{edgecollection},
|
||||||
|
@ -1505,55 +1521,55 @@ Example calls:
|
||||||
attributes `vertices` and `edges`, which are both lists. Note that `path` is only present
|
attributes `vertices` and `edges`, which are both lists. Note that `path` is only present
|
||||||
in the result if the `paths` attribute is set in the @FA{options}.
|
in the result if the `paths` attribute is set in the @FA{options}.
|
||||||
|
|
||||||
Example calls:
|
Example calls:
|
||||||
|
|
||||||
TRAVERSAL(friends, friendrelations, "friends/john", "outbound", {
|
TRAVERSAL(friends, friendrelations, "friends/john", "outbound", {
|
||||||
strategy: "depthfirst",
|
strategy: "depthfirst",
|
||||||
order: "postorder",
|
order: "postorder",
|
||||||
itemOrder: "backward",
|
itemOrder: "backward",
|
||||||
maxDepth: 6,
|
maxDepth: 6,
|
||||||
paths: true
|
paths: true
|
||||||
})
|
})
|
||||||
|
|
||||||
// filtering on specific edges (by specifying example edges)
|
// filtering on specific edges (by specifying example edges)
|
||||||
TRAVERSAL(friends, friendrelations, "friends/john", "outbound", {
|
TRAVERSAL(friends, friendrelations, "friends/john", "outbound", {
|
||||||
strategy: "breadthfirst",
|
strategy: "breadthfirst",
|
||||||
order: "preorder",
|
order: "preorder",
|
||||||
itemOrder: "forward",
|
itemOrder: "forward",
|
||||||
followEdges: [ { type: "knows" }, { state: "FL" } ]
|
followEdges: [ { type: "knows" }, { state: "FL" } ]
|
||||||
})
|
})
|
||||||
|
|
||||||
// filtering on specific edges and vertices
|
// filtering on specific edges and vertices
|
||||||
TRAVERSAL(friends, friendrelations, "friends/john", "outbound", {
|
TRAVERSAL(friends, friendrelations, "friends/john", "outbound", {
|
||||||
strategy: "breadthfirst",
|
strategy: "breadthfirst",
|
||||||
order: "preorder",
|
order: "preorder",
|
||||||
itemOrder: "forward",
|
itemOrder: "forward",
|
||||||
followEdges: [ { type: "knows" }, { state: "FL" } ],
|
followEdges: [ { type: "knows" }, { state: "FL" } ],
|
||||||
filterVertices: [ { isActive: true }, { isDeleted: false } ],
|
filterVertices: [ { isActive: true }, { isDeleted: false } ],
|
||||||
vertexFilterMethod: [ "prune", "exclude" ]
|
vertexFilterMethod: [ "prune", "exclude" ]
|
||||||
})
|
})
|
||||||
|
|
||||||
// using user-defined AQL functions for edge and vertex filtering
|
// using user-defined AQL functions for edge and vertex filtering
|
||||||
TRAVERSAL(friends, friendrelations, "friends/john", "outbound", {
|
TRAVERSAL(friends, friendrelations, "friends/john", "outbound", {
|
||||||
followEdges: "myfunctions::checkedge",
|
followEdges: "myfunctions::checkedge",
|
||||||
filterVertices: "myfunctions::checkvertex"
|
filterVertices: "myfunctions::checkvertex"
|
||||||
})
|
})
|
||||||
|
|
||||||
// to register the custom AQL functions, execute something in the fashion of the
|
// to register the custom AQL functions, execute something in the fashion of the
|
||||||
// following commands in arangosh once:
|
// following commands in arangosh once:
|
||||||
var aqlfunctions = require("org/arangodb/aql/functions");
|
var aqlfunctions = require("org/arangodb/aql/functions");
|
||||||
|
|
||||||
// these are the actual filter functions
|
// these are the actual filter functions
|
||||||
aqlfunctions.register("myfunctions::checkedge", function (config, vertex, edge, path) {
|
aqlfunctions.register("myfunctions::checkedge", function (config, vertex, edge, path) {
|
||||||
return (edge.type !== 'dislikes'); // don't follow these edges
|
return (edge.type !== 'dislikes'); // don't follow these edges
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
aqlfunctions.register("myfunctions::checkvertex", function (config, vertex, path) {
|
aqlfunctions.register("myfunctions::checkvertex", function (config, vertex, path) {
|
||||||
if (vertex.isDeleted || ! vertex.isActive) {
|
if (vertex.isDeleted || ! vertex.isActive) {
|
||||||
return [ "prune", "exclude" ]; // exclude these and don't follow them
|
return [ "prune", "exclude" ]; // exclude these and don't follow them
|
||||||
}
|
}
|
||||||
return [ ]; // include everything else
|
return [ ]; // include everything else
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
- @FN{TRAVERSAL_TREE(@FA{vertexcollection}, @FA{edgecollection}, @FA{startVertex}, @FA{direction}, @FA{connectName}, @FA{options})}:
|
- @FN{TRAVERSAL_TREE(@FA{vertexcollection}, @FA{edgecollection}, @FA{startVertex}, @FA{direction}, @FA{connectName}, @FA{options})}:
|
||||||
traverses the graph described by @FA{vertexcollection} and @FA{edgecollection},
|
traverses the graph described by @FA{vertexcollection} and @FA{edgecollection},
|
||||||
|
@ -1566,11 +1582,11 @@ Example calls:
|
||||||
be set up in a way that resembles a depth-first, pre-order visitation result. Thus, the
|
be set up in a way that resembles a depth-first, pre-order visitation result. Thus, the
|
||||||
`strategy` and `order` attributes of the @FA{options} attribute will be ignored.
|
`strategy` and `order` attributes of the @FA{options} attribute will be ignored.
|
||||||
|
|
||||||
Example calls:
|
Example calls:
|
||||||
|
|
||||||
TRAVERSAL_TREE(friends, friendrelations, "friends/john", "outbound", "likes", {
|
TRAVERSAL_TREE(friends, friendrelations, "friends/john", "outbound", "likes", {
|
||||||
itemOrder: "forward"
|
itemOrder: "forward"
|
||||||
})
|
})
|
||||||
|
|
||||||
When using one of AQL's graph functions please make sure that the graph does not contain cycles,
|
When using one of AQL's graph functions please make sure that the graph does not contain cycles,
|
||||||
or that you at least specify some maximum depth or uniqueness criteria for a traversal.
|
or that you at least specify some maximum depth or uniqueness criteria for a traversal.
|
||||||
|
@ -1647,37 +1663,37 @@ time and memory for the result set.
|
||||||
attributes `vertices` and `edges`, which are both lists. Note that `path` is only present
|
attributes `vertices` and `edges`, which are both lists. Note that `path` is only present
|
||||||
in the result if the `paths` attribute is set in the @FA{options}.
|
in the result if the `paths` attribute is set in the @FA{options}.
|
||||||
|
|
||||||
Example calls:
|
Example calls:
|
||||||
|
|
||||||
SHORTEST_PATH(cities, motorways, "cities/CGN", "cities/MUC", "outbound", {
|
SHORTEST_PATH(cities, motorways, "cities/CGN", "cities/MUC", "outbound", {
|
||||||
paths: true
|
paths: true
|
||||||
})
|
})
|
||||||
|
|
||||||
// using a user-defined distance function
|
// using a user-defined distance function
|
||||||
SHORTEST_PATH(cities, motorways, "cities/CGN", "cities/MUC", "outbound", {
|
SHORTEST_PATH(cities, motorways, "cities/CGN", "cities/MUC", "outbound", {
|
||||||
paths: true,
|
paths: true,
|
||||||
distance: "myfunctions::citydistance"
|
distance: "myfunctions::citydistance"
|
||||||
})
|
})
|
||||||
|
|
||||||
// using a user-defined function to filter edges
|
// using a user-defined function to filter edges
|
||||||
SHORTEST_PATH(cities, motorways, "cities/CGN", "cities/MUC", "outbound", {
|
SHORTEST_PATH(cities, motorways, "cities/CGN", "cities/MUC", "outbound", {
|
||||||
paths: true,
|
paths: true,
|
||||||
followEdges: "myfunctions::checkedge"
|
followEdges: "myfunctions::checkedge"
|
||||||
})
|
})
|
||||||
|
|
||||||
// to register a custom AQL distance function, execute something in the fashion of the
|
// to register a custom AQL distance function, execute something in the fashion of the
|
||||||
// following commands in arangosh once:
|
// following commands in arangosh once:
|
||||||
var aqlfunctions = require("org/arangodb/aql/functions");
|
var aqlfunctions = require("org/arangodb/aql/functions");
|
||||||
|
|
||||||
// this is the actual distance function
|
// this is the actual distance function
|
||||||
aqlfunctions.register("myfunctions::distance", function (config, vertex1, vertex2, edge) {
|
aqlfunctions.register("myfunctions::distance", function (config, vertex1, vertex2, edge) {
|
||||||
return Math.sqrt(Math.pow(vertex1.x - vertex2.x) + Math.pow(vertex1.y - vertex2.y));
|
return Math.sqrt(Math.pow(vertex1.x - vertex2.x) + Math.pow(vertex1.y - vertex2.y));
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
// this is the filter function for the edges
|
// this is the filter function for the edges
|
||||||
aqlfunctions.register("myfunctions::checkedge", function (config, vertex, edge, path) {
|
aqlfunctions.register("myfunctions::checkedge", function (config, vertex, edge, path) {
|
||||||
return (edge.underConstruction === false); // don't follow these edges
|
return (edge.underConstruction === false); // don't follow these edges
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
- @FN{EDGES(@FA{edgecollection}, @FA{startvertex}, @FA{direction}, @FA{edgeexamples})}:
|
- @FN{EDGES(@FA{edgecollection}, @FA{startvertex}, @FA{direction}, @FA{edgeexamples})}:
|
||||||
return all edges connected to the vertex @FA{startvertex} as a list. The possible values for
|
return all edges connected to the vertex @FA{startvertex} as a list. The possible values for
|
||||||
|
@ -1691,10 +1707,10 @@ Example calls:
|
||||||
To not restrict the result to specific connections, @FA{edgeexamples} should be left
|
To not restrict the result to specific connections, @FA{edgeexamples} should be left
|
||||||
unspecified.
|
unspecified.
|
||||||
|
|
||||||
Example calls:
|
Example calls:
|
||||||
|
|
||||||
EDGES(friendrelations, "friends/john", "outbound")
|
EDGES(friendrelations, "friends/john", "outbound")
|
||||||
EDGES(friendrelations, "friends/john", "any", [ { "$label": "knows" } ])
|
EDGES(friendrelations, "friends/john", "any", [ { "$label": "knows" } ])
|
||||||
|
|
||||||
- @FN{NEIGHBORS(@FA{vertexcollection}, @FA{edgecollection}, @FA{startvertex}, @FA{direction}, @FA{edgeexamples})}:
|
- @FN{NEIGHBORS(@FA{vertexcollection}, @FA{edgecollection}, @FA{startvertex}, @FA{direction}, @FA{edgeexamples})}:
|
||||||
return all neighbors that are directly connected to the vertex @FA{startvertex} as a list.
|
return all neighbors that are directly connected to the vertex @FA{startvertex} as a list.
|
||||||
|
@ -1708,10 +1724,10 @@ Example calls:
|
||||||
To not restrict the result to specific connections, @FA{edgeexamples} should be left
|
To not restrict the result to specific connections, @FA{edgeexamples} should be left
|
||||||
unspecified.
|
unspecified.
|
||||||
|
|
||||||
Example calls:
|
Example calls:
|
||||||
|
|
||||||
NEIGHBORS(friends, friendrelations, "friends/john", "outbound")
|
NEIGHBORS(friends, friendrelations, "friends/john", "outbound")
|
||||||
NEIGHBORS(users, usersrelations, "users/john", "any", [ { "$label": "recommends" } ] )
|
NEIGHBORS(users, usersrelations, "users/john", "any", [ { "$label": "recommends" } ] )
|
||||||
|
|
||||||
@subsubsection AqlFunctionsControl Control flow functions
|
@subsubsection AqlFunctionsControl Control flow functions
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,17 @@ TOC {#AqlTOC}
|
||||||
- @ref AqlData
|
- @ref AqlData
|
||||||
- @ref AqlOperators
|
- @ref AqlOperators
|
||||||
- @ref AqlFunctions
|
- @ref AqlFunctions
|
||||||
|
- @ref AqlFunctionsCasting
|
||||||
|
- @ref AqlFunctionsChecking
|
||||||
|
- @ref AqlFunctionsString
|
||||||
|
- @ref AqlFunctionsNumeric
|
||||||
|
- @ref AqlFunctionsList
|
||||||
|
- @ref AqlFunctionsDocument
|
||||||
|
- @ref AqlFunctionsGeo
|
||||||
|
- @ref AqlFunctionsFulltext
|
||||||
|
- @ref AqlFunctionsGraph
|
||||||
|
- @ref AqlFunctionsControl
|
||||||
|
- @ref AqlFunctionsMisc
|
||||||
- @ref AqlOperations
|
- @ref AqlOperations
|
||||||
- @ref AqlOperationFor
|
- @ref AqlOperationFor
|
||||||
- @ref AqlOperationReturn
|
- @ref AqlOperationReturn
|
||||||
|
|
Loading…
Reference in New Issue