@@ -474,6 +474,102 @@ def test_add(self):
474
474
475
475
self .schema .drop_collection (collection_name )
476
476
477
+ @unittest .skipIf (tests .MYSQL_VERSION < (8 , 0 , 2 ),
478
+ "CONT_IN operator unavailable" )
479
+ def test_cont_in_operator (self ):
480
+ collection_name = "{0}.test" .format (self .schema_name )
481
+ collection = self .schema .create_collection (collection_name )
482
+ collection .add ({
483
+ "_id" : "a6f4b93e1a264a108393524f29546a8c" ,
484
+ "title" : "AFRICAN EGG" ,
485
+ "description" : "A Fast-Paced Documentary of a Pastry Chef And a "
486
+ "Dentist who must Pursue a Forensic Psychologist in "
487
+ "The Gulf of Mexico" ,
488
+ "releaseyear" : 2006 ,
489
+ "language" : "English" ,
490
+ "duration" : 130 ,
491
+ "rating" : "G" ,
492
+ "genre" : "Science fiction" ,
493
+ "actors" : [{
494
+ "name" : "MILLA PECK" ,
495
+ "country" : "Mexico" ,
496
+ "birthdate" : "12 Jan 1984"
497
+ }, {
498
+ "name" : "VAL BOLGER" ,
499
+ "country" : "Botswana" ,
500
+ "birthdate" : "26 Jul 1975"
501
+ }, {
502
+ "name" : "SCARLETT BENING" ,
503
+ "country" : "Syria" ,
504
+ "birthdate" : "16 Mar 1978"
505
+ }],
506
+ "additionalinfo" : {
507
+ "director" : "Sharice Legaspi" ,
508
+ "writers" : ["Rusty Couturier" , "Angelic Orduno" , "Carin Postell" ],
509
+ "productioncompanies" : ["Qvodrill" , "Indigoholdings" ]
510
+ }
511
+ }).execute ()
512
+
513
+ tests = [
514
+ ("(1+5) in (1, 2, 3, 4, 5)" , False ),
515
+ ("(1>5) in (true, false)" , True ),
516
+ ("('a'>'b') in (true, false)" , True ),
517
+ ("(1>5) in [true, false]" , None ),
518
+ ("(1+5) in [1, 2, 3, 4, 5]" , None ),
519
+ ("('a'>'b') in [true, false]" , None ),
520
+ ("true IN [(1>5), !(false), (true || false), (false && true)]" ,
521
+ True ),
522
+ ("true IN ((1>5), !(false), (true || false), (false && true))" ,
523
+ True ),
524
+ ("{ 'name' : 'MILLA PECK' } IN actors" , True ),
525
+ ("{\" field\" :true} IN (\" mystring\" , 124, myvar, othervar.jsonobj)" ,
526
+ None ),
527
+ ("actor.name IN ['a name', null, (1<5-4), myvar.jsonobj.name]" ,
528
+ None ),
529
+ ("!false && true IN [true]" , True ),
530
+ ("1-5/2*2 > 3-2/1*2 IN [true, false]" , None ),
531
+ ("true IN [1-5/2*2 > 3-2/1*2]" , False ),
532
+ ("'African Egg' IN ('African Egg', 1, true, NULL, [0,1,2], "
533
+ "{ 'title' : 'Atomic Firefighter' })" , True ),
534
+ ("1 IN ('African Egg', 1, true, NULL, [0,1,2], "
535
+ "{ 'title' : 'Atomic Firefighter' })" , True ),
536
+ ("false IN ('African Egg', 1, true, NULL, [0,1,2], "
537
+ "{ 'title' : 'Atomic Firefighter' })" , True ),
538
+ ("[0,1,2] IN ('African Egg', 1, true, NULL, [0,1,2], "
539
+ "{ 'title' : 'Atomic Firefighter' })" , True ),
540
+ ("{ 'title' : 'Atomic Firefighter' } IN ('African Egg', 1, true, "
541
+ "NULL, [0,1,2], { 'title' : 'Atomic Firefighter' })" , True ),
542
+ ("title IN ('African Egg', 'The Witcher', 'Jurassic Perk')" , False ),
543
+ ("releaseyear IN (2006, 2010, 2017)" , True ),
544
+ ("'African Egg' in movietitle" , None ),
545
+ ("0 NOT IN [1,2,3]" , True ),
546
+ ("1 NOT IN [1,2,3]" , False ),
547
+ ("'' IN title" , False ),
548
+ ("title IN ('', ' ')" , False ),
549
+ ("title IN ['', ' ']" , False ),
550
+ ("[\" Rusty Couturier\" , \" Angelic Orduno\" , \" Carin Postell\" ] IN "
551
+ "additionalinfo.writers" , True ),
552
+ ("{ \" name\" : \" MILLA PECK\" , \" country\" : \" Mexico\" , "
553
+ "\" birthdate\" : \" 12 Jan 1984\" } IN actors" , True ),
554
+ ("releaseyear IN [2006, 2007, 2008]" , True ),
555
+ ("true IN title" , False ),
556
+ ("false IN genre" , False ),
557
+ ("'Sharice Legaspi' IN additionalinfo.director" , True ),
558
+ ("'Mexico' IN actors[*].country" , True ),
559
+ ("'Angelic Orduno' IN additionalinfo.writers" , True ),
560
+ ]
561
+
562
+ for test in tests :
563
+ try :
564
+ result = collection .find () \
565
+ .fields ("{0} as res" .format (test [0 ])) \
566
+ .execute ().fetch_one ()
567
+ except :
568
+ self .assertEqual (None , test [1 ])
569
+ else :
570
+ self .assertEqual (result ['res' ], test [1 ])
571
+ self .schema .drop_collection (collection_name )
572
+
477
573
def test_ilri_expressions (self ):
478
574
collection_name = "{0}.test" .format (self .schema_name )
479
575
collection = self .schema .create_collection (collection_name )
0 commit comments