4444
4545import java .io .PrintWriter ;
4646import java .io .StringWriter ;
47- import java .util .ArrayList ;
4847import java .util .Arrays ;
4948import java .util .List ;
5049
@@ -685,9 +684,7 @@ public void queryRestrictions_sortWrongOrderOnInequality_isInvalid() throws Exce
685684 public void queryRestrictions_surprisingMultipleValuesAllMustMatch_returnsNoEntities ()
686685 throws Exception {
687686 Entity a = new Entity ("Widget" , "a" );
688- ArrayList <Long > xs = new ArrayList <>();
689- xs .add (1L );
690- xs .add (2L );
687+ List <Long > xs = Arrays .asList (1L , 2L );
691688 a .setProperty ("x" , xs );
692689 datastore .put (a );
693690
@@ -701,6 +698,8 @@ public void queryRestrictions_surprisingMultipleValuesAllMustMatch_returnsNoEnti
701698 // [END surprising_behavior_example_1]
702699
703700 // Entity "a" will not match because no individual value matches all filters.
701+ // See the documentation for more details:
702+ // https://cloud.google.com/appengine/docs/java/datastore/query-restrictions#properties_with_multiple_values_can_behave_in_surprising_ways
704703 List <Entity > results = datastore .prepare (q ).asList (FetchOptions .Builder .withDefaults ());
705704 assertThat (results ).named ("query results" ).isEmpty ();
706705 }
@@ -729,6 +728,9 @@ public void queryRestrictions_surprisingMultipleValuesEquals_returnsMatchedEntit
729728 new FilterPredicate ("x" , FilterOperator .EQUAL , 2 )));
730729 // [END surprising_behavior_example_2]
731730
731+ // Only "a" and "e" have both 1 and 2 in the "x" array-valued property.
732+ // See the documentation for more details:
733+ // https://cloud.google.com/appengine/docs/java/datastore/query-restrictions#properties_with_multiple_values_can_behave_in_surprising_ways
732734 List <Entity > results = datastore .prepare (q ).asList (FetchOptions .Builder .withDefaults ());
733735 assertThat (getKeys (results )).named ("query result keys" ).containsExactly (a .getKey (), e .getKey ());
734736 }
@@ -752,6 +754,9 @@ public void queryRestrictions_surprisingMultipleValuesNotEquals_returnsMatchedEn
752754 Query q = new Query ("Widget" ).setFilter (new FilterPredicate ("x" , FilterOperator .NOT_EQUAL , 1 ));
753755 // [END surprising_behavior_example_3]
754756
757+ // The query matches any entity that has a some value other than 1. Only
758+ // entity "e" is not matched. See the documentation for more details:
759+ // https://cloud.google.com/appengine/docs/java/datastore/query-restrictions#properties_with_multiple_values_can_behave_in_surprising_ways
755760 List <Entity > results = datastore .prepare (q ).asList (FetchOptions .Builder .withDefaults ());
756761 assertThat (getKeys (results ))
757762 .named ("query result keys" )
@@ -776,6 +781,13 @@ public void queryRestrictions_surprisingMultipleValuesTwoNotEquals_returnsMatche
776781 new FilterPredicate ("x" , FilterOperator .NOT_EQUAL , 2 )));
777782 // [END surprising_behavior_example_4]
778783
784+ // The two NOT_EQUAL filters in the query become like the combination of queries:
785+ // x < 1 OR (x > 1 AND x < 2) OR x > 2
786+ //
787+ // Only "b" has some value which matches the "x > 2" portion of this query.
788+ //
789+ // See the documentation for more details:
790+ // https://cloud.google.com/appengine/docs/java/datastore/query-restrictions#properties_with_multiple_values_can_behave_in_surprising_ways
779791 List <Entity > results = datastore .prepare (q ).asList (FetchOptions .Builder .withDefaults ());
780792 assertThat (getKeys (results )).named ("query result keys" ).containsExactly (b .getKey ());
781793 }
0 commit comments