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,7 @@ 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
+ testParams . zkdMdiRenamed = semver . satisfies ( serverVersion , ">3.11.99" ) ;
139
141
const isEnterprise = internal . isEnterprise ( ) ;
140
142
const isCluster = internal . isCluster ( ) ;
141
143
@@ -214,14 +216,14 @@ exports.test = function (testParams) {
214
216
let errors = [ ] ;
215
217
for ( let i = 0 ; i < tests . length ; ++ i ) {
216
218
let test = tests [ i ] ;
217
- print ( test )
219
+ print ( test ) ;
218
220
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' ] } ` ) ;
221
+ if ( ! ( test [ " version" ] === undefined || semver . satisfies ( serverVersion , test [ " version" ] ) ) ) {
222
+ print ( `skipping test ${ test [ " name" ] } , requires version ${ test [ " version" ] } ` ) ;
223
+ } else if ( test [ " legacy" ] && ! testParams . legacy ) {
224
+ print ( `skipping legacy test ${ test [ " name" ] } ` ) ;
223
225
} else {
224
- print ( `running test ${ test [ ' name' ] } ` ) ;
226
+ print ( `running test ${ test [ " name" ] } ` ) ;
225
227
for ( let j = 0 ; j < options . collections . length ; ++ j ) {
226
228
let collection = options . collections [ j ] ;
227
229
@@ -231,7 +233,7 @@ exports.test = function (testParams) {
231
233
const stats = calc ( results , options ) ;
232
234
233
235
const result = {
234
- name : test [ ' name' ] ,
236
+ name : test [ " name" ] ,
235
237
runs : options . runs ,
236
238
min : stats . min . toFixed ( options . digits ) ,
237
239
max : stats . max . toFixed ( options . digits ) ,
@@ -253,8 +255,8 @@ exports.test = function (testParams) {
253
255
} // for j
254
256
}
255
257
} catch ( ex ) {
256
- print ( `exception in test ${ test [ ' name' ] } : ${ String ( ex ) } \n${ String ( ex . stack ) } ` ) ;
257
- errors . push ( { name : test [ ' name' ] , error : ex } ) ;
258
+ print ( `exception in test ${ test [ " name" ] } : ${ String ( ex ) } \n${ String ( ex . stack ) } ` ) ;
259
+ errors . push ( { name : test [ " name" ] , error : ex } ) ;
258
260
GLOBAL . returnValue = 1 ;
259
261
}
260
262
} // for i
@@ -810,7 +812,6 @@ exports.test = function (testParams) {
810
812
createArangoSearch ( viewParams ) ;
811
813
}
812
814
} ,
813
-
814
815
fill = function ( params ) {
815
816
let c = db . _collection ( params . collection ) ,
816
817
n = parseInt ( params . collection . replace ( / [ a - z ] + / g, "" ) , 10 ) ,
@@ -819,34 +820,78 @@ exports.test = function (testParams) {
819
820
for ( let i = 0 ; i < docSize ; ++ i ) {
820
821
doc [ "value" + i ] = i ;
821
822
}
823
+ let vectors = [ ] ;
824
+ if ( params . type === "vector" ) {
825
+ const seed = 12132390894 ;
826
+ const randomNumberGeneratorFloat = function ( seed ) {
827
+ const rng = ( function * ( seed ) {
828
+ while ( true ) {
829
+ const nextVal = Math . cos ( seed ++ ) ;
830
+ yield nextVal ;
831
+ }
832
+ } ) ( seed ) ;
833
+
834
+ return function ( ) {
835
+ return rng . next ( ) . value ;
836
+ } ;
837
+ } ;
838
+ let gen = randomNumberGeneratorFloat ( seed ) ;
839
+
840
+ for ( let i = 0 ; i < n ; ++ i ) {
841
+ const vector = Array . from ( {
842
+ length : params . dimension
843
+ } , ( ) => gen ( ) ) ;
844
+ if ( i === 250 ) {
845
+ randomPoint = vector ;
846
+ }
847
+ vectors . push ( {
848
+ vector,
849
+ nonVector : i ,
850
+ unIndexedVector : vector
851
+ } ) ;
852
+ }
853
+ }
822
854
823
855
const batchSize = params . batchSize ;
824
856
if ( batchSize ) {
825
857
// perform babies operations
826
858
for ( let i = 0 ; i < n / batchSize ; ++ i ) {
827
859
let docs = [ ] ;
828
860
for ( let j = 0 ; j < batchSize ; ++ j ) {
829
- docs . push ( { _key : "test" + ( i * batchSize + j ) , ...doc } ) ;
861
+ let oneDoc = { _key : "test" + ( i * batchSize + j ) , ...doc } ;
862
+ if ( params . type === "vector" ) {
863
+ let vec = vectors [ i * batchSize + j ] ;
864
+ oneDoc [ "vector" ] = vec . vector ;
865
+ oneDoc [ "nonVector" ] = vec . nonVector ;
866
+ oneDoc [ "unIndexedVector" ] = vec . unIndexedVector ;
867
+ }
868
+ docs . push ( oneDoc ) ;
830
869
}
831
870
c . insert ( docs ) ;
832
871
}
833
872
} else {
834
873
// perform single document operations
835
874
for ( let i = 0 ; i < n ; ++ i ) {
836
875
doc . _key = "test" + i ;
876
+ if ( params . type === "vector" ) {
877
+ let vec = vectors [ i ] ;
878
+ doc [ "vector" ] = vec . vector ;
879
+ doc [ "nonVector" ] = vec . nonVector ;
880
+ doc [ "unIndexedVector" ] = vec . unIndexedVector ;
881
+ }
837
882
c . insert ( doc ) ;
838
883
}
839
884
}
840
885
} ,
841
-
886
+
842
887
// /////////////////////////////////////////////////////////////////////////////
843
888
// indexes tests
844
889
// /////////////////////////////////////////////////////////////////////////////
845
890
846
891
insertIndexOne = function ( params ) {
847
892
let c = db . _collection ( params . collection ) ,
848
893
n = parseInt ( params . collection . replace ( / [ a - z ] + / g, "" ) , 10 ) ;
849
-
894
+
850
895
// perform small batch document operations
851
896
const batchSize = params . batchSize || 100 ;
852
897
let docs = [ ] ;
@@ -868,11 +913,11 @@ exports.test = function (testParams) {
868
913
}
869
914
}
870
915
} ,
871
-
916
+
872
917
insertIndexTwo = function ( params ) {
873
918
let c = db . _collection ( params . collection ) ,
874
919
n = parseInt ( params . collection . replace ( / [ a - z ] + / g, "" ) , 10 ) ;
875
-
920
+
876
921
// perform small batch document operations
877
922
const batchSize = params . batchSize || 100 ;
878
923
let docs = [ ] ;
@@ -1002,10 +1047,10 @@ exports.test = function (testParams) {
1002
1047
// edgeTests
1003
1048
// /////////////////////////////////////////////////////////////////////////////
1004
1049
1005
- traversalProjections = function ( params ) {
1050
+ traversalProjections = function ( ) {
1006
1051
// Note that depth 8 is good for all three sizes small (6), medium (7)
1007
1052
// 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} ) ;
1053
+ db . _query ( " FOR v IN 0..8 OUTBOUND \ "TreeV/S1:K1\ " GRAPH \ "Tree\ " RETURN v.data" , { } , { } , { silent} ) ;
1009
1054
} ,
1010
1055
1011
1056
outbound = function ( params ) {
@@ -2169,7 +2214,14 @@ exports.test = function (testParams) {
2169
2214
} ,
2170
2215
{
2171
2216
name : "aql-index-collect-aggregate" ,
2172
- params : { func : indexCollectAggregate , attr : "value1" }
2217
+ params : {
2218
+ func : indexCollectAggregate ,
2219
+ setup : function ( params ) {
2220
+ drop ( params ) ;
2221
+ create ( params ) ;
2222
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" , "value2" ] } ) ;
2223
+ }
2224
+ }
2173
2225
} ,
2174
2226
{
2175
2227
name : "aql-subquery" ,
@@ -2390,7 +2442,7 @@ exports.test = function (testParams) {
2390
2442
setup : function ( params ) {
2391
2443
drop ( params ) ;
2392
2444
create ( params ) ;
2393
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2445
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2394
2446
} ,
2395
2447
type : "number" ,
2396
2448
teardown : drop
@@ -2403,7 +2455,7 @@ exports.test = function (testParams) {
2403
2455
setup : function ( params ) {
2404
2456
drop ( params ) ;
2405
2457
create ( params ) ;
2406
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2458
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2407
2459
} ,
2408
2460
type : "number" ,
2409
2461
teardown : drop
@@ -2416,7 +2468,7 @@ exports.test = function (testParams) {
2416
2468
setup : function ( params ) {
2417
2469
drop ( params ) ;
2418
2470
create ( params ) ;
2419
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2471
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2420
2472
} ,
2421
2473
type : "string" ,
2422
2474
teardown : drop
@@ -2429,7 +2481,7 @@ exports.test = function (testParams) {
2429
2481
setup : function ( params ) {
2430
2482
drop ( params ) ;
2431
2483
create ( params ) ;
2432
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2484
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2433
2485
} ,
2434
2486
type : "string" ,
2435
2487
teardown : drop
@@ -2442,8 +2494,8 @@ exports.test = function (testParams) {
2442
2494
setup : function ( params ) {
2443
2495
drop ( params ) ;
2444
2496
create ( params ) ;
2445
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2446
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] } ) ;
2497
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2498
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] } ) ;
2447
2499
} ,
2448
2500
type : "number" ,
2449
2501
teardown : drop
@@ -2456,8 +2508,8 @@ exports.test = function (testParams) {
2456
2508
setup : function ( params ) {
2457
2509
drop ( params ) ;
2458
2510
create ( params ) ;
2459
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2460
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] , estimates : false } ) ;
2511
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2512
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] , estimates : false } ) ;
2461
2513
} ,
2462
2514
type : "number" ,
2463
2515
teardown : drop
@@ -2470,8 +2522,8 @@ exports.test = function (testParams) {
2470
2522
setup : function ( params ) {
2471
2523
drop ( params ) ;
2472
2524
create ( params ) ;
2473
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2474
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] } ) ;
2525
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] } ) ;
2526
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] } ) ;
2475
2527
} ,
2476
2528
type : "string" ,
2477
2529
teardown : drop
@@ -2484,13 +2536,44 @@ exports.test = function (testParams) {
2484
2536
setup : function ( params ) {
2485
2537
drop ( params ) ;
2486
2538
create ( params ) ;
2487
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2488
- db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] , estimates : false } ) ;
2539
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value1" ] , estimates : false } ) ;
2540
+ db [ params . collection ] . ensureIndex ( { type : "persistent" , fields : [ "value2" ] , estimates : false } ) ;
2489
2541
} ,
2490
2542
type : "string" ,
2491
2543
teardown : drop
2492
2544
}
2493
2545
} ,
2546
+ {
2547
+ name : "indexes-vector" ,
2548
+ params : {
2549
+ vector : true ,
2550
+ dimension : 500 ,
2551
+ setup : function ( params ) {
2552
+ drop ( params ) ;
2553
+ create ( params ) ;
2554
+ fill ( params ) ;
2555
+ db [ params . collection ] . ensureIndex ( {
2556
+ name : "vector_l2" ,
2557
+ type : "vector" ,
2558
+ fields : [ "vector" ] ,
2559
+ inBackground : false ,
2560
+ params : {
2561
+ metric : "l2" ,
2562
+ dimension : params . dimension ,
2563
+ nLists : 10 ,
2564
+ trainingIterations : 10
2565
+ }
2566
+ } ) ;
2567
+ } ,
2568
+ func : function ( params ) {
2569
+ db . _query ( aql `FOR d IN
2570
+ ${ db [ params . collection ] }
2571
+ SORT APPROX_NEAR_L2(d.vector, ${ randomPoint } ) LIMIT 5 RETURN {key: d._key}` ) . toArray ( ) ;
2572
+ } ,
2573
+ type : "vector" ,
2574
+ teardown : drop
2575
+ }
2576
+ }
2494
2577
] ;
2495
2578
2496
2579
// Tests without collections/IO, to focus on aql block performance.
@@ -2549,7 +2632,7 @@ exports.test = function (testParams) {
2549
2632
{
2550
2633
name : "traversal-projections" ,
2551
2634
params : { func : traversalProjections }
2552
- } ,
2635
+ } ,
2553
2636
{
2554
2637
name : "traversal-outbound-1" ,
2555
2638
params : { func : outbound , minDepth : 1 , maxDepth : 1 , loops : 1000 }
@@ -3276,7 +3359,7 @@ exports.test = function (testParams) {
3276
3359
}
3277
3360
db . _query (
3278
3361
params . queryString ,
3279
- bindParam ,
3362
+ bindParam
3280
3363
) ;
3281
3364
}
3282
3365
@@ -3330,7 +3413,7 @@ exports.test = function (testParams) {
3330
3413
FILTER d.x == 9 and d.y >= 52
3331
3414
RETURN d`
3332
3415
}
3333
- } ,
3416
+ }
3334
3417
] ;
3335
3418
3336
3419
const runSatelliteGraphTests = ( testParams . satelliteGraphTests && isEnterprise && isCluster ) ;
@@ -3414,7 +3497,7 @@ exports.test = function (testParams) {
3414
3497
setup : function ( params ) {
3415
3498
db . _drop ( params . collection ) ;
3416
3499
let col = db . _create ( params . collection ) ;
3417
- let type = ( testParams . zkdMdiRenamed ) ? "mdi" : "zkd" ;
3500
+ let type = ( testParams . zkdMdiRenamed ) ? "mdi" : "zkd" ;
3418
3501
col . ensureIndex ( { type : type , name : "mdiIndex" , fields : [ "x" , "y" ] , fieldValueTypes : "double" } ) ;
3419
3502
db . _query ( `
3420
3503
FOR i IN 0..${ params . collectionSize }
@@ -3586,7 +3669,7 @@ exports.test = function (testParams) {
3586
3669
3587
3670
runTestSuite ( "Arango Search No Materialization" , arangosearchNoMaterializationTests , options ) ;
3588
3671
}
3589
-
3672
+
3590
3673
// indexes tests
3591
3674
if ( testParams . indexes ) {
3592
3675
options = {
0 commit comments