4646import org .apache .hugegraph .structure .HugeElement ;
4747import org .apache .hugegraph .structure .HugeProperty ;
4848import org .apache .hugegraph .type .HugeType ;
49+ import org .apache .hugegraph .type .define .DataType ;
4950import org .apache .hugegraph .type .define .Directions ;
5051import org .apache .hugegraph .type .define .HugeKeys ;
5152import org .apache .hugegraph .util .CollectionUtil ;
@@ -419,9 +420,9 @@ public static Condition convOr(HugeGraph graph,
419420 return cond ;
420421 }
421422
422- private static Condition . Relation convCompare2Relation (HugeGraph graph ,
423- HugeType type ,
424- HasContainer has ) {
423+ private static Condition convCompare2Relation (HugeGraph graph ,
424+ HugeType type ,
425+ HasContainer has ) {
425426 assert type .isGraph ();
426427 BiPredicate <?, ?> bp = has .getPredicate ().getBiPredicate ();
427428 assert bp instanceof Compare ;
@@ -459,16 +460,21 @@ private static Condition.Relation convCompare2SyspropRelation(HugeGraph graph,
459460 }
460461 }
461462
462- private static Condition . Relation convCompare2UserpropRelation (HugeGraph graph ,
463- HugeType type ,
464- HasContainer has ) {
463+ private static Condition convCompare2UserpropRelation (HugeGraph graph ,
464+ HugeType type ,
465+ HasContainer has ) {
465466 BiPredicate <?, ?> bp = has .getPredicate ().getBiPredicate ();
466467 assert bp instanceof Compare ;
467468
468469 String key = has .getKey ();
469470 PropertyKey pkey = graph .propertyKey (key );
470471 Id pkeyId = pkey .id ();
471472 Object value = validPropertyValue (has .getValue (), pkey );
473+ if (pkey .dataType () == DataType .BOOLEAN &&
474+ value instanceof Boolean ) {
475+ return convCompare2BooleanUserpropRelation ((Compare ) bp , pkeyId ,
476+ (Boolean ) value );
477+ }
472478
473479 switch ((Compare ) bp ) {
474480 case eq :
@@ -488,6 +494,36 @@ private static Condition.Relation convCompare2UserpropRelation(HugeGraph graph,
488494 }
489495 }
490496
497+ private static Condition convCompare2BooleanUserpropRelation (Compare compare ,
498+ Id key ,
499+ Boolean value ) {
500+ switch (compare ) {
501+ case eq :
502+ return Condition .eq (key , value );
503+ case neq :
504+ return Condition .neq (key , value );
505+ case gt :
506+ return value ? impossibleBooleanCondition (key ) :
507+ Condition .eq (key , true );
508+ case gte :
509+ return value ? Condition .eq (key , true ) :
510+ Condition .in (key , ImmutableList .of (false , true ));
511+ case lt :
512+ return value ? Condition .eq (key , false ) :
513+ impossibleBooleanCondition (key );
514+ case lte :
515+ return value ? Condition .in (key , ImmutableList .of (false , true )) :
516+ Condition .eq (key , false );
517+ default :
518+ throw new AssertionError (compare );
519+ }
520+ }
521+
522+ private static Condition impossibleBooleanCondition (Id key ) {
523+ return Condition .and (Condition .eq (key , false ),
524+ Condition .eq (key , true ));
525+ }
526+
491527 private static Condition convRelationType2Relation (HugeGraph graph ,
492528 HugeType type ,
493529 HasContainer has ) {
0 commit comments