mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of github.com:triAGENS/ArangoDB into devel
This commit is contained in:
commit
c563756a35
|
@ -211,9 +211,14 @@ AQLStatement.prototype.isVertexQuery = function() {
|
|||
return this.type === "vertex";
|
||||
};
|
||||
|
||||
AQLStatement.prototype.isNeighborQuery = function() {
|
||||
return this.type === "neighbor";
|
||||
};
|
||||
|
||||
AQLStatement.prototype.allowsRestrict = function() {
|
||||
return this.isEdgeQuery()
|
||||
|| this.isVertexQuery();
|
||||
|| this.isVertexQuery()
|
||||
|| this.isNeighborQuery();
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -352,18 +357,20 @@ AQLGenerator.prototype.getLastVar = function() {
|
|||
return this.lastVar;
|
||||
};
|
||||
|
||||
AQLGenerator.prototype.neighbors = function(startVertexExample, options) {
|
||||
var ex = transformExample(startVertexExample);
|
||||
var resultName = "neighbors_" + this.stack.length + ".vertices";
|
||||
AQLGenerator.prototype.neighbors = function(vertexExample, options) {
|
||||
var ex = transformExample(vertexExample);
|
||||
var resultName = "neighbors_" + this.stack.length;
|
||||
var query = "FOR " + resultName
|
||||
+ " IN GRAPH_NEIGHBORS(@graphName,@startVertexExample_"
|
||||
+ this.stack.length + ',@options_'
|
||||
+ " IN GRAPH_NEIGHBORS(@graphName,"
|
||||
+ this.getLastVar()
|
||||
+ ',@options_'
|
||||
+ this.stack.length + ')';
|
||||
this.bindVars["startVertexExample_" + this.stack.length] = ex;
|
||||
options = options || {};
|
||||
options.vertexExamples = ex;
|
||||
this.bindVars["options_" + this.stack.length] = options;
|
||||
var stmt = new AQLStatement(query, true);
|
||||
var stmt = new AQLStatement(query, "neighbor");
|
||||
this.stack.push(stmt);
|
||||
this.lastEdgeVar = resultName;
|
||||
this.lastVar = resultName + ".vertex";
|
||||
return this;
|
||||
};
|
||||
|
||||
|
@ -393,7 +400,7 @@ AQLGenerator.prototype.restrict = function(restrictions) {
|
|||
);
|
||||
restricts = opts.edgeCollectionRestriction || [];
|
||||
opts.edgeCollectionRestriction = restricts.concat(restrictions);
|
||||
} else if (lastQuery.isVertexQuery()) {
|
||||
} else if (lastQuery.isVertexQuery() || lastQuery.isNeighborQuery()) {
|
||||
checkAllowsRestriction(
|
||||
this.graph.__vertexCollections,
|
||||
rest,
|
||||
|
@ -874,7 +881,7 @@ Graph.prototype._EDGES = function(vertexId) {
|
|||
throw vertexId + " is not a valid id";
|
||||
}
|
||||
var collection = vertexId.split("/");
|
||||
if (!db._exists(collection)) {
|
||||
if (!db._collection(collection)) {
|
||||
throw collection + " does not exists.";
|
||||
}
|
||||
|
||||
|
@ -898,7 +905,7 @@ Graph.prototype._INEDGES = function(vertexId) {
|
|||
throw vertexId + " is not a valid id";
|
||||
}
|
||||
var collection = vertexId.split("/");
|
||||
if (!db._exists(collection)) {
|
||||
if (!db._collection(collection)) {
|
||||
throw collection + " does not exists.";
|
||||
}
|
||||
|
||||
|
@ -923,7 +930,7 @@ Graph.prototype._OUTEDGES = function(vertexId) {
|
|||
throw vertexId + " is not a valid id";
|
||||
}
|
||||
var collection = vertexId.split("/");
|
||||
if (!db._exists(collection)) {
|
||||
if (!db._collection(collection)) {
|
||||
throw collection + " does not exists.";
|
||||
}
|
||||
|
||||
|
|
|
@ -844,6 +844,14 @@ function ChainedFluentAQLResultsSuite() {
|
|||
+ "@options_" + depth + ")";
|
||||
};
|
||||
|
||||
var plainNeighborQueryStmt = function(depth, vdepth) {
|
||||
return "FOR neighbors_" + depth + " IN "
|
||||
+ "GRAPH_NEIGHBORS("
|
||||
+ "@graphName,"
|
||||
+ "vertices_" + vdepth + ","
|
||||
+ "@options_" + depth + ")";
|
||||
};
|
||||
|
||||
var vertexFilterStmt = function(direction, eDepth, vDepth) {
|
||||
switch(direction) {
|
||||
case "both":
|
||||
|
@ -874,12 +882,19 @@ function ChainedFluentAQLResultsSuite() {
|
|||
|
||||
};
|
||||
|
||||
var plainEdgesQueryStmt = function(depth, vDepth) {
|
||||
var plainEdgesQueryStmt = function(depth, vDepth, type) {
|
||||
if (!type) {
|
||||
type = "vertices";
|
||||
}
|
||||
var q = "FOR edges_" + depth + " IN "
|
||||
+ "GRAPH_EDGES("
|
||||
+ "@graphName,";
|
||||
if(vDepth > -1) {
|
||||
q += "vertices_" + vDepth + ",";
|
||||
q += type + "_" + vDepth;
|
||||
if (type === "neighbors") {
|
||||
q += ".vertex";
|
||||
}
|
||||
q += ",";
|
||||
} else {
|
||||
q += "{},";
|
||||
}
|
||||
|
@ -995,7 +1010,7 @@ function ChainedFluentAQLResultsSuite() {
|
|||
assertEqual(sorted[1].name, p1Name);
|
||||
},
|
||||
|
||||
test_getVerticiesByExampleAndIdMix: function() {
|
||||
test_getVerticiesByExampleAndIdMixResultingAQL: function() {
|
||||
var b_id = g[user].firstExample({name: ubName})._id;
|
||||
var query = g._vertices([{
|
||||
name: uaName
|
||||
|
@ -1395,7 +1410,103 @@ function ChainedFluentAQLResultsSuite() {
|
|||
var sorted = _.sortBy(result, "name");
|
||||
assertEqual(sorted[0].name, ubName);
|
||||
assertEqual(sorted[1].name, p1Name);
|
||||
},
|
||||
|
||||
test_getNeighborsOfSelectedVerticesResultingAQL: function() {
|
||||
var query = g._vertices({name: uaName})
|
||||
.neighbors();
|
||||
var stmt = query.printQuery();
|
||||
var expected = [];
|
||||
expected.push(plainVertexQueryStmt(0));
|
||||
expected.push(plainNeighborQueryStmt(1, 0));
|
||||
assertEqual(stmt, expected.join(" "));
|
||||
assertEqual(query.bindVars.options_0, {});
|
||||
assertEqual(query.bindVars.options_1, {
|
||||
vertexExamples: {}
|
||||
});
|
||||
},
|
||||
|
||||
test_getNeighborsOfSelectedVertices: function() {
|
||||
var result = g._vertices({name: uaName})
|
||||
.neighbors()
|
||||
.toArray();
|
||||
assertEqual(result.length, 3);
|
||||
var sorted = _.sortBy(result, "name");
|
||||
assertEqual(sorted[0].name, ubName);
|
||||
assertEqual(sorted[1].name, ucName);
|
||||
assertEqual(sorted[2].name, p1Name);
|
||||
},
|
||||
|
||||
test_getExampleNeighborsOfSelectedVerticesResultingAQL: function() {
|
||||
var query = g._vertices({name: uaName})
|
||||
.neighbors([{
|
||||
name: uaName
|
||||
},{
|
||||
name: p1Name
|
||||
}]);
|
||||
var stmt = query.printQuery();
|
||||
var expected = [];
|
||||
expected.push(plainVertexQueryStmt(0));
|
||||
expected.push(plainNeighborQueryStmt(1, 0));
|
||||
assertEqual(stmt, expected.join(" "));
|
||||
assertEqual(query.bindVars.options_0, {});
|
||||
assertEqual(query.bindVars.options_1, {
|
||||
vertexExamples: [{
|
||||
name: uaName
|
||||
},{
|
||||
name: p1Name
|
||||
}]
|
||||
});
|
||||
},
|
||||
|
||||
/* Not yet working, neighbors requires vertex-examples in AQL
|
||||
|
||||
test_getExampleNeighborsOfSelectedVertices: function() {
|
||||
var result = g._vertices({name: uaName})
|
||||
.neighbors([{
|
||||
name: uaName
|
||||
},{
|
||||
name: p1Name
|
||||
}])
|
||||
.toArray();
|
||||
assertEqual(result.length, 2);
|
||||
var sorted = _.sortBy(result, "name");
|
||||
assertEqual(sorted[0].name, uaName);
|
||||
assertEqual(sorted[1].name, p1Name);
|
||||
},
|
||||
|
||||
*/
|
||||
|
||||
test_getEdgesOfNeighborsResultingAQL: function() {
|
||||
var query = g._vertices({name: uaName})
|
||||
.neighbors()
|
||||
.outEdges();
|
||||
var stmt = query.printQuery();
|
||||
var expected = [];
|
||||
expected.push(plainVertexQueryStmt(0));
|
||||
expected.push(plainNeighborQueryStmt(1, 0));
|
||||
expected.push(plainEdgesQueryStmt(2, 1, "neighbors"));
|
||||
assertEqual(stmt, expected.join(" "));
|
||||
assertEqual(query.bindVars.options_0, {});
|
||||
assertEqual(query.bindVars.options_1, {
|
||||
vertexExamples: {}
|
||||
});
|
||||
assertEqual(query.bindVars.options_2, {
|
||||
direction: "outbound",
|
||||
edgeExamples: [{}]
|
||||
});
|
||||
},
|
||||
|
||||
test_getEdgesOfNeighbors: function() {
|
||||
var result = g._vertices({name: uaName})
|
||||
.neighbors()
|
||||
.outEdges()
|
||||
.toArray();
|
||||
assertEqual(result.length, 4);
|
||||
findFriends(result, [ud3, ud4]);
|
||||
findBoughts(result, [d2, d3]);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue