Skip to content

Commit 08e2260

Browse files
neunhoefjsteemann
andauthored
New test for traversal projections (#47)
* Add a test for traversal projections. * Do three different sizes. * Add silent. --------- Co-authored-by: jsteemann <jsteemann@users.noreply.github.com>
1 parent 345f2df commit 08e2260

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

simple/BIGvertices.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// This script can create a binary tree in ArangoDB with relatively large
2+
// vertex documents (approx. 1 MB each). You can give the depth and you can
3+
// choose what type of graph to create.
4+
//
5+
// Usage:
6+
//
7+
// makeGraph("G", "V", "E") - creates a general graph with name G, vertex
8+
// collection V and edge collection E
9+
// makeTree(6, "V", "E") - creates the actual tree after the graph was created
10+
// 6 is the depth and one has to name the vertex and
11+
// edge collections
12+
//
13+
// The following AQL query and its performance could be of interest:
14+
//
15+
// FOR v IN 0..6 OUTBOUND "V/S1:K1" GRAPH "G"
16+
// RETURN v.data
17+
//
18+
// This traverses the whole graph starting from the root but retrieves only
19+
// a tiny part of the vertex data. This tests the 3.10 feature of
20+
// traversal projections. You can see that it does this from this explain
21+
// output for the above query:
22+
//
23+
// Query String (58 chars, cacheable: true):
24+
// FOR v IN 0..6 OUTBOUND "V/S1:K1" GRAPH "G"
25+
// RETURN v.data
26+
//
27+
// Execution plan:
28+
// Id NodeType Site Est. Comment
29+
// 1 SingletonNode COOR 1 * ROOT
30+
// 2 TraversalNode COOR 64 - FOR v /* vertex (projections: `data`) */ IN 0..6 /* min..maxPathDepth */ OUTBOUND 'V/S1:K1' /* startnode */ GRAPH 'G'
31+
// 3 CalculationNode COOR 64 - LET #3 = v.`data` /* attribute expression */
32+
// 4 ReturnNode COOR 64 - RETURN #3
33+
//
34+
// In the line with Id 2 you can see that the TraversalNode uses a projection to the field `data`.
35+
//
36+
37+
rand = require("internal").rand;
38+
time = require("internal").time;
39+
40+
function makeRandomString(l) {
41+
var r = rand();
42+
var d = rand();
43+
var s = "x";
44+
for (var i = 0; i < l; ++i) {
45+
s += r;
46+
r += d;
47+
}
48+
return s;
49+
}
50+
51+
function makeGraph(graphName, vertexCollName, edgeCollName) {
52+
let graph = require("@arangodb/general-graph");
53+
try {
54+
graph._drop(graphName, true);
55+
}
56+
catch {
57+
}
58+
graph._create(graphName, [graph._relation(edgeCollName, [vertexCollName], [vertexCollName])]);
59+
}
60+
61+
function makeKey(i) {
62+
return "S" + (i % 3) + ":K" + i;
63+
}
64+
65+
function makeTree(depth, vertexCollName, edgeCollName) {
66+
let V = db._collection(vertexCollName);
67+
let E = db._collection(edgeCollName);
68+
let klumpen = {};
69+
for (let i = 0; i < 1000; ++i) {
70+
klumpen["K"+i] = makeRandomString(1024);
71+
}
72+
for (let i = 1; i <= 2 ** depth - 1; ++i) {
73+
let v = klumpen;
74+
v.data = "D"+i;
75+
v.smart = "S"+(i % 3);
76+
v._key = makeKey(i);
77+
V.insert(v);
78+
print("Have created", i, "vertices out of", 2 ** depth - 1);
79+
}
80+
81+
// This is now a gigabyte of data, one megabyte per vertex.
82+
83+
// Make a binary tree:
84+
for (let i = 1; i <= 2 ** (depth - 1) - 1; ++i) {
85+
let e = { _from: vertexCollName + "/" + makeKey(i),
86+
_to: vertexCollName + "/" + makeKey(2 * i)};
87+
E.insert(e);
88+
e = { _from: vertexCollName + "/" + makeKey(i),
89+
_to: vertexCollName + "/" + makeKey(2 * i + 1)};
90+
E.insert(e);
91+
}
92+
93+
}

simple/test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const fs = require("fs");
66
const semver = require("semver");
77
const _ = require("lodash");
88
const db = require("org/arangodb").db;
9+
require("internal").load("simple/BIGvertices.js");
910

1011
function sum (values) {
1112
if (values.length > 1) {
@@ -482,10 +483,16 @@ exports.test = function (global) {
482483
createEdges(1000);
483484
} else if (global.small) {
484485
createEdges(10000);
486+
makeGraph("Tree", "TreeV", "TreeE");
487+
makeTree(6, "TreeV", "TreeE");
485488
} else if (global.medium) {
486489
createEdges(100000);
490+
makeGraph("Tree", "TreeV", "TreeE");
491+
makeTree(7, "TreeV", "TreeE");
487492
} else if (global.big) {
488493
createEdges(1000000);
494+
makeGraph("Tree", "TreeV", "TreeE");
495+
makeTree(8, "TreeV", "TreeE");
489496
}
490497

491498
internal.wal.flush(true, true);
@@ -998,6 +1005,12 @@ exports.test = function (global) {
9981005
// edgeTests
9991006
// /////////////////////////////////////////////////////////////////////////////
10001007

1008+
traversalProjections = function(params) {
1009+
// Note that depth 8 is good for all three sizes small (6), medium (7)
1010+
// and big (8). Depending on the size, we create a different tree.
1011+
db._query(`FOR v IN 0..8 OUTBOUND "TreeV/S1:K1" GRAPH "Tree" RETURN v.data`, {}, {}, {silent});
1012+
},
1013+
10011014
outbound = function (params) {
10021015
db._query(
10031016
"WITH @@v FOR i IN 1 .. @loops FOR v, e, p IN @minDepth..@maxDepth OUTBOUND @start @@c RETURN v",
@@ -2520,6 +2533,10 @@ exports.test = function (global) {
25202533
}
25212534
];
25222535
let edgeTests = [
2536+
{
2537+
name: "traversal-projections",
2538+
params: { func: traversalProjections }
2539+
},
25232540
{
25242541
name: "traversal-outbound-1",
25252542
params: { func: outbound, minDepth: 1, maxDepth: 1, loops: 1000 }

0 commit comments

Comments
 (0)