mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of github.com:triAGENS/ArangoDB into devel
This commit is contained in:
commit
6d76e8c6ac
|
@ -715,6 +715,8 @@ TRI_associative_pointer_t* TRI_CreateFunctionsAql (void) {
|
|||
REGISTER_FUNCTION("GRAPH_VERTICES", "GENERAL_GRAPH_VERTICES", false, false, "s,als|a", NULL);
|
||||
REGISTER_FUNCTION("NEIGHBORS", "GRAPH_NEIGHBORS", false, false, "h,h,s,s|l", NULL);
|
||||
REGISTER_FUNCTION("GRAPH_NEIGHBORS", "GENERAL_GRAPH_NEIGHBORS", false, false, "s,als|a", NULL);
|
||||
REGISTER_FUNCTION("GRAPH_COMMON_NEIGHBORS", "GENERAL_GRAPH_COMMON_NEIGHBORS", false, false, "s,als,als|a", NULL);
|
||||
REGISTER_FUNCTION("GRAPH_COMMON_PROPERTIES", "GENERAL_GRAPH_COMMON_PROPERTIES", false, false, "s,als,als|a", NULL);
|
||||
|
||||
// date functions
|
||||
REGISTER_FUNCTION("DATE_NOW", "DATE_NOW", false, false, "", NULL); // NOW is non-deterministic
|
||||
|
|
|
@ -73,6 +73,7 @@ var GRAPH_CONTEXT = "api";
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function graph_by_request (req) {
|
||||
|
||||
var key = req.suffix[0];
|
||||
|
||||
var g = new graph.Graph(key);
|
||||
|
@ -251,8 +252,8 @@ function post_graph_graph (req, res) {
|
|||
}
|
||||
|
||||
var name = json._key;
|
||||
var vertices = json.vertices;
|
||||
var edges = json.edges;
|
||||
var vertices = json.edgeDefinitions[0].from[0];
|
||||
var edges = json.edgeDefinitions[0].collection;
|
||||
|
||||
var waitForSync = false;
|
||||
if (req.parameters.waitForSync &&
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */
|
||||
/*global require, exports, Backbone, EJS, $, setTimeout, localStorage, ace, Storage, window, _ */
|
||||
/*global arangoHelper, templateEngine*/
|
||||
/*global arangoHelper, templateEngine, jQuery*/
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
|
|
@ -212,16 +212,17 @@ Graph.prototype.initialize = function (name, vertices, edges) {
|
|||
edges = edges.name();
|
||||
}
|
||||
|
||||
var newEdgeDefinition = [{"collection": edges, "from" :[vertices], "to": [vertices]}];
|
||||
|
||||
results = GraphAPI.postGraph({
|
||||
_key: name,
|
||||
vertices: vertices,
|
||||
edges: edges
|
||||
edgeDefinitions: newEdgeDefinition
|
||||
});
|
||||
}
|
||||
|
||||
this._properties = results.graph;
|
||||
this._vertices = arangodb.db._collection(this._properties.vertices);
|
||||
this._edges = arangodb.db._collection(this._properties.edges);
|
||||
this._vertices = arangodb.db._collection(this._properties.edgeDefinitions[0].from[0]);
|
||||
this._edges = arangodb.db._collection(this._properties.edgeDefinitions[0].collection);
|
||||
|
||||
// and dictionary for vertices and edges
|
||||
this._verticesCache = {};
|
||||
|
|
|
@ -1092,7 +1092,25 @@ Graph.prototype._neighbors = function(vertexExample, options) {
|
|||
/// @brief get common neighbors of two vertices in the graph.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Graph.prototype._listCommonNeighbors = function(vertex1, vertex2, options) {
|
||||
Graph.prototype._listCommonNeighbors = function(vertex1Example, vertex2Example, options) {
|
||||
|
||||
var ex1 = transformExample(vertex1Example);
|
||||
var ex2 = transformExample(vertex2Example);
|
||||
var query = "FOR e"
|
||||
+ " IN GRAPH_COMMON_NEIGHBORS(@graphName"
|
||||
+ ',@ex1'
|
||||
+ ',@ex2'
|
||||
+ ',@options'
|
||||
+ ') SORT ATTRIBUTES(e)[0] RETURN e';
|
||||
options = options || {};
|
||||
var bindVars = {
|
||||
"graphName": this.__name,
|
||||
"options": options,
|
||||
"ex1": ex1,
|
||||
"ex2": ex2
|
||||
};
|
||||
return db._query(query, bindVars, {count: true}).toArray();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@ -1100,15 +1118,63 @@ Graph.prototype._listCommonNeighbors = function(vertex1, vertex2, options) {
|
|||
/// @brief get amount of common neighbors of two vertices in the graph.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Graph.prototype._amountCommonNeighbors = function(vertex1, vertex2, options) {
|
||||
|
||||
Graph.prototype._amountCommonNeighbors = function(vertex1Example, vertex2Example, options) {
|
||||
var ex1 = transformExample(vertex1Example);
|
||||
var ex2 = transformExample(vertex2Example);
|
||||
var query = "FOR e"
|
||||
+ " IN GRAPH_COMMON_NEIGHBORS(@graphName"
|
||||
+ ',@ex1'
|
||||
+ ',@ex2'
|
||||
+ ',@options'
|
||||
+ ') FOR a in ATTRIBUTES(e) FOR b in ATTRIBUTES(e[a]) '
|
||||
+ 'SORT ATTRIBUTES(e)[0] RETURN [a, b, LENGTH(e[a][b]) ]';
|
||||
options = options || {};
|
||||
var bindVars = {
|
||||
"graphName": this.__name,
|
||||
"options": options,
|
||||
"ex1": ex1,
|
||||
"ex2": ex2
|
||||
};
|
||||
var result = db._query(query, bindVars, {count: true}).toArray(),
|
||||
tmp = {}, tmp2={}, returnHash = [];
|
||||
result.forEach(function (r) {
|
||||
if (!tmp[r[0]]) {
|
||||
tmp[r[0]] = [];
|
||||
}
|
||||
tmp2 = {};
|
||||
tmp2[r[1]] = r[2];
|
||||
tmp[r[0]].push(tmp2);
|
||||
});
|
||||
Object.keys(tmp).forEach(function(w) {
|
||||
tmp2 = {};
|
||||
tmp2[w] = tmp[w];
|
||||
returnHash.push(tmp2);
|
||||
});
|
||||
return returnHash;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get common properties of two vertices in the graph.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Graph.prototype._listCommonProperties = function(vertex1, vertex2, options) {
|
||||
Graph.prototype._listCommonProperties = function(vertex1Example, vertex2Example, options) {
|
||||
|
||||
var ex1 = transformExample(vertex1Example);
|
||||
var ex2 = transformExample(vertex2Example);
|
||||
var query = "FOR e"
|
||||
+ " IN GRAPH_COMMON_PROPERTIES(@graphName"
|
||||
+ ',@ex1'
|
||||
+ ',@ex2'
|
||||
+ ',@options'
|
||||
+ ') SORT ATTRIBUTES(e)[0] RETURN e';
|
||||
options = options || {};
|
||||
var bindVars = {
|
||||
"graphName": this.__name,
|
||||
"options": options,
|
||||
"ex1": ex1,
|
||||
"ex2": ex2
|
||||
};
|
||||
return db._query(query, bindVars, {count: true}).toArray();
|
||||
|
||||
};
|
||||
|
||||
|
@ -1116,8 +1182,29 @@ Graph.prototype._listCommonProperties = function(vertex1, vertex2, options) {
|
|||
/// @brief get amount of common properties of two vertices in the graph.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Graph.prototype._amountCommonProperties = function(vertex1, vertex2, options) {
|
||||
|
||||
Graph.prototype._amountCommonProperties = function(vertex1Example, vertex2Example, options) {
|
||||
var ex1 = transformExample(vertex1Example);
|
||||
var ex2 = transformExample(vertex2Example);
|
||||
var query = "FOR e"
|
||||
+ " IN GRAPH_COMMON_PROPERTIES(@graphName"
|
||||
+ ',@ex1'
|
||||
+ ',@ex2'
|
||||
+ ',@options'
|
||||
+ ') FOR a in ATTRIBUTES(e) SORT ATTRIBUTES(e)[0] RETURN [ ATTRIBUTES(e)[0], LENGTH(e[a]) ]';
|
||||
options = options || {};
|
||||
var bindVars = {
|
||||
"graphName": this.__name,
|
||||
"options": options,
|
||||
"ex1": ex1,
|
||||
"ex2": ex2
|
||||
};
|
||||
var result = db._query(query, bindVars, {count: true}).toArray(), returnHash = [];
|
||||
result.forEach(function (r) {
|
||||
var tmp = {};
|
||||
tmp[r[0]] = r[1];
|
||||
returnHash.push(tmp);
|
||||
});
|
||||
return returnHash;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -1893,6 +1893,275 @@ function EdgesAndVerticesSuite() {
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
function GeneralGraphCommonNeighborsSuite() {
|
||||
var vertex = null;
|
||||
var edge = null;
|
||||
var testGraph, actual;
|
||||
|
||||
return {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set up
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
setUp: function () {
|
||||
db._drop("UnitTestsAhuacatlVertex1");
|
||||
db._drop("UnitTestsAhuacatlVertex2");
|
||||
db._drop("UnitTestsAhuacatlEdge1");
|
||||
|
||||
vertex1 = db._create("UnitTestsAhuacatlVertex1");
|
||||
vertex2 = db._create("UnitTestsAhuacatlVertex2");
|
||||
edge1 = db._createEdgeCollection("UnitTestsAhuacatlEdge1");
|
||||
|
||||
vertex1.save({ _key: "v1" , hugo : true});
|
||||
vertex1.save({ _key: "v2" ,hugo : true});
|
||||
vertex1.save({ _key: "v3" , heinz : 1});
|
||||
vertex1.save({ _key: "v4" , harald : "meier"});
|
||||
vertex2.save({ _key: "v5" , ageing : true});
|
||||
vertex2.save({ _key: "v6" , harald : "meier", ageing : true});
|
||||
vertex2.save({ _key: "v7" ,harald : "meier"});
|
||||
vertex2.save({ _key: "v8" ,heinz : 1, harald : "meier"});
|
||||
|
||||
function makeEdge(from, to, collection) {
|
||||
collection.save(from, to, { what: from.split("/")[1] + "->" + to.split("/")[1] });
|
||||
}
|
||||
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v1", "UnitTestsAhuacatlVertex1/v2", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v2", "UnitTestsAhuacatlVertex1/v3", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v3", "UnitTestsAhuacatlVertex2/v5", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v2", "UnitTestsAhuacatlVertex2/v6", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex2/v6", "UnitTestsAhuacatlVertex2/v7", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v4", "UnitTestsAhuacatlVertex2/v7", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v3", "UnitTestsAhuacatlVertex2/v7", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex2/v8", "UnitTestsAhuacatlVertex1/v1", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v3", "UnitTestsAhuacatlVertex2/v5", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v3", "UnitTestsAhuacatlVertex2/v8", edge1);
|
||||
|
||||
try {
|
||||
db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
testGraph = graph._create(
|
||||
"bla3",
|
||||
graph._edgeDefinitions(
|
||||
graph._directedRelationDefinition("UnitTestsAhuacatlEdge1",
|
||||
["UnitTestsAhuacatlVertex1", "UnitTestsAhuacatlVertex2"],
|
||||
["UnitTestsAhuacatlVertex1", "UnitTestsAhuacatlVertex2"]
|
||||
)
|
||||
)
|
||||
);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tear down
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
tearDown: function () {
|
||||
db._drop("UnitTestsAhuacatlVertex1");
|
||||
db._drop("UnitTestsAhuacatlVertex2");
|
||||
db._drop("UnitTestsAhuacatlEdge1");
|
||||
try {
|
||||
db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks GRAPH_COMMON_NEIGHBORS() and GRAPH_COMMON_PROPERTIES()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testCommonNeighborsAny: function () {
|
||||
actual = testGraph._listCommonNeighbors('UnitTestsAhuacatlVertex1/v3' , 'UnitTestsAhuacatlVertex2/v6', {direction : 'any'});
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v3"]["UnitTestsAhuacatlVertex2/v6"][0]._id , "UnitTestsAhuacatlVertex1/v2");
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v3"]["UnitTestsAhuacatlVertex2/v6"][1]._id , "UnitTestsAhuacatlVertex2/v7");
|
||||
|
||||
|
||||
actual = testGraph._amountCommonNeighbors('UnitTestsAhuacatlVertex1/v3' , 'UnitTestsAhuacatlVertex2/v6', {direction : 'any'});
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v3"][0]["UnitTestsAhuacatlVertex2/v6"] , 2);
|
||||
|
||||
},
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks GRAPH_COMMON_NEIGHBORS()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testCommonNeighborsIn: function () {
|
||||
actual = testGraph._listCommonNeighbors({} , {}, {direction : 'inbound'});
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v3"]["UnitTestsAhuacatlVertex2/v6"][0]._id , "UnitTestsAhuacatlVertex1/v2");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex2/v5"]["UnitTestsAhuacatlVertex2/v8"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex2/v5"]["UnitTestsAhuacatlVertex2/v7"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
|
||||
|
||||
assertEqual(actual[2]["UnitTestsAhuacatlVertex2/v6"]["UnitTestsAhuacatlVertex1/v3"][0]._id , "UnitTestsAhuacatlVertex1/v2");
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex2/v7"]["UnitTestsAhuacatlVertex2/v5"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex2/v7"]["UnitTestsAhuacatlVertex2/v8"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
|
||||
assertEqual(actual[4]["UnitTestsAhuacatlVertex2/v8"]["UnitTestsAhuacatlVertex2/v5"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
assertEqual(actual[4]["UnitTestsAhuacatlVertex2/v8"]["UnitTestsAhuacatlVertex2/v7"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
|
||||
actual = testGraph._amountCommonNeighbors({} , {}, {direction : 'inbound'});
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v3"][0]["UnitTestsAhuacatlVertex2/v6"] , 1);
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex2/v5"][0]["UnitTestsAhuacatlVertex2/v8"] , 1);
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex2/v5"][1]["UnitTestsAhuacatlVertex2/v7"] , 1);
|
||||
assertEqual(actual[2]["UnitTestsAhuacatlVertex2/v6"][0]["UnitTestsAhuacatlVertex1/v3"] , 1);
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex2/v7"][0]["UnitTestsAhuacatlVertex2/v5"] , 1);
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex2/v7"][1]["UnitTestsAhuacatlVertex2/v8"] , 1);
|
||||
|
||||
assertEqual(actual[4]["UnitTestsAhuacatlVertex2/v8"][0]["UnitTestsAhuacatlVertex2/v5"] , 1);
|
||||
assertEqual(actual[4]["UnitTestsAhuacatlVertex2/v8"][1]["UnitTestsAhuacatlVertex2/v7"] , 1);
|
||||
|
||||
},
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks GRAPH_COMMON_NEIGHBORS()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testCommonNeighborsOut: function () {
|
||||
actual = testGraph._listCommonNeighbors( { hugo : true } , {heinz : 1}, {direction : 'outbound', minDepth : 1, maxDepth : 3});
|
||||
assertEqual(Object.keys(actual[1])[0] , "UnitTestsAhuacatlVertex1/v2");
|
||||
assertEqual(Object.keys(actual[1][Object.keys(actual[1])[0]]) , ["UnitTestsAhuacatlVertex2/v8", "UnitTestsAhuacatlVertex1/v3"]);
|
||||
|
||||
assertEqual(actual[1][Object.keys(actual[1])[0]]["UnitTestsAhuacatlVertex2/v8"].length , 3);
|
||||
assertEqual(actual[1][Object.keys(actual[1])[0]]["UnitTestsAhuacatlVertex1/v3"].length , 4);
|
||||
|
||||
assertEqual(Object.keys(actual[0])[0] , "UnitTestsAhuacatlVertex1/v1");
|
||||
assertEqual(Object.keys(actual[0][Object.keys(actual[0])[0]]) , ["UnitTestsAhuacatlVertex1/v3", "UnitTestsAhuacatlVertex2/v8"]);
|
||||
|
||||
assertEqual(actual[0][Object.keys(actual[0])[0]]["UnitTestsAhuacatlVertex1/v3"].length , 4);
|
||||
assertEqual(actual[0][Object.keys(actual[0])[0]]["UnitTestsAhuacatlVertex2/v8"].length , 3);
|
||||
|
||||
actual = testGraph._amountCommonNeighbors({ hugo : true } , {heinz : 1}, {direction : 'outbound', minDepth : 1, maxDepth : 3});
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v1"][0]["UnitTestsAhuacatlVertex1/v3"] , 4);
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v1"][1]["UnitTestsAhuacatlVertex2/v8"] , 3);
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex1/v2"][0]["UnitTestsAhuacatlVertex2/v8"] , 3);
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex1/v2"][1]["UnitTestsAhuacatlVertex1/v3"] , 4);
|
||||
|
||||
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks GRAPH_COMMON_PROPERTIES()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testCommonProperties: function () {
|
||||
actual = testGraph._listCommonProperties( { } , {}, {});
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v1"][0]._id , "UnitTestsAhuacatlVertex1/v2");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex1/v2"][0]._id , "UnitTestsAhuacatlVertex1/v1");
|
||||
assertEqual(actual[2]["UnitTestsAhuacatlVertex1/v3"][0]._id , "UnitTestsAhuacatlVertex2/v8");
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex1/v4"][0]._id , "UnitTestsAhuacatlVertex2/v6");
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex1/v4"][1]._id , "UnitTestsAhuacatlVertex2/v8");
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex1/v4"][2]._id , "UnitTestsAhuacatlVertex2/v7");
|
||||
|
||||
assertEqual(actual[4]["UnitTestsAhuacatlVertex2/v5"][0]._id , "UnitTestsAhuacatlVertex2/v6");
|
||||
assertEqual(actual[5]["UnitTestsAhuacatlVertex2/v6"][0]._id , "UnitTestsAhuacatlVertex1/v4");
|
||||
assertEqual(actual[5]["UnitTestsAhuacatlVertex2/v6"][1]._id , "UnitTestsAhuacatlVertex2/v5");
|
||||
assertEqual(actual[5]["UnitTestsAhuacatlVertex2/v6"][2]._id , "UnitTestsAhuacatlVertex2/v8");
|
||||
assertEqual(actual[5]["UnitTestsAhuacatlVertex2/v6"][3]._id , "UnitTestsAhuacatlVertex2/v7");
|
||||
|
||||
|
||||
assertEqual(actual[6]["UnitTestsAhuacatlVertex2/v7"][0]._id , "UnitTestsAhuacatlVertex1/v4");
|
||||
assertEqual(actual[6]["UnitTestsAhuacatlVertex2/v7"][1]._id , "UnitTestsAhuacatlVertex2/v6");
|
||||
assertEqual(actual[6]["UnitTestsAhuacatlVertex2/v7"][2]._id , "UnitTestsAhuacatlVertex2/v8");
|
||||
|
||||
assertEqual(actual[7]["UnitTestsAhuacatlVertex2/v8"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
assertEqual(actual[7]["UnitTestsAhuacatlVertex2/v8"][1]._id , "UnitTestsAhuacatlVertex1/v4");
|
||||
assertEqual(actual[7]["UnitTestsAhuacatlVertex2/v8"][2]._id , "UnitTestsAhuacatlVertex2/v6");
|
||||
assertEqual(actual[7]["UnitTestsAhuacatlVertex2/v8"][3]._id , "UnitTestsAhuacatlVertex2/v7");
|
||||
|
||||
|
||||
actual = testGraph._amountCommonProperties( { } , {}, {});
|
||||
assertEqual(actual, [
|
||||
{
|
||||
"UnitTestsAhuacatlVertex1/v1" : 1
|
||||
},
|
||||
{
|
||||
"UnitTestsAhuacatlVertex1/v2" : 1
|
||||
},
|
||||
{
|
||||
"UnitTestsAhuacatlVertex1/v3" : 1
|
||||
},
|
||||
{
|
||||
"UnitTestsAhuacatlVertex1/v4" : 3
|
||||
},
|
||||
{
|
||||
"UnitTestsAhuacatlVertex2/v5" : 1
|
||||
},
|
||||
{
|
||||
"UnitTestsAhuacatlVertex2/v6" : 4
|
||||
},
|
||||
{
|
||||
"UnitTestsAhuacatlVertex2/v7" : 3
|
||||
},
|
||||
{
|
||||
"UnitTestsAhuacatlVertex2/v8" : 4
|
||||
}
|
||||
]);
|
||||
|
||||
|
||||
|
||||
},
|
||||
|
||||
testCommonPropertiesWithFilters: function () {
|
||||
actual = testGraph._listCommonProperties({ageing : true} , {harald : 'meier'}, {});
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex2/v5"][0]._id , "UnitTestsAhuacatlVertex2/v6");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex2/v6"][0]._id , "UnitTestsAhuacatlVertex1/v4");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex2/v6"][1]._id , "UnitTestsAhuacatlVertex2/v8");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex2/v6"][2]._id , "UnitTestsAhuacatlVertex2/v7");
|
||||
|
||||
actual = testGraph._amountCommonProperties({ageing : true} , {harald : 'meier'}, {});
|
||||
assertEqual(actual, [
|
||||
{
|
||||
"UnitTestsAhuacatlVertex2/v5" : 1
|
||||
},
|
||||
{
|
||||
"UnitTestsAhuacatlVertex2/v6" : 3
|
||||
}
|
||||
]);
|
||||
|
||||
},
|
||||
|
||||
testCommonPropertiesWithFiltersAndIgnoringKeyHarald: function () {
|
||||
actual = testGraph._listCommonProperties( {} , {}, {ignoreProperties : 'harald'});
|
||||
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v1"][0]._id , "UnitTestsAhuacatlVertex1/v2");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex1/v2"][0]._id , "UnitTestsAhuacatlVertex1/v1");
|
||||
assertEqual(actual[2]["UnitTestsAhuacatlVertex1/v3"][0]._id , "UnitTestsAhuacatlVertex2/v8");
|
||||
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex2/v5"][0]._id , "UnitTestsAhuacatlVertex2/v6");
|
||||
|
||||
assertEqual(actual[4]["UnitTestsAhuacatlVertex2/v6"][0]._id , "UnitTestsAhuacatlVertex2/v5");
|
||||
assertEqual(actual[5]["UnitTestsAhuacatlVertex2/v8"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
|
||||
actual = testGraph._amountCommonProperties({} , {}, {ignoreProperties : 'harald'});
|
||||
assertEqual(actual, [
|
||||
{
|
||||
"UnitTestsAhuacatlVertex1/v1" : 1
|
||||
},
|
||||
{
|
||||
"UnitTestsAhuacatlVertex1/v2" : 1
|
||||
},
|
||||
{
|
||||
"UnitTestsAhuacatlVertex1/v3" : 1
|
||||
},
|
||||
{
|
||||
"UnitTestsAhuacatlVertex2/v5" : 1
|
||||
},
|
||||
{
|
||||
"UnitTestsAhuacatlVertex2/v6" : 1
|
||||
},
|
||||
{
|
||||
"UnitTestsAhuacatlVertex2/v8" : 1
|
||||
}
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- main
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -1901,6 +2170,7 @@ function EdgesAndVerticesSuite() {
|
|||
/// @brief executes the test suites
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
jsunity.run(GeneralGraphCommonNeighborsSuite);
|
||||
jsunity.run(GeneralGraphAQLQueriesSuite);
|
||||
jsunity.run(EdgesAndVerticesSuite);
|
||||
jsunity.run(GeneralGraphCreationSuite);
|
||||
|
|
|
@ -219,6 +219,25 @@ function INDEX_FULLTEXT (collection, attribute) {
|
|||
return null;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Transforms a parameter to a list,
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function TO_LIST (param, isStringHash) {
|
||||
|
||||
if (!param) {
|
||||
param = isStringHash ? [] : [{}];
|
||||
}
|
||||
if (typeof param === "string") {
|
||||
param = isStringHash ? [param] : {_id : param};
|
||||
}
|
||||
if (!Array.isArray(param)) {
|
||||
param = [param];
|
||||
}
|
||||
return param;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief find an index of a certain type for a collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -4250,7 +4269,7 @@ function TRAVERSAL_VISITOR (config, result, vertex, path) {
|
|||
function TRAVERSAL_NEIGHBOR_VISITOR (config, result, vertex, path) {
|
||||
"use strict";
|
||||
|
||||
result.push(CLONE({ vertex: vertex, path: path }));
|
||||
result.push(CLONE({ vertex: vertex, path: path, startVertex : config.startVertex }));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -4398,7 +4417,9 @@ function TRAVERSAL_FUNC (func,
|
|||
expander: direction,
|
||||
strategy: params.strategy,
|
||||
order: params.order,
|
||||
itemOrder: params.itemOrder
|
||||
itemOrder: params.itemOrder,
|
||||
startVertex : startVertex
|
||||
|
||||
};
|
||||
|
||||
if (params.followEdges) {
|
||||
|
@ -4862,7 +4883,10 @@ function RESOLVE_GRAPH_TO_DOCUMENTS (graphname, options) {
|
|||
toVertices : DOCUMENTS_BY_EXAMPLE(
|
||||
toCollection.filter(removeDuplicates), options.toVertexExample
|
||||
),
|
||||
edges : DOCUMENTS_BY_EXAMPLE(edgeCollections.filter(removeDuplicates), options.edgeExample)
|
||||
edges : DOCUMENTS_BY_EXAMPLE(edgeCollections.filter(removeDuplicates), options.edgeExample),
|
||||
edgeCollections : edgeCollections,
|
||||
fromCollections : fromCollections,
|
||||
toCollection : toCollection
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -4928,7 +4952,16 @@ function GENERAL_GRAPH_NEIGHBORS (graphName,
|
|||
|
||||
neighbors = neighbors.concat(e);
|
||||
});
|
||||
return neighbors;
|
||||
|
||||
var result = [];
|
||||
neighbors.forEach(function (n) {
|
||||
if (FILTER([n.vertex], options.neighborExamples).length > 0) {
|
||||
result.push(n);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -4977,6 +5010,140 @@ function GENERAL_GRAPH_VERTICES (
|
|||
return graph.fromVertices;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return common neighbors of two vertices lists
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
function TRANSFER_GENERAL_GRAPH_NEIGHBORS_RESULT (result) {
|
||||
|
||||
var ret = {};
|
||||
result.forEach(function (r) {
|
||||
if (!ret[r.startVertex]) {
|
||||
ret[r.startVertex] = [];
|
||||
}
|
||||
ret[r.startVertex].push(r.vertex);
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return common neighbors of two vertices lists
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
function GENERAL_GRAPH_COMMON_NEIGHBORS (
|
||||
graphName,
|
||||
vertex1Examples,
|
||||
vertex2Examples,
|
||||
options) {
|
||||
"use strict";
|
||||
|
||||
var neighbors1 = TRANSFER_GENERAL_GRAPH_NEIGHBORS_RESULT(
|
||||
GENERAL_GRAPH_NEIGHBORS(graphName, vertex1Examples, options)
|
||||
);
|
||||
var result = {}, res = [];
|
||||
|
||||
Object.keys(neighbors1).forEach(function (n1) {
|
||||
if (!result[n1]) {
|
||||
result[n1] = {};
|
||||
}
|
||||
neighbors1[n1].forEach(function (n11) {
|
||||
options.neighborExamples = {_id : n11._id };
|
||||
var neighbors2 = TRANSFER_GENERAL_GRAPH_NEIGHBORS_RESULT(
|
||||
GENERAL_GRAPH_NEIGHBORS(graphName, vertex2Examples, options)
|
||||
);
|
||||
Object.keys(neighbors2).forEach(function (n2) {
|
||||
if (n1 === n2) {return;}
|
||||
if (!result[n1][n2]) {
|
||||
result[n1][n2] = [];
|
||||
}
|
||||
var keys = [];
|
||||
result[n1][n2].forEach(function (a) {keys.push(a._id);});
|
||||
if (keys.indexOf(n11._id) === -1) {
|
||||
result[n1][n2].push(n11);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Object.keys(result).forEach(function (r) {
|
||||
var tmp = {};
|
||||
tmp[r] = result[r];
|
||||
if (Object.keys(result[r]).length > 0) {
|
||||
res.push(tmp);
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return common neighbors of two vertices lists
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
function GENERAL_GRAPH_COMMON_PROPERTIES (
|
||||
graphName,
|
||||
vertex1Examples,
|
||||
vertex2Examples,
|
||||
options) {
|
||||
"use strict";
|
||||
|
||||
if (! options) {
|
||||
options = { };
|
||||
}
|
||||
options.fromVertexExample = vertex1Examples;
|
||||
options.direction = 'any';
|
||||
options.ignoreProperties = TO_LIST(options.ignoreProperties, true);
|
||||
|
||||
var g = RESOLVE_GRAPH_TO_DOCUMENTS(graphName, options);
|
||||
var result = {}, res = [];
|
||||
var removeDuplicates = function(elem, pos, self) {
|
||||
return self.indexOf(elem) === pos;
|
||||
};
|
||||
|
||||
g.fromVertices.forEach(function (n1) {
|
||||
options.fromVertexExample = vertex2Examples;
|
||||
vertex2Examples = TO_LIST(vertex2Examples);
|
||||
var searchOptions = [];
|
||||
Object.keys(n1).forEach(function (key) {
|
||||
if (key.indexOf("_") === 0 || options.ignoreProperties.indexOf(key) !== -1) {
|
||||
return;
|
||||
}
|
||||
if (vertex2Examples.length === 0) {
|
||||
var con = {};
|
||||
con[key] = n1[key];
|
||||
searchOptions.push(con);
|
||||
}
|
||||
vertex2Examples.forEach(function (example) {
|
||||
var con = CLONE(example);
|
||||
con[key] = n1[key];
|
||||
searchOptions.push(con);
|
||||
});
|
||||
});
|
||||
if (searchOptions.length > 0) {
|
||||
options.fromVertexExample = searchOptions;
|
||||
var commons = DOCUMENTS_BY_EXAMPLE(
|
||||
g.fromCollections.filter(removeDuplicates), options.fromVertexExample
|
||||
);
|
||||
result[n1._id] = [];
|
||||
commons.forEach(function (c) {
|
||||
if (c._id !== n1._id) {
|
||||
result[n1._id].push(c);
|
||||
}
|
||||
});
|
||||
if (result[n1._id].length === 0) {
|
||||
delete result[n1._id];
|
||||
}
|
||||
}
|
||||
});
|
||||
Object.keys(result).forEach(function (r) {
|
||||
var tmp = {};
|
||||
tmp[r] = result[r];
|
||||
if (Object.keys(result[r]).length > 0) {
|
||||
res.push(tmp);
|
||||
}
|
||||
});
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -5095,6 +5262,8 @@ exports.GENERAL_GRAPH_VERTICES = GENERAL_GRAPH_VERTICES;
|
|||
exports.GENERAL_GRAPH_PATHS = GENERAL_GRAPH_PATHS;
|
||||
exports.GRAPH_NEIGHBORS = GRAPH_NEIGHBORS;
|
||||
exports.GENERAL_GRAPH_NEIGHBORS = GENERAL_GRAPH_NEIGHBORS;
|
||||
exports.GENERAL_GRAPH_COMMON_NEIGHBORS = GENERAL_GRAPH_COMMON_NEIGHBORS;
|
||||
exports.GENERAL_GRAPH_COMMON_PROPERTIES = GENERAL_GRAPH_COMMON_PROPERTIES;
|
||||
exports.NOT_NULL = NOT_NULL;
|
||||
exports.FIRST_LIST = FIRST_LIST;
|
||||
exports.FIRST_DOCUMENT = FIRST_DOCUMENT;
|
||||
|
|
|
@ -33,6 +33,7 @@ var arangodb = require("org/arangodb"),
|
|||
db = arangodb.db,
|
||||
ArangoCollection = arangodb.ArangoCollection,
|
||||
common = require("org/arangodb/graph-common"),
|
||||
newGraph = require("org/arangodb/general-graph"),
|
||||
Edge = common.Edge,
|
||||
Graph = common.Graph,
|
||||
Vertex = common.Vertex,
|
||||
|
@ -317,6 +318,8 @@ Vertex.prototype.setProperty = function (name, value) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
|
||||
|
||||
this._name = name;
|
||||
var gdb = db._collection("_graphs");
|
||||
var graphProperties;
|
||||
var graphPropertiesId;
|
||||
|
@ -340,6 +343,7 @@ Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
|
|||
|
||||
// find an existing graph by name
|
||||
if (vertices === undefined && edges === undefined) {
|
||||
|
||||
try {
|
||||
graphProperties = gdb.document(name);
|
||||
}
|
||||
|
@ -351,16 +355,34 @@ Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
|
|||
throw "no graph named '" + name + "' found";
|
||||
}
|
||||
|
||||
vertices = db._collection(graphProperties.vertices);
|
||||
|
||||
if (vertices === null) {
|
||||
throw "vertex collection '" + graphProperties.vertices + "' has vanished";
|
||||
//check if graph can be loaded by this deprecated module
|
||||
var newGraphError = "Graph can not be loaded, "
|
||||
+ "because more than 1 vertex collection is defined. "
|
||||
+ "Please use the new graph module";
|
||||
var edgeDefinitions = db._graphs.document(name).edgeDefinitions;
|
||||
if (edgeDefinitions.length === 0) {
|
||||
throw newGraphError;
|
||||
}
|
||||
if (edgeDefinitions.length > 1) {
|
||||
throw newGraphError;
|
||||
} else if (edgeDefinitions.length === 1) {
|
||||
var from = edgeDefinitions[0].from;
|
||||
var to = edgeDefinitions[0].to;
|
||||
if (from.length !== 1 || to.length !== 1 || from[0] !== to[0]) {
|
||||
throw newGraphError;
|
||||
}
|
||||
}
|
||||
|
||||
edges = db._collection(graphProperties.edges);
|
||||
vertices = db._collection(edgeDefinitions[0].from[0]);
|
||||
|
||||
if (vertices === null) {
|
||||
throw "vertex collection '" + edgeDefinitions[0].from[0] + "' has vanished";
|
||||
}
|
||||
|
||||
edges = db._collection(edgeDefinitions[0].collection);
|
||||
|
||||
if (edges === null) {
|
||||
throw "edge collection '" + graphProperties.edges + "' has vanished";
|
||||
throw "edge collection '" + edgeDefinitions[0].collection + "' has vanished";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,26 +410,41 @@ Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
|
|||
|
||||
// check if know that graph
|
||||
graphProperties = gdb.firstExample(
|
||||
'vertices', vertices,
|
||||
'edges', edges
|
||||
'edgeDefintions', [{"collection": edges, "from" :[vertices], "to": [vertices]}]
|
||||
);
|
||||
|
||||
if (graphProperties === null) {
|
||||
|
||||
// check if edge is used in a graph
|
||||
graphProperties = gdb.firstExample('edges', edges);
|
||||
//hole alle graphen nud schau nach O.o
|
||||
gdb.toArray().forEach(
|
||||
function(singleGraph) {
|
||||
var sGEDs = singleGraph.edgeDefinitions;
|
||||
sGEDs.forEach(
|
||||
function(sGED) {
|
||||
if (sGED.collection === edges) {
|
||||
graphProperties = "";
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
if (graphProperties === null) {
|
||||
findOrCreateCollectionByName(vertices);
|
||||
findOrCreateEdgeCollectionByName(edges);
|
||||
|
||||
graphPropertiesId = gdb.save({
|
||||
'vertices' : vertices,
|
||||
'edges' : edges,
|
||||
'_key' : name
|
||||
}, waitForSync);
|
||||
var newEdgeDefinition = [{"collection": edges, "from" :[vertices], "to": [vertices]}];
|
||||
|
||||
graphProperties = gdb.document(graphPropertiesId);
|
||||
graphPropertiesId = gdb.save(
|
||||
{
|
||||
'edgeDefinitions' : newEdgeDefinition,
|
||||
'_key' : name
|
||||
},
|
||||
waitForSync
|
||||
);
|
||||
|
||||
graphProperties = gdb.document(graphPropertiesId._key);
|
||||
}
|
||||
else {
|
||||
throw "edge collection already used";
|
||||
|
@ -419,14 +456,13 @@ Graph.prototype.initialize = function (name, vertices, edges, waitForSync) {
|
|||
}
|
||||
else {
|
||||
if (graphProperties.vertices !== vertices || graphProperties.edges !== edges) {
|
||||
throw "graph with that name already exists";
|
||||
throw "graph with that name already exists!";
|
||||
}
|
||||
}
|
||||
|
||||
vertices = db._collection(graphProperties.vertices);
|
||||
edges = db._collection(graphProperties.edges);
|
||||
vertices = db._collection(graphProperties.edgeDefinitions[0].from[0]);
|
||||
edges = db._collection(graphProperties.edgeDefinitions[0].collection);
|
||||
}
|
||||
|
||||
this._properties = graphProperties;
|
||||
|
||||
// and store the collections
|
||||
|
@ -506,15 +542,7 @@ Graph.drop = function (name, waitForSync) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Graph.prototype.drop = function (waitForSync) {
|
||||
var gdb = db._collection("_graphs");
|
||||
|
||||
gdb.remove(this._properties, true, waitForSync);
|
||||
|
||||
if (gdb.byExample({vertices: this._vertices.name()}).count() === 0) {
|
||||
this._vertices.drop();
|
||||
}
|
||||
|
||||
this._edges.drop();
|
||||
newGraph._drop(this._name, true);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -208,12 +208,15 @@ function ahuacatlQueryGeneralEdgesTestSuite() {
|
|||
assertEqual(actual, []);
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_NEIGHBORS('bla3', 'UnitTestsAhuacatlVertex1/v1', {direction : 'outbound' ,minDepth : 1, maxDepth : 3}) SORT e.vertex._key RETURN e");
|
||||
|
||||
assertEqual(actual[0].vertex._key , "v1");
|
||||
assertEqual(actual[1].vertex._key , "v2");
|
||||
assertEqual(actual[2].vertex._key , "v5");
|
||||
assertEqual(actual[3].vertex._key , "v5");
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_NEIGHBORS('bla3', 'UnitTestsAhuacatlVertex1/v1', {neighborExamples : {hugo : true} , direction : 'outbound' ,minDepth : 1, maxDepth : 3}) SORT e.vertex._key RETURN e");
|
||||
assertEqual(actual[0].vertex._key , "v1");
|
||||
assertEqual(actual[1].vertex._key , "v2");
|
||||
|
||||
actual = getRawQueryResults("FOR e IN GRAPH_VERTICES('bla3', [{hugo : true}, {heinz : 1}], {direction : 'outbound'}) SORT e._id RETURN e");
|
||||
assertEqual(actual[0]._id, 'UnitTestsAhuacatlVertex1/v1');
|
||||
assertEqual(actual[1]._id, 'UnitTestsAhuacatlVertex1/v2');
|
||||
|
@ -235,7 +238,6 @@ function ahuacatlQueryGeneralEdgesTestSuite() {
|
|||
assertEqual(actual[3].vertex._key , "v5");
|
||||
|
||||
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_NEIGHBORS('bla3', { hugo : true } , {direction : 'outbound', endVertexCollectionRestriction : 'UnitTestsAhuacatlVertex3' }) " +
|
||||
"SORT e.vertex._key RETURN e");
|
||||
|
||||
|
@ -243,7 +245,6 @@ function ahuacatlQueryGeneralEdgesTestSuite() {
|
|||
assertEqual(actual[1].vertex._key , "v2");
|
||||
assertEqual(actual[2].vertex._key , "v5");
|
||||
assertEqual(actual[3].vertex._key , "v5");
|
||||
|
||||
},
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks EDGES() exceptions
|
||||
|
@ -260,6 +261,190 @@ function ahuacatlQueryGeneralEdgesTestSuite() {
|
|||
|
||||
|
||||
|
||||
function ahuacatlQueryGeneralCommonTestSuite() {
|
||||
var vertex = null;
|
||||
var edge = null;
|
||||
|
||||
return {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set up
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
setUp: function () {
|
||||
db._drop("UnitTestsAhuacatlVertex1");
|
||||
db._drop("UnitTestsAhuacatlVertex2");
|
||||
db._drop("UnitTestsAhuacatlEdge1");
|
||||
|
||||
vertex1 = db._create("UnitTestsAhuacatlVertex1");
|
||||
vertex2 = db._create("UnitTestsAhuacatlVertex2");
|
||||
edge1 = db._createEdgeCollection("UnitTestsAhuacatlEdge1");
|
||||
|
||||
vertex1.save({ _key: "v1" , hugo : true});
|
||||
vertex1.save({ _key: "v2" ,hugo : true});
|
||||
vertex1.save({ _key: "v3" , heinz : 1});
|
||||
vertex1.save({ _key: "v4" , harald : "meier"});
|
||||
vertex2.save({ _key: "v5" , ageing : true});
|
||||
vertex2.save({ _key: "v6" , harald : "meier", ageing : true});
|
||||
vertex2.save({ _key: "v7" ,harald : "meier"});
|
||||
vertex2.save({ _key: "v8" ,heinz : 1, harald : "meier"});
|
||||
|
||||
function makeEdge(from, to, collection) {
|
||||
collection.save(from, to, { what: from.split("/")[1] + "->" + to.split("/")[1] });
|
||||
}
|
||||
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v1", "UnitTestsAhuacatlVertex1/v2", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v2", "UnitTestsAhuacatlVertex1/v3", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v3", "UnitTestsAhuacatlVertex2/v5", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v2", "UnitTestsAhuacatlVertex2/v6", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex2/v6", "UnitTestsAhuacatlVertex2/v7", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v4", "UnitTestsAhuacatlVertex2/v7", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v3", "UnitTestsAhuacatlVertex2/v7", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex2/v8", "UnitTestsAhuacatlVertex1/v1", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v3", "UnitTestsAhuacatlVertex2/v5", edge1);
|
||||
makeEdge("UnitTestsAhuacatlVertex1/v3", "UnitTestsAhuacatlVertex2/v8", edge1);
|
||||
|
||||
try {
|
||||
db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
graph._create(
|
||||
"bla3",
|
||||
graph._edgeDefinitions(
|
||||
graph._directedRelationDefinition("UnitTestsAhuacatlEdge1",
|
||||
["UnitTestsAhuacatlVertex1", "UnitTestsAhuacatlVertex2"],
|
||||
["UnitTestsAhuacatlVertex1", "UnitTestsAhuacatlVertex2"]
|
||||
)
|
||||
)
|
||||
);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tear down
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
tearDown: function () {
|
||||
db._drop("UnitTestsAhuacatlVertex1");
|
||||
db._drop("UnitTestsAhuacatlVertex2");
|
||||
db._drop("UnitTestsAhuacatlEdge1");
|
||||
try {
|
||||
db._collection("_graphs").remove("_graphs/bla3")
|
||||
} catch (err) {
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks GRAPH_COMMON_NEIGHBORS() and GRAPH_COMMON_PROPERTIES()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testEdgesAny: function () {
|
||||
actual = getQueryResults("FOR e IN GRAPH_COMMON_NEIGHBORS('bla3', 'UnitTestsAhuacatlVertex1/v3' , 'UnitTestsAhuacatlVertex2/v6', {direction : 'any'}) SORT ATTRIBUTES(e)[0] RETURN e");
|
||||
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v3"]["UnitTestsAhuacatlVertex2/v6"][0]._id , "UnitTestsAhuacatlVertex1/v2");
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v3"]["UnitTestsAhuacatlVertex2/v6"][1]._id , "UnitTestsAhuacatlVertex2/v7");
|
||||
|
||||
},
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks GRAPH_COMMON_NEIGHBORS()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testEdgesIn: function () {
|
||||
|
||||
actual = getQueryResults("FOR e IN GRAPH_COMMON_NEIGHBORS('bla3', {} , {}, {direction : 'inbound'}) SORT ATTRIBUTES(e)[0] RETURN e");
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v3"]["UnitTestsAhuacatlVertex2/v6"][0]._id , "UnitTestsAhuacatlVertex1/v2");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex2/v5"]["UnitTestsAhuacatlVertex2/v8"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex2/v5"]["UnitTestsAhuacatlVertex2/v7"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
|
||||
|
||||
assertEqual(actual[2]["UnitTestsAhuacatlVertex2/v6"]["UnitTestsAhuacatlVertex1/v3"][0]._id , "UnitTestsAhuacatlVertex1/v2");
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex2/v7"]["UnitTestsAhuacatlVertex2/v5"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex2/v7"]["UnitTestsAhuacatlVertex2/v8"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
|
||||
assertEqual(actual[4]["UnitTestsAhuacatlVertex2/v8"]["UnitTestsAhuacatlVertex2/v5"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
assertEqual(actual[4]["UnitTestsAhuacatlVertex2/v8"]["UnitTestsAhuacatlVertex2/v7"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
|
||||
},
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks GRAPH_COMMON_NEIGHBORS()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testEdgesOut: function () {
|
||||
actual = getQueryResults("FOR e IN GRAPH_COMMON_NEIGHBORS('bla3', { hugo : true } , {heinz : 1}, {direction : 'outbound', minDepth : 1, maxDepth : 3}) SORT e RETURN e");
|
||||
assertEqual(Object.keys(actual[0])[0] , "UnitTestsAhuacatlVertex1/v2");
|
||||
assertEqual(Object.keys(actual[0][Object.keys(actual[0])[0]]) , ["UnitTestsAhuacatlVertex2/v8", "UnitTestsAhuacatlVertex1/v3"]);
|
||||
|
||||
assertEqual(actual[0][Object.keys(actual[0])[0]]["UnitTestsAhuacatlVertex2/v8"].length , 3);
|
||||
assertEqual(actual[0][Object.keys(actual[0])[0]]["UnitTestsAhuacatlVertex1/v3"].length , 4);
|
||||
|
||||
assertEqual(Object.keys(actual[1])[0] , "UnitTestsAhuacatlVertex1/v1");
|
||||
assertEqual(Object.keys(actual[1][Object.keys(actual[1])[0]]) , ["UnitTestsAhuacatlVertex1/v3", "UnitTestsAhuacatlVertex2/v8"]);
|
||||
|
||||
assertEqual(actual[1][Object.keys(actual[1])[0]]["UnitTestsAhuacatlVertex1/v3"].length , 4);
|
||||
assertEqual(actual[1][Object.keys(actual[1])[0]]["UnitTestsAhuacatlVertex2/v8"].length , 3);
|
||||
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief checks GRAPH_COMMON_PROPERTIES()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testCommonProperties: function () {
|
||||
actual = getQueryResults("FOR e IN GRAPH_COMMON_PROPERTIES('bla3', { } , {}, {}) SORT ATTRIBUTES(e)[0] RETURN e");
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v1"][0]._id , "UnitTestsAhuacatlVertex1/v2");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex1/v2"][0]._id , "UnitTestsAhuacatlVertex1/v1");
|
||||
assertEqual(actual[2]["UnitTestsAhuacatlVertex1/v3"][0]._id , "UnitTestsAhuacatlVertex2/v8");
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex1/v4"][0]._id , "UnitTestsAhuacatlVertex2/v6");
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex1/v4"][1]._id , "UnitTestsAhuacatlVertex2/v8");
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex1/v4"][2]._id , "UnitTestsAhuacatlVertex2/v7");
|
||||
|
||||
assertEqual(actual[4]["UnitTestsAhuacatlVertex2/v5"][0]._id , "UnitTestsAhuacatlVertex2/v6");
|
||||
assertEqual(actual[5]["UnitTestsAhuacatlVertex2/v6"][0]._id , "UnitTestsAhuacatlVertex1/v4");
|
||||
assertEqual(actual[5]["UnitTestsAhuacatlVertex2/v6"][1]._id , "UnitTestsAhuacatlVertex2/v5");
|
||||
assertEqual(actual[5]["UnitTestsAhuacatlVertex2/v6"][2]._id , "UnitTestsAhuacatlVertex2/v8");
|
||||
assertEqual(actual[5]["UnitTestsAhuacatlVertex2/v6"][3]._id , "UnitTestsAhuacatlVertex2/v7");
|
||||
|
||||
|
||||
assertEqual(actual[6]["UnitTestsAhuacatlVertex2/v7"][0]._id , "UnitTestsAhuacatlVertex1/v4");
|
||||
assertEqual(actual[6]["UnitTestsAhuacatlVertex2/v7"][1]._id , "UnitTestsAhuacatlVertex2/v6");
|
||||
assertEqual(actual[6]["UnitTestsAhuacatlVertex2/v7"][2]._id , "UnitTestsAhuacatlVertex2/v8");
|
||||
|
||||
assertEqual(actual[7]["UnitTestsAhuacatlVertex2/v8"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
assertEqual(actual[7]["UnitTestsAhuacatlVertex2/v8"][1]._id , "UnitTestsAhuacatlVertex1/v4");
|
||||
assertEqual(actual[7]["UnitTestsAhuacatlVertex2/v8"][2]._id , "UnitTestsAhuacatlVertex2/v6");
|
||||
assertEqual(actual[7]["UnitTestsAhuacatlVertex2/v8"][3]._id , "UnitTestsAhuacatlVertex2/v7");
|
||||
|
||||
},
|
||||
|
||||
testCommonPropertiesWithFilters: function () {
|
||||
actual = getQueryResults("FOR e IN GRAPH_COMMON_PROPERTIES('bla3', {ageing : true} , {harald : 'meier'}, {}) SORT ATTRIBUTES(e)[0] RETURN e");
|
||||
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex2/v5"][0]._id , "UnitTestsAhuacatlVertex2/v6");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex2/v6"][0]._id , "UnitTestsAhuacatlVertex1/v4");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex2/v6"][1]._id , "UnitTestsAhuacatlVertex2/v8");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex2/v6"][2]._id , "UnitTestsAhuacatlVertex2/v7");
|
||||
|
||||
},
|
||||
|
||||
testCommonPropertiesWithFiltersAndIgnoringKeyHarald: function () {
|
||||
actual = getQueryResults("FOR e IN GRAPH_COMMON_PROPERTIES('bla3', {} , {}, {ignoreProperties : 'harald'}) SORT ATTRIBUTES(e)[0] RETURN e");
|
||||
|
||||
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v1"][0]._id , "UnitTestsAhuacatlVertex1/v2");
|
||||
assertEqual(actual[1]["UnitTestsAhuacatlVertex1/v2"][0]._id , "UnitTestsAhuacatlVertex1/v1");
|
||||
assertEqual(actual[2]["UnitTestsAhuacatlVertex1/v3"][0]._id , "UnitTestsAhuacatlVertex2/v8");
|
||||
|
||||
assertEqual(actual[3]["UnitTestsAhuacatlVertex2/v5"][0]._id , "UnitTestsAhuacatlVertex2/v6");
|
||||
|
||||
assertEqual(actual[4]["UnitTestsAhuacatlVertex2/v6"][0]._id , "UnitTestsAhuacatlVertex2/v5");
|
||||
assertEqual(actual[5]["UnitTestsAhuacatlVertex2/v8"][0]._id , "UnitTestsAhuacatlVertex1/v3");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test suite for GRAPH_PATHS() function
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -599,6 +784,7 @@ function ahuacatlQueryGeneralTraversalTestSuite() {
|
|||
/// @brief executes the test suite
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
jsunity.run(ahuacatlQueryGeneralCommonTestSuite);
|
||||
jsunity.run(ahuacatlQueryGeneralTraversalTestSuite);
|
||||
jsunity.run(ahuacatlQueryGeneralEdgesTestSuite);
|
||||
jsunity.run(ahuacatlQueryGeneralPathsTestSuite);
|
||||
|
|
Loading…
Reference in New Issue