1
0
Fork 0

Fixed all GRAPH_NEIGHBOR tests for new format. GRAPH_EDGES still failing. CPP MATCHER still not able to match internal attributes

This commit is contained in:
Michael Hackstein 2015-05-28 15:18:24 -07:00
parent 1ca771f304
commit 4dbf8b454d
2 changed files with 168 additions and 126 deletions

View File

@ -6118,18 +6118,19 @@ function AQL_GRAPH_SHORTEST_PATH (graphName,
let graph_module = require("org/arangodb/general-graph");
let graph = graph_module._graph(graphName);
let edgeCollections;
let edgeCollections = graph._edgeCollections().map(function (c) { return c.name();});
if (options.hasOwnProperty("edgeCollectionRestriction")) {
if (!Array.isArray(options.edgeCollectionRestriction)) {
if (typeof options.edgeCollectionRestriction === "string") {
if (!underscore.contains(edgeCollections, options.edgeCollectionRestriction)) {
// Short circut collection not in graph, cannot find results.
return [];
}
edgeCollections = [options.edgeCollectionRestriction];
}
} else {
// TODO: Intersect?
edgeCollections = options.edgeCollectionRestriction;
edgeCollections = underscore.intersection(edgeCollections, options.edgeCollectionRestriction);
}
} else {
edgeCollections = graph._edgeCollections().map(function (c) { return c.name();});
}
let vertexCollections = graph._vertexCollections().map(function (c) { return c.name();});
@ -6602,33 +6603,6 @@ function FILTERED_EDGES (edges, vertex, direction, examples) {
/// @brief return connected neighbors
////////////////////////////////////////////////////////////////////////////////
function useCXXforDeepNeighbors (vertexCollections, edgeCollections,
vertex, options) {
'use strict';
let db = require("internal").db;
let l = [vertex];
let s = new Set();
s.add(vertex);
for (let dist = 1; dist <= options.distance; ++dist) {
let ll = CPP_NEIGHBORS(vertexCollections, edgeCollections,
l, {distinct: true, includeData: false,
direction: options.direction});
l = [];
for (let i = 0; i < ll.length; ++i) {
if (! s.has(ll[i])) {
l.push(ll[i]);
s.add(ll[i]);
}
}
}
if (options.includeData) {
for (let j = 0; j < l.length; ++j) {
l[j] = db._document(l[j]);
}
}
return l;
}
function AQL_NEIGHBORS (vertexCollection,
edgeCollection,
vertex,
@ -6649,14 +6623,7 @@ function AQL_NEIGHBORS (vertexCollection,
if (examples !== undefined && Array.isArray(examples) && examples.length > 0) {
options.examples = examples;
}
if (typeof options.distance === "number" && options.distance > 1) {
return useCXXforDeepNeighbors([vertexCollection], [edgeCollection], vertex,
options);
}
else {
return CPP_NEIGHBORS([vertexCollection], [edgeCollection], vertex,
options);
}
return CPP_NEIGHBORS([vertexCollection], [edgeCollection], vertex, options);
}
////////////////////////////////////////////////////////////////////////////////
@ -6817,18 +6784,19 @@ function AQL_GRAPH_NEIGHBORS (graphName,
let graph_module = require("org/arangodb/general-graph");
let graph = graph_module._graph(graphName);
let edgeCollections;
let edgeCollections = graph._edgeCollections().map(function (c) { return c.name();});
if (options.hasOwnProperty("edgeCollectionRestriction")) {
if (!Array.isArray(options.edgeCollectionRestriction)) {
if (typeof options.edgeCollectionRestriction === "string") {
if (!underscore.contains(edgeCollections, options.edgeCollectionRestriction)) {
// Short circut collection not in graph, cannot find results.
return [];
}
edgeCollections = [options.edgeCollectionRestriction];
}
} else {
// TODO: Intersect?
edgeCollections = options.edgeCollectionRestriction;
edgeCollections = underscore.intersection(edgeCollections, options.edgeCollectionRestriction);
}
} else {
edgeCollections = graph._edgeCollections().map(function (c) { return c.name();});
}
let vertexCollections = graph._vertexCollections().map(function (c) { return c.name();});
let startVertices = DOCUMENT_IDS_BY_EXAMPLE(vertexCollections, vertexExample);
@ -6838,27 +6806,28 @@ function AQL_GRAPH_NEIGHBORS (graphName,
if (options.hasOwnProperty("vertexCollectionRestriction")) {
if (!Array.isArray(options.vertexCollectionRestriction)) {
if (typeof options.vertexCollectionRestriction === "string") {
if (!underscore.contains(vertexCollections, options.vertexCollectionRestriction)) {
// Short circut collection not in graph, cannot find results.
return [];
}
vertexCollections = [options.vertexCollectionRestriction];
}
} else {
// TODO: Intersect?
vertexCollections = options.vertexCollectionRestriction;
vertexCollections = underscore.intersection(vertexCollections, options.vertexCollectionRestriction);
}
}
if (options.hasOwnProperty("minDepth")) {
params.minDepth = options.minDepth;
}
if (options.hasOwnProperty("maxDepth")) {
params.maxDepth = options.maxDepth;
}
if (options.hasOwnProperty("includeData")) {
params.includeData = options.includeData;
}
/*
if (typeof options.distance === "number" && options.distance > 1) {
return useCXXforDeepNeighbors([vertexCollection], [edgeCollection], vertex,
params);
}
else {
*/
return CPP_NEIGHBORS(vertexCollections, edgeCollections, startVertices,
params);
/*
}
*/
return CPP_NEIGHBORS(vertexCollections, edgeCollections, startVertices, params);
}
@ -6903,6 +6872,7 @@ function AQL_GRAPH_NEIGHBORS (graphName,
/// be returned).
/// * *maxIterations*: the maximum number of iterations that the traversal is
/// allowed to perform. It is sensible to set this number so unbounded traversals
/// will terminate.
///
/// @EXAMPLES
///
@ -7083,42 +7053,21 @@ function AQL_GRAPH_COMMON_NEIGHBORS (graphName,
options1 = options1 || {};
options1.includeData = false;
options1.distinct = true;
options2 = options2 || {};
options2.includeData = false;
options2.distinct = true;
let vertexCollections1;
if (options1.hasOwnProperty("vertexCollectionRestriction")) {
if (!Array.isArray(options1.vertexCollectionRestriction)) {
if (typeof options1.vertexCollectionRestriction === "string") {
vertexCollections1 = [options1.vertexCollectionRestriction];
}
} else {
// TODO: Intersect?
vertexCollections1 = options1.vertexCollectionRestriction;
}
}
let vertices1 = DOCUMENT_IDS_BY_EXAMPLE(vertexCollections1, vertex1Examples);
let graph_module = require("org/arangodb/general-graph");
let graph = graph_module._graph(graphName);
let vertexCollections = graph._vertexCollections().map(function (c) { return c.name();});
let vertices1 = DOCUMENT_IDS_BY_EXAMPLE(vertexCollections, vertex1Examples);
let vertices2;
if (vertex1Examples === vertex2Examples &&
options1.vertexCollectionRestriction === options2.vertexCollectionRestriction) {
if (vertex1Examples === vertex2Examples) {
vertices2 = vertices1;
} else {
let vertexCollections2;
if (options2.hasOwnProperty("vertexCollectionRestriction")) {
if (!Array.isArray(options2.vertexCollectionRestriction)) {
if (typeof options2.vertexCollectionRestriction === "string") {
vertexCollections2 = [options2.vertexCollectionRestriction];
}
} else {
// TODO: Intersect?
vertexCollections2 = options2.vertexCollectionRestriction;
}
}
vertices2 = DOCUMENT_IDS_BY_EXAMPLE(vertexCollections2, vertex2Examples);
vertices2 = DOCUMENT_IDS_BY_EXAMPLE(vertexCollections, vertex2Examples);
}
// Use ES6 Map. Higher performance then Object.
let tmpNeighbors = new Map();
let tmpNeighborsLeft = new Map();
let tmpNeighborsRight = new Map();
let result = [];
// Legacy Format
@ -7129,36 +7078,41 @@ function AQL_GRAPH_COMMON_NEIGHBORS (graphName,
// For each entry iterate over right side vertex list as right.
// Calculate their neighbors as rn
// For each store one entry in result {left: left, right: right, neighbors: intersection(ln, rn)}
// All Neighbors are cached in tmpNeighbors
// All Neighbors are cached in tmpNeighborsLeft and tmpNeighborsRight resp.
for (let i = 0; i < vertices1.length; ++i) {
let left = vertices1[i];
let itemNeighbors;
if(tmpNeighbors.has(left)) {
itemNeighbors = tmpNeighbors.get(left);
if(tmpNeighborsLeft.has(left)) {
itemNeighbors = tmpNeighborsLeft.get(left);
} else {
itemNeighbors = AQL_GRAPH_NEIGHBORS(graphName, left, options1);
tmpNeighbors.set(left, itemNeighbors);
tmpNeighborsLeft.set(left, itemNeighbors);
}
for (let j = 0; j < vertices2.length; ++j) {
let right = vertices2[j];
if (left === right) {
continue;
}
let rNeighbors;
if(tmpNeighbors.has(right)) {
rNeighbors = tmpNeighbors.get(right);
if(tmpNeighborsRight.has(right)) {
rNeighbors = tmpNeighborsRight.get(right);
} else {
rNeighbors = AQL_GRAPH_NEIGHBORS(graphName, right, options2);
tmpNeighbors.set(right, rNeighbors);
tmpNeighborsRight.set(right, rNeighbors);
}
let neighbors = underscore.intersection(itemNeighbors, rNeighbors);
// Legacy Format
// tmpRes[left] = tmpRes[left] || {};
// tmpRes[left][right] = neighbors;
result.push({left, right, neighbors});
if (neighbors.length > 0) {
// Legacy Format
// tmpRes[left] = tmpRes[left] || {};
// tmpRes[left][right] = neighbors;
result.push({left, right, neighbors});
}
}
}
// Legacy Format
// result.push(tmpRes);
tmpNeighbors.clear();
tmpNeighborsLeft.clear();
tmpNeighborsRight.clear();
return result;
}

View File

@ -802,6 +802,9 @@ function ahuacatlQueryGeneralEdgesTestSuite() {
function ahuacatlQueryGeneralCommonTestSuite() {
var vertexIds = {};
return {
////////////////////////////////////////////////////////////////////////////////
@ -817,29 +820,38 @@ function ahuacatlQueryGeneralCommonTestSuite() {
var vertex2 = db._create("UnitTestsAhuacatlVertex2");
var 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"});
var v1 = vertex1.save({ _key: "v1", hugo: true})._id;
var v2 = vertex1.save({ _key: "v2", hugo: true})._id;
var v3 = vertex1.save({ _key: "v3", heinz: 1})._id;
var v4 = vertex1.save({ _key: "v4", harald: "meier"})._id;
var v5 = vertex2.save({ _key: "v5", ageing: true})._id;
var v6 = vertex2.save({ _key: "v6", harald: "meier", ageing: true})._id;
var v7 = vertex2.save({ _key: "v7", harald: "meier"})._id;
var v8 = vertex2.save({ _key: "v8", heinz: 1, harald: "meier"})._id;
vertexIds.v1 = v1;
vertexIds.v2 = v2;
vertexIds.v3 = v3;
vertexIds.v4 = v4;
vertexIds.v5 = v5;
vertexIds.v6 = v6;
vertexIds.v7 = v7;
vertexIds.v8 = v8;
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);
makeEdge(v1, v2, edge1);
makeEdge(v2, v3, edge1);
makeEdge(v3, v5, edge1);
makeEdge(v2, v6, edge1);
makeEdge(v6, v7, edge1);
makeEdge(v4, v7, edge1);
makeEdge(v3, v7, edge1);
makeEdge(v8, v1, edge1);
makeEdge(v3, v5, edge1);
makeEdge(v3, v8, edge1);
try {
db._collection("_graphs").remove("_graphs/bla3");
@ -875,10 +887,15 @@ function ahuacatlQueryGeneralCommonTestSuite() {
////////////////////////////////////////////////////////////////////////////////
testCommonNeighbors: function () {
var actual = getQueryResults("FOR e IN GRAPH_COMMON_NEIGHBORS('bla3', 'UnitTestsAhuacatlVertex1/v3' , 'UnitTestsAhuacatlVertex2/v6', {direction : 'any'}) SORT ATTRIBUTES(e)[0] RETURN e");
var actual = getQueryResults("FOR e IN GRAPH_COMMON_NEIGHBORS('bla3', 'UnitTestsAhuacatlVertex1/v3' , 'UnitTestsAhuacatlVertex2/v6', {direction : 'any'}) SORT e.left RETURN e");
assertEqual(actual.length, 1);
assertEqual(actual[0].left, vertexIds.v3);
assertEqual(actual[0].right, vertexIds.v6);
assertEqual(actual[0].neighbors.sort(), [vertexIds.v2, vertexIds.v7].sort());
/* Legacy
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v3"]["UnitTestsAhuacatlVertex2/v6"][0]._id, "UnitTestsAhuacatlVertex1/v2");
assertEqual(actual[0]["UnitTestsAhuacatlVertex1/v3"]["UnitTestsAhuacatlVertex2/v6"][1]._id, "UnitTestsAhuacatlVertex2/v7");
*/
},
////////////////////////////////////////////////////////////////////////////////
@ -886,8 +903,42 @@ function ahuacatlQueryGeneralCommonTestSuite() {
////////////////////////////////////////////////////////////////////////////////
testCommonNeighborsIn: function () {
var actual = getQueryResults("FOR e IN GRAPH_COMMON_NEIGHBORS('bla3', {} , {}, {direction : 'inbound'}, {direction : 'inbound'}) SORT TO_STRING(ATTRIBUTES(e)) RETURN e");
var actual = getQueryResults("FOR e IN GRAPH_COMMON_NEIGHBORS('bla3', {} , {}, {direction : 'inbound'}, {direction : 'inbound'}) SORT e.left, e.right RETURN e");
assertEqual(actual.length, 8, "We expect one entry for each pair of vertices having at least one common neighbor");
assertEqual(actual[0].left, vertexIds.v3);
assertEqual(actual[0].right, vertexIds.v6);
assertEqual(actual[0].neighbors.sort(), [vertexIds.v2].sort());
assertEqual(actual[1].left, vertexIds.v5);
assertEqual(actual[1].right, vertexIds.v7);
assertEqual(actual[1].neighbors.sort(), [vertexIds.v3].sort());
assertEqual(actual[2].left, vertexIds.v5);
assertEqual(actual[2].right, vertexIds.v8);
assertEqual(actual[2].neighbors.sort(), [vertexIds.v3].sort());
assertEqual(actual[3].left, vertexIds.v6);
assertEqual(actual[3].right, vertexIds.v3);
assertEqual(actual[3].neighbors.sort(), [vertexIds.v2].sort());
assertEqual(actual[4].left, vertexIds.v7);
assertEqual(actual[4].right, vertexIds.v5);
assertEqual(actual[4].neighbors.sort(), [vertexIds.v3].sort());
assertEqual(actual[5].left, vertexIds.v7);
assertEqual(actual[5].right, vertexIds.v8);
assertEqual(actual[5].neighbors.sort(), [vertexIds.v3].sort());
assertEqual(actual[6].left, vertexIds.v8);
assertEqual(actual[6].right, vertexIds.v5);
assertEqual(actual[6].neighbors.sort(), [vertexIds.v3].sort());
assertEqual(actual[7].left, vertexIds.v8);
assertEqual(actual[7].right, vertexIds.v7);
assertEqual(actual[7].neighbors.sort(), [vertexIds.v3].sort());
/* Legacy
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");
@ -899,6 +950,7 @@ function ahuacatlQueryGeneralCommonTestSuite() {
assertEqual(actual[4]["UnitTestsAhuacatlVertex2/v8"]["UnitTestsAhuacatlVertex2/v5"][0]._id, "UnitTestsAhuacatlVertex1/v3");
assertEqual(actual[4]["UnitTestsAhuacatlVertex2/v8"]["UnitTestsAhuacatlVertex2/v7"][0]._id, "UnitTestsAhuacatlVertex1/v3");
*/
},
////////////////////////////////////////////////////////////////////////////////
@ -907,7 +959,27 @@ function ahuacatlQueryGeneralCommonTestSuite() {
testCommonNeighborsOut: function () {
var actual = getQueryResults("FOR e IN GRAPH_COMMON_NEIGHBORS('bla3', { hugo : true } , {heinz : 1}, " +
" {direction : 'outbound', minDepth : 1, maxDepth : 3}, {direction : 'outbound', minDepth : 1, maxDepth : 3}) SORT e RETURN e");
" {direction : 'outbound', minDepth : 1, maxDepth : 3}, {direction : 'outbound', minDepth : 1, maxDepth : 3}) SORT e.left, e.right RETURN e");
assertEqual(actual.length, 4, "Expect one result for each pair of vertices sharing neighbors");
assertEqual(actual[0].left, vertexIds.v1);
assertEqual(actual[0].right, vertexIds.v3);
assertEqual(actual[0].neighbors.sort(), [vertexIds.v2, vertexIds.v5, vertexIds.v7, vertexIds.v8].sort());
assertEqual(actual[1].left, vertexIds.v1);
assertEqual(actual[1].right, vertexIds.v8);
assertEqual(actual[1].neighbors.sort(), [vertexIds.v2, vertexIds.v3, vertexIds.v6].sort());
assertEqual(actual[2].left, vertexIds.v2);
assertEqual(actual[2].right, vertexIds.v3);
assertEqual(actual[2].neighbors.sort(), [vertexIds.v1, vertexIds.v5, vertexIds.v7, vertexIds.v8].sort());
assertEqual(actual[3].left, vertexIds.v2);
assertEqual(actual[3].right, vertexIds.v8);
assertEqual(actual[3].neighbors.sort(), [vertexIds.v1, vertexIds.v6, vertexIds.v3].sort());
/* Legacy
assertEqual(Object.keys(actual[0])[0], "UnitTestsAhuacatlVertex1/v2");
assertEqual(Object.keys(actual[0][Object.keys(actual[0])[0]]), ["UnitTestsAhuacatlVertex2/v8", "UnitTestsAhuacatlVertex1/v3"]);
@ -919,6 +991,7 @@ function ahuacatlQueryGeneralCommonTestSuite() {
assertEqual(actual[1][Object.keys(actual[1])[0]]["UnitTestsAhuacatlVertex1/v3"].length, 4);
assertEqual(actual[1][Object.keys(actual[1])[0]]["UnitTestsAhuacatlVertex2/v8"].length, 3);
*/
},
@ -929,15 +1002,29 @@ function ahuacatlQueryGeneralCommonTestSuite() {
testCommonNeighborsMixedOptionsDistinctFilters: function () {
var actual = getQueryResults("FOR e IN GRAPH_COMMON_NEIGHBORS('bla3', {} , {}, " +
"{direction : 'outbound', vertexCollectionRestriction : 'UnitTestsAhuacatlVertex1'}, " +
"{direction : 'inbound', minDepth : 1, maxDepth : 2, vertexCollectionRestriction : 'UnitTestsAhuacatlVertex2'}) SORT TO_STRING(e) RETURN e");
assertEqual(actual.length, 0);
"{direction : 'inbound', minDepth : 1, maxDepth : 2, vertexCollectionRestriction : 'UnitTestsAhuacatlVertex2'}) SORT e.left, e.right RETURN e");
assertEqual(actual.length, 0, "Expect one result for each pair of vertices sharing neighbors");
},
testCommonNeighborsMixedOptionsFilterBasedOnOneCollectionOnly: function () {
var actual = getQueryResults("FOR e IN GRAPH_COMMON_NEIGHBORS('bla3', {} , {}, " +
"{direction : 'outbound', vertexCollectionRestriction : 'UnitTestsAhuacatlVertex2'}, " +
"{direction : 'inbound', minDepth : 1, maxDepth : 2, vertexCollectionRestriction : 'UnitTestsAhuacatlVertex2'}) SORT TO_STRING(e) RETURN e");
"{direction : 'inbound', minDepth : 1, maxDepth : 2, vertexCollectionRestriction : 'UnitTestsAhuacatlVertex2'}) SORT e.left, e.right RETURN e");
assertEqual(actual.length, 3, "Expect one result for each pair of vertices sharing neighbors");
assertEqual(actual[0].left, vertexIds.v2);
assertEqual(actual[0].right, vertexIds.v7);
assertEqual(actual[0].neighbors.sort(), [vertexIds.v6].sort());
assertEqual(actual[1].left, vertexIds.v3);
assertEqual(actual[1].right, vertexIds.v1);
assertEqual(actual[1].neighbors.sort(), [vertexIds.v8].sort());
assertEqual(actual[2].left, vertexIds.v3);
assertEqual(actual[2].right, vertexIds.v2);
assertEqual(actual[2].neighbors.sort(), [vertexIds.v8].sort());
/* Legacy
assertEqual(Object.keys(actual[0])[0], "UnitTestsAhuacatlVertex1/v3");
assertEqual(Object.keys(actual[0][Object.keys(actual[0])[0]]).sort(), ["UnitTestsAhuacatlVertex1/v1", "UnitTestsAhuacatlVertex1/v2"]);
@ -948,6 +1035,7 @@ function ahuacatlQueryGeneralCommonTestSuite() {
assertEqual(Object.keys(actual[1][Object.keys(actual[1])[0]]).sort(), ["UnitTestsAhuacatlVertex2/v7"]);
assertEqual(actual[1][Object.keys(actual[1])[0]]["UnitTestsAhuacatlVertex2/v7"].length, 1);
*/
},