1
0
Fork 0

added yesternight's changes

This commit is contained in:
Jan Steemann 2015-01-30 08:47:43 +01:00
parent 9bf26eed37
commit 07733c672a
2 changed files with 46 additions and 27 deletions

View File

@ -166,13 +166,14 @@ instead.
function can modify its *result* parameter value in-place. At the end of the traversal, function can modify its *result* parameter value in-place. At the end of the traversal,
*result* is expected to be an array. *result* is expected to be an array.
- *data*: only useful in combination with a custom AQL visitor function. This attribute can - *data*: only useful in combination with custom AQL visitor or filter functions. This attribute can
be used to pass arbitrary data into the custom visitor function. The value contained in the be used to pass arbitrary data into the custom visitor function. The value contained in the
*data* attribute will be made available to the *visitor* function in the *config.data* *data* attribute will be made available to the *visitor* and *filterVertices* functions in the *config.data*
attribute. attribute.
By default, the result of the TRAVERSAL function is an array of traversed points. Each point By default, the result of the TRAVERSAL function is an array of traversed points. Each point
is an object consisting of the following attributes: is an object consisting of the following attributes:
- *vertex*: The vertex at the traversal point - *vertex*: The vertex at the traversal point
- *path*: The path history for the traversal point. The path is a document with the - *path*: The path history for the traversal point. The path is a document with the
attributes *vertices* and *edges*, which are both arrays. Note that *path* is only present attributes *vertices* and *edges*, which are both arrays. Note that *path* is only present
@ -239,7 +240,10 @@ instead.
order: "preorder-expander" order: "preorder-expander"
}) })
// registering the custom leaf node visitor function // to register the custom AQL function visitor that only returns leaf nodes, run
// the following commands in arangosh once:
var aqlfunctions = require("org/arangodb/aql/functions");
aqlfunctions.register("myfunctions::leafnodevisitor", function (config, vertex, edge, path, connections) { aqlfunctions.register("myfunctions::leafnodevisitor", function (config, vertex, edge, path, connections) {
if (connected && connected.length === 0) { if (connected && connected.length === 0) {
// will put the vertex into the result if it does not have any further connections // will put the vertex into the result if it does not have any further connections
@ -269,6 +273,19 @@ instead.
}, false); }, false);
// using one of the predefined visitor functions
TRAVERSAL(friends, friendrelations, "friends/john", "outbound", {
visitor: "_AQL::COUNTINGVISITOR"
})
// passing data into a visitor
TRAVERSAL(friends, friendrelations, "friends/john", "outbound", {
visitor: "_AQL::PROJECTINGVISITOR",
data: { attributes: [ "_id", "_key", "name" ] }
})
- *TRAVERSAL_TREE(vertexcollection, edgecollection, startVertex, direction, connectName, options)*: - *TRAVERSAL_TREE(vertexcollection, edgecollection, startVertex, direction, connectName, options)*:
Traverses the graph described by *vertexcollection* and *edgecollection*, Traverses the graph described by *vertexcollection* and *edgecollection*,
starting at the vertex identified by id *startVertex* and creates a hierarchical result. starting at the vertex identified by id *startVertex* and creates a hierarchical result.
@ -343,6 +360,7 @@ instead.
function (config, vertex, path) function (config, vertex, path)
If a custom AQL function is used, it is expected to return one of the following values: If a custom AQL function is used, it is expected to return one of the following values:
- *[ ]*: Include the vertex in the result and descend into its connected edges - *[ ]*: Include the vertex in the result and descend into its connected edges
- *[ "prune" ]*: Will include the vertex in the result but not descend into its connected edges - *[ "prune" ]*: Will include the vertex in the result but not descend into its connected edges
- *[ "exclude" ]*: Will not include the vertex in the result but descend into its connected edges - *[ "exclude" ]*: Will not include the vertex in the result but descend into its connected edges
@ -372,6 +390,10 @@ instead.
function can modify its *result* parameter value in-place. At the end of the traversal, function can modify its *result* parameter value in-place. At the end of the traversal,
*result* is expected to be an array. *result* is expected to be an array.
- *data*: only useful in combination with custom AQL visitor or filter functions. This attribute can
be used to pass arbitrary data into the custom visitor function. The value contained in the
*data* attribute will be made available to the *visitor* and *filterVertices* functions in the *config.data*
attribute.
By default, the result of the SHORTEST_PATH function is an array with the components of the By default, the result of the SHORTEST_PATH function is an array with the components of the
shortest path. Each component is a document consisting of the following attributes: shortest path. Each component is a document consisting of the following attributes:

View File

@ -313,6 +313,24 @@ function GET_FILTER (name, config) {
}; };
} }
////////////////////////////////////////////////////////////////////////////////
/// @brief create a user-defined expand filter from a function name
////////////////////////////////////////////////////////////////////////////////
function GET_EXPANDFILTER (name, config) {
var func = GET_USERFUNCTION(name, config);
return function (config, vertex, edge, path) {
try {
var filterResult = func.apply(null, arguments);
return FIX_VALUE(filterResult);
}
catch (err) {
WARN(name, INTERNAL.errors.ERROR_QUERY_FUNCTION_RUNTIME_ERROR, AQL_TO_STRING(err));
}
};
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief normalise a function name /// @brief normalise a function name
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -5118,10 +5136,7 @@ function TRAVERSAL_FUNC (func,
if (params.followEdges) { if (params.followEdges) {
if (typeof params.followEdges === 'string') { if (typeof params.followEdges === 'string') {
var f1 = params.followEdges.toUpperCase(); config.expandFilter = GET_EXPANDFILTER(params.followEdges, params);
config.expandFilter = function (config, vertex, edge, path) {
return FCALL_USER(f1, [ config, vertex, edge, path ]);
};
} }
else { else {
config.expandFilter = TRAVERSAL_EDGE_EXAMPLE_FILTER; config.expandFilter = TRAVERSAL_EDGE_EXAMPLE_FILTER;
@ -5135,10 +5150,7 @@ function TRAVERSAL_FUNC (func,
if (params.filterVertices) { if (params.filterVertices) {
if (typeof params.filterVertices === 'string') { if (typeof params.filterVertices === 'string') {
var f2 = params.filterVertices.toUpperCase(); config.filter = GET_FILTER(params.filterVertices, params);
config.filter = function (config, vertex, edge, path) {
return FCALL_USER(f2, [ config, vertex, path ]);
};
} }
else { else {
config.filter = TRAVERSAL_VERTEX_FILTER; config.filter = TRAVERSAL_VERTEX_FILTER;
@ -5512,11 +5524,6 @@ function SHORTEST_PATH_PARAMS (params) {
params.visitor = TRAVERSAL_VISITOR; params.visitor = TRAVERSAL_VISITOR;
} }
// add user-defined filter, if specified
if (typeof params.filter === "string") {
params.filter = GET_FILTER(params.filter, params);
}
if (typeof params.distance === "string") { if (typeof params.distance === "string") {
var name = params.distance.toUpperCase(); var name = params.distance.toUpperCase();
@ -5742,11 +5749,6 @@ function TRAVERSAL_PARAMS (params) {
params.visitor = TRAVERSAL_VISITOR; params.visitor = TRAVERSAL_VISITOR;
} }
// add user-defined filter, if specified
if (typeof params.filter === "string") {
params.filter = GET_FILTER(params.filter, params);
}
return params; return params;
} }
@ -6101,11 +6103,6 @@ function TRAVERSAL_TREE_PARAMS (params, connectName, func) {
params.visitor = TRAVERSAL_TREE_VISITOR; params.visitor = TRAVERSAL_TREE_VISITOR;
} }
// add user-defined filter, if specified
if (typeof params.filter === "string") {
params.filter = GET_FILTER(params.filter, params);
}
params.connect = AQL_TO_STRING(connectName); params.connect = AQL_TO_STRING(connectName);
if (params.connect === "") { if (params.connect === "") {