1
+ /* jshint globalstrict:false, strict:false, maxlen: 500 */
2
+ /* global aql, GLOBAL, makeGraph, makeTree, */
1
3
"use strict" ;
2
4
const internal = require ( "internal" ) ;
3
5
const arango = internal . arango ;
@@ -96,7 +98,7 @@ function toAsciiTable (title, out) {
96
98
97
99
return table . toString ( ) ;
98
100
}
99
-
101
+ let randomPoint ;
100
102
exports . test = function ( testParams ) {
101
103
testParams . tiny = testParams . tiny || false ;
102
104
testParams . small = testParams . small || false ;
@@ -135,7 +137,8 @@ exports.test = function (testParams) {
135
137
136
138
// Substring first 5 characters to limit to A.B.C format and not use any `nightly`, `rc`, `preview` etc.
137
139
const serverVersion = ( ( ( typeof arango ) !== "undefined" ) ? arango . getVersion ( ) : internal . version ) . split ( "-" ) [ 0 ] ;
138
- testParams . zkdMdiRenamed = semver . satisfies ( serverVersion , ">3.11.99" ) ;
140
+ print ( serverVersion )
141
+ testParams . zkdMdiRenamed = semver . satisfies ( serverVersion , ">3.11.99" ) ;
139
142
const isEnterprise = internal . isEnterprise ( ) ;
140
143
const isCluster = internal . isCluster ( ) ;
141
144
@@ -214,14 +217,14 @@ exports.test = function (testParams) {
214
217
let errors = [ ] ;
215
218
for ( let i = 0 ; i < tests . length ; ++ i ) {
216
219
let test = tests [ i ] ;
217
- print ( test )
220
+ print ( test ) ;
218
221
try {
219
- if ( ! ( test [ ' version' ] === undefined || semver . satisfies ( serverVersion , test [ ' version' ] ) ) ) {
220
- print ( `skipping test ${ test [ ' name' ] } , requires version ${ test [ ' version' ] } ` ) ;
221
- } else if ( test [ ' legacy' ] && ! testParams . legacy ) {
222
- print ( `skipping legacy test ${ test [ ' name' ] } ` ) ;
222
+ if ( ! ( test [ " version" ] === undefined || semver . satisfies ( serverVersion , test [ " version" ] ) ) ) {
223
+ print ( `skipping test ${ test [ " name" ] } , requires version ${ test [ " version" ] } ` ) ;
224
+ } else if ( test [ " legacy" ] && ! testParams . legacy ) {
225
+ print ( `skipping legacy test ${ test [ " name" ] } ` ) ;
223
226
} else {
224
- print ( `running test ${ test [ ' name' ] } ` ) ;
227
+ print ( `running test ${ test [ " name" ] } ` ) ;
225
228
for ( let j = 0 ; j < options . collections . length ; ++ j ) {
226
229
let collection = options . collections [ j ] ;
227
230
@@ -231,7 +234,7 @@ exports.test = function (testParams) {
231
234
const stats = calc ( results , options ) ;
232
235
233
236
const result = {
234
- name : test [ ' name' ] ,
237
+ name : test [ " name" ] ,
235
238
runs : options . runs ,
236
239
min : stats . min . toFixed ( options . digits ) ,
237
240
max : stats . max . toFixed ( options . digits ) ,
@@ -253,8 +256,8 @@ exports.test = function (testParams) {
253
256
} // for j
254
257
}
255
258
} catch ( ex ) {
256
- print ( `exception in test ${ test [ ' name' ] } : ${ String ( ex ) } \n${ String ( ex . stack ) } ` ) ;
257
- errors . push ( { name : test [ ' name' ] , error : ex } ) ;
259
+ print ( `exception in test ${ test [ " name" ] } : ${ String ( ex ) } \n${ String ( ex . stack ) } ` ) ;
260
+ errors . push ( { name : test [ " name" ] , error : ex } ) ;
258
261
GLOBAL . returnValue = 1 ;
259
262
}
260
263
} // for i
@@ -810,7 +813,6 @@ exports.test = function (testParams) {
810
813
createArangoSearch ( viewParams ) ;
811
814
}
812
815
} ,
813
-
814
816
fill = function ( params ) {
815
817
let c = db . _collection ( params . collection ) ,
816
818
n = parseInt ( params . collection . replace ( / [ a - z ] + / g, "" ) , 10 ) ,
@@ -819,34 +821,78 @@ exports.test = function (testParams) {
819
821
for ( let i = 0 ; i < docSize ; ++ i ) {
820
822
doc [ "value" + i ] = i ;
821
823
}
824
+ let vectors = [ ] ;
825
+ if ( params . type === "vector" ) {
826
+ const seed = 12132390894 ;
827
+ const randomNumberGeneratorFloat = function ( seed ) {
828
+ const rng = ( function * ( seed ) {
829
+ while ( true ) {
830
+ const nextVal = Math . cos ( seed ++ ) ;
831
+ yield nextVal ;
832
+ }
833
+ } ) ( seed ) ;
834
+
835
+ return function ( ) {
836
+ return rng . next ( ) . value ;
837
+ } ;
838
+ } ;
839
+ let gen = randomNumberGeneratorFloat ( seed ) ;
840
+
841
+ for ( let i = 0 ; i < n ; ++ i ) {
842
+ const vector = Array . from ( {
843
+ length : params . dimension
844
+ } , ( ) => gen ( ) ) ;
845
+ if ( i === 250 ) {
846
+ randomPoint = vector ;
847
+ }
848
+ vectors . push ( {
849
+ vector,
850
+ nonVector : i ,
851
+ unIndexedVector : vector
852
+ } ) ;
853
+ }
854
+ }
822
855
823
856
const batchSize = params . batchSize ;
824
857
if ( batchSize ) {
825
858
// perform babies operations
826
859
for ( let i = 0 ; i < n / batchSize ; ++ i ) {
827
860
let docs = [ ] ;
828
861
for ( let j = 0 ; j < batchSize ; ++ j ) {
829
- docs . push ( { _key : "test" + ( i * batchSize + j ) , ...doc } ) ;
862
+ let oneDoc = { _key : "test" + ( i * batchSize + j ) , ...doc } ;
863
+ if ( params . type === "vector" ) {
864
+ let vec = vectors [ i * batchSize + j ] ;
865
+ oneDoc [ "vector" ] = vec . vector ;
866
+ oneDoc [ "nonVector" ] = vec . nonVector ;
867
+ oneDoc [ "unIndexedVector" ] = vec . unIndexedVector ;
868
+ }
869
+ docs . push ( oneDoc ) ;
830
870
}
831
871
c . insert ( docs ) ;
832
872
}
833
873
} else {
834
874
// perform single document operations
835
875
for ( let i = 0 ; i < n ; ++ i ) {
836
876
doc . _key = "test" + i ;
877
+ if ( params . type === "vector" ) {
878
+ let vec = vectors [ i ] ;
879
+ doc [ "vector" ] = vec . vector ;
880
+ doc [ "nonVector" ] = vec . nonVector ;
881
+ doc [ "unIndexedVector" ] = vec . unIndexedVector ;
882
+ }
837
883
c . insert ( doc ) ;
838
884
}
839
885
}
840
886
} ,
841
-
887
+
842
888
// /////////////////////////////////////////////////////////////////////////////
843
889
// indexes tests
844
890
// /////////////////////////////////////////////////////////////////////////////
845
891
846
892
insertIndexOne = function ( params ) {
847
893
let c = db . _collection ( params . collection ) ,
848
894
n = parseInt ( params . collection . replace ( / [ a - z ] + / g, "" ) , 10 ) ;
849
-
895
+
850
896
// perform small batch document operations
851
897
const batchSize = params . batchSize || 100 ;
852
898
let docs = [ ] ;
@@ -868,11 +914,11 @@ exports.test = function (testParams) {
868
914
}
869
915
}
870
916
} ,
871
-
917
+
872
918
insertIndexTwo = function ( params ) {
873
919
let c = db . _collection ( params . collection ) ,
874
920
n = parseInt ( params . collection . replace ( / [ a - z ] + / g, "" ) , 10 ) ;
875
-
921
+
876
922
// perform small batch document operations
877
923
const batchSize = params . batchSize || 100 ;
878
924
let docs = [ ] ;
@@ -1002,10 +1048,10 @@ exports.test = function (testParams) {
1002
1048
// edgeTests
1003
1049
// /////////////////////////////////////////////////////////////////////////////
1004
1050
1005
- traversalProjections = function ( params ) {
1051
+ traversalProjections = function ( ) {
1006
1052
// Note that depth 8 is good for all three sizes small (6), medium (7)
1007
1053
// and big (8). Depending on the size, we create a different tree.
1008
- db . _query ( ` FOR v IN 0..8 OUTBOUND "TreeV/S1:K1" GRAPH "Tree" RETURN v.data` , { } , { } , { silent} ) ;
1054
+ db . _query ( " FOR v IN 0..8 OUTBOUND \ "TreeV/S1:K1\ " GRAPH \ "Tree\ " RETURN v.data" , { } , { } , { silent} ) ;
1009
1055
} ,
1010
1056
1011
1057
outbound = function ( params ) {
@@ -2171,7 +2217,7 @@ exports.test = function (testParams) {
2171
2217
setup : function ( params ) {
2172
2218
drop ( params ) ;
2173
2219
create ( params ) ;
2174
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" , "value2" ] } ) ;
2220
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" , "value2" ] } ) ;
2175
2221
}
2176
2222
}
2177
2223
} ,
@@ -2394,7 +2440,7 @@ exports.test = function (testParams) {
2394
2440
setup : function ( params ) {
2395
2441
drop ( params ) ;
2396
2442
create ( params ) ;
2397
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2443
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2398
2444
} ,
2399
2445
type : "number" ,
2400
2446
teardown : drop
@@ -2407,7 +2453,7 @@ exports.test = function (testParams) {
2407
2453
setup : function ( params ) {
2408
2454
drop ( params ) ;
2409
2455
create ( params ) ;
2410
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2456
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2411
2457
} ,
2412
2458
type : "number" ,
2413
2459
teardown : drop
@@ -2420,7 +2466,7 @@ exports.test = function (testParams) {
2420
2466
setup : function ( params ) {
2421
2467
drop ( params ) ;
2422
2468
create ( params ) ;
2423
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2469
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2424
2470
} ,
2425
2471
type : "string" ,
2426
2472
teardown : drop
@@ -2433,7 +2479,7 @@ exports.test = function (testParams) {
2433
2479
setup : function ( params ) {
2434
2480
drop ( params ) ;
2435
2481
create ( params ) ;
2436
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2482
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2437
2483
} ,
2438
2484
type : "string" ,
2439
2485
teardown : drop
@@ -2446,8 +2492,8 @@ exports.test = function (testParams) {
2446
2492
setup : function ( params ) {
2447
2493
drop ( params ) ;
2448
2494
create ( params ) ;
2449
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2450
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] } ) ;
2495
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2496
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] } ) ;
2451
2497
} ,
2452
2498
type : "number" ,
2453
2499
teardown : drop
@@ -2460,8 +2506,8 @@ exports.test = function (testParams) {
2460
2506
setup : function ( params ) {
2461
2507
drop ( params ) ;
2462
2508
create ( params ) ;
2463
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2464
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] , estimates : false } ) ;
2509
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2510
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] , estimates : false } ) ;
2465
2511
} ,
2466
2512
type : "number" ,
2467
2513
teardown : drop
@@ -2474,8 +2520,8 @@ exports.test = function (testParams) {
2474
2520
setup : function ( params ) {
2475
2521
drop ( params ) ;
2476
2522
create ( params ) ;
2477
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2478
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] } ) ;
2523
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2524
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] } ) ;
2479
2525
} ,
2480
2526
type : "string" ,
2481
2527
teardown : drop
@@ -2488,13 +2534,44 @@ exports.test = function (testParams) {
2488
2534
setup : function ( params ) {
2489
2535
drop ( params ) ;
2490
2536
create ( params ) ;
2491
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2492
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] , estimates : false } ) ;
2537
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2538
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] , estimates : false } ) ;
2493
2539
} ,
2494
2540
type : "string" ,
2495
2541
teardown : drop
2496
2542
}
2497
2543
} ,
2544
+ {
2545
+ name : "indexes-vector" ,
2546
+ params : {
2547
+ vector : true ,
2548
+ dimension : 500 ,
2549
+ setup : function ( params ) {
2550
+ drop ( params ) ;
2551
+ create ( params ) ;
2552
+ fill ( params ) ;
2553
+ db [ params . collection ] . ensureIndex ( {
2554
+ name : "vector_l2" ,
2555
+ type : "vector" ,
2556
+ fields : [ "vector" ] ,
2557
+ inBackground : false ,
2558
+ params : {
2559
+ metric : "l2" ,
2560
+ dimension : params . dimension ,
2561
+ nLists : 10 ,
2562
+ trainingIterations : 10
2563
+ }
2564
+ } ) ;
2565
+ } ,
2566
+ func : function ( params ) {
2567
+ db . _query ( aql `FOR d IN
2568
+ ${ db [ params . collection ] }
2569
+ SORT APPROX_NEAR_L2(d.vector, ${ randomPoint } ) LIMIT 5 RETURN {key: d._key}` ) . toArray ( ) ;
2570
+ } ,
2571
+ type : "vector" ,
2572
+ teardown : drop
2573
+ }
2574
+ }
2498
2575
] ;
2499
2576
2500
2577
// Tests without collections/IO, to focus on aql block performance.
@@ -2553,7 +2630,7 @@ exports.test = function (testParams) {
2553
2630
{
2554
2631
name : "traversal-projections" ,
2555
2632
params : { func : traversalProjections }
2556
- } ,
2633
+ } ,
2557
2634
{
2558
2635
name : "traversal-outbound-1" ,
2559
2636
params : { func : outbound , minDepth : 1 , maxDepth : 1 , loops : 1000 }
@@ -3280,7 +3357,7 @@ exports.test = function (testParams) {
3280
3357
}
3281
3358
db . _query (
3282
3359
params . queryString ,
3283
- bindParam ,
3360
+ bindParam
3284
3361
) ;
3285
3362
}
3286
3363
@@ -3334,7 +3411,7 @@ exports.test = function (testParams) {
3334
3411
FILTER d.x == 9 and d.y >= 52
3335
3412
RETURN d`
3336
3413
}
3337
- } ,
3414
+ }
3338
3415
] ;
3339
3416
3340
3417
const runSatelliteGraphTests = ( testParams . satelliteGraphTests && isEnterprise && isCluster ) ;
@@ -3418,7 +3495,7 @@ exports.test = function (testParams) {
3418
3495
setup : function ( params ) {
3419
3496
db . _drop ( params . collection ) ;
3420
3497
let col = db . _create ( params . collection ) ;
3421
- let type = ( testParams . zkdMdiRenamed ) ? "mdi" : "zkd" ;
3498
+ let type = ( testParams . zkdMdiRenamed ) ? "mdi" : "zkd" ;
3422
3499
col . ensureIndex ( { type : type , name : "mdiIndex" , fields : [ "x" , "y" ] , fieldValueTypes : "double" } ) ;
3423
3500
db . _query ( `
3424
3501
FOR i IN 0..${ params . collectionSize }
@@ -3590,7 +3667,7 @@ exports.test = function (testParams) {
3590
3667
3591
3668
runTestSuite ( "Arango Search No Materialization" , arangosearchNoMaterializationTests , options ) ;
3592
3669
}
3593
-
3670
+
3594
3671
// indexes tests
3595
3672
if ( testParams . indexes ) {
3596
3673
options = {
0 commit comments