Author: chetanm
Date: Tue Mar  3 11:56:58 2015
New Revision: 1663680

URL: http://svn.apache.org/r1663680
Log:
OAK-2568 - Ignore redundant IS NOT NULL constraints

Modified:
    
jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
    
jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java

Modified: 
jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java?rev=1663680&r1=1663679&r2=1663680&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
 (original)
+++ 
jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
 Tue Mar  3 11:56:58 2015
@@ -574,6 +574,14 @@ public class LucenePropertyIndex impleme
                 continue;
             }
 
+            //If there are more than one restriction on same property then
+            //isNotNullRestriction can be ignored
+            if (pr.isNotNullRestriction()
+                    && filter.getPropertyRestrictions(name).size() > 1
+                    && pr.list == null) { //Check also for pr.list due to 
OAK-2566
+                continue;
+            }
+
             if (pr.first != null && pr.first.equals(pr.last) && 
pr.firstIncluding
                     && pr.lastIncluding) {
                 String first = pr.first.getValue(STRING);

Modified: 
jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java?rev=1663680&r1=1663679&r2=1663680&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
 (original)
+++ 
jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
 Tue Mar  3 11:56:58 2015
@@ -53,7 +53,6 @@ import org.apache.jackrabbit.oak.spi.com
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
 import org.apache.jackrabbit.util.ISO8601;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import static com.google.common.collect.ImmutableSet.of;
@@ -317,7 +316,6 @@ public class LucenePropertyIndexTest ext
         assertQuery("select [jcr:path] from [nt:base] where propa is not 
null", asList("/test/a", "/test/b"));
     }
 
-    @Ignore("OAK-2568")
     @Test
     public void redundantNotNullCheck() throws Exception{
         Tree idx = createIndex("test1", of("tags"));
@@ -347,7 +345,12 @@ public class LucenePropertyIndexTest ext
                 ")";
 
         //Check that filter created out of query does not have is not null 
restriction
-        assertThat(explain(q), not(containsString("[content].[tags] is not 
null")));
+        //Changed the condition to check for absence of range query in Lucene 
as the fix
+        //is done in LucenePropertyIndex level and not query engine level.
+        //So  [content].[tags] is not null would still be present but would 
not be passed
+        //on to Lucene
+        //assertThat(explain(q), not(containsString("[content].[tags] is not 
null")));
+        assertThat(explain(q), not(containsString("+tags:[* TO *]")));
     }
 
     @Test
@@ -659,7 +662,7 @@ public class LucenePropertyIndexTest ext
         Tree test = root.getTree("/").addChild("test");
         List<Long> values = createLongs(NUMBER_OF_NODES);
         List<Tuple> tuples = Lists.newArrayListWithCapacity(values.size());
-        for(int i = 0; i < values.size(); i++){
+        for (int i = 0; i < values.size(); i++){
             Tree child = test.addChild("n"+i);
             child.setProperty("foo", values.get(i));
             child.setProperty("bar", "baz");
@@ -705,8 +708,8 @@ public class LucenePropertyIndexTest ext
 
         assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] = 
'baz' order by [foo]", getSortedPaths(tuples, OrderDirection.ASC));
         assertOrderedQuery(
-            "select [jcr:path] from [nt:base] where [bar] = 'baz' order by 
[foo] DESC",
-            getSortedPaths(tuples, OrderDirection.DESC));
+                "select [jcr:path] from [nt:base] where [bar] = 'baz' order by 
[foo] DESC",
+                getSortedPaths(tuples, OrderDirection.DESC));
     }
 
     @Test
@@ -743,8 +746,8 @@ public class LucenePropertyIndexTest ext
 
         assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] = 
'baz' order by [foo]", getSortedPaths(tuples, OrderDirection.ASC));
         assertOrderedQuery(
-            "select [jcr:path] from [nt:base] where [bar] = 'baz' order by 
[foo] DESC",
-            getSortedPaths(tuples, OrderDirection.DESC));
+                "select [jcr:path] from [nt:base] where [bar] = 'baz' order by 
[foo] DESC",
+                getSortedPaths(tuples, OrderDirection.DESC));
     }
 
     @Test
@@ -784,8 +787,8 @@ public class LucenePropertyIndexTest ext
         assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] = 
'baz' order by [foo]",
             getSortedPaths(tuples, OrderDirection.ASC));
         assertOrderedQuery(
-            "select [jcr:path] from [nt:base] where [bar] = 'baz' order by 
[foo] DESC",
-            getSortedPaths(tuples, OrderDirection.DESC));
+                "select [jcr:path] from [nt:base] where [bar] = 'baz' order by 
[foo] DESC",
+                getSortedPaths(tuples, OrderDirection.DESC));
     }
 
     @Test
@@ -818,9 +821,9 @@ public class LucenePropertyIndexTest ext
                 getSortedPaths(tuples, OrderDirection.ASC))));
         // Append the path of property added as timestamp string to the sorted 
list
         assertOrderedQuery(
-            "select [jcr:path] from [nt:base] where [bar] = 'baz' order by 
[foo] DESC", Lists
-            .newArrayList(Iterables.concat(getSortedPaths(tuples, 
OrderDirection.DESC),
-                Lists.newArrayList("/test/n0"))));
+                "select [jcr:path] from [nt:base] where [bar] = 'baz' order by 
[foo] DESC", Lists
+                        .newArrayList(Iterables.concat(getSortedPaths(tuples, 
OrderDirection.DESC),
+                                Lists.newArrayList("/test/n0"))));
     }
 
     @Test
@@ -958,9 +961,9 @@ public class LucenePropertyIndexTest ext
 
         root.commit();
         assertQuery(
-            "select * from [nt:base] where CONTAINS(*, 'fox') and 
CONTAINS([propb], '\"winter is here\" OR \"summer "
-                + "is here\"')",
-            asList("/test/a", "/test/b"));
+                "select * from [nt:base] where CONTAINS(*, 'fox') and 
CONTAINS([propb], '\"winter is here\" OR \"summer "
+                        + "is here\"')",
+                asList("/test/a", "/test/b"));
     }
 
     // OAK-2434
@@ -1109,7 +1112,7 @@ public class LucenePropertyIndexTest ext
     }
 
     private static String dt(String date) throws ParseException {
-        return String.format("CAST ('%s' AS 
DATE)",ISO8601.format(createCal(date)));
+        return String.format("CAST ('%s' AS DATE)", 
ISO8601.format(createCal(date)));
     }
 
     private static List<String> getSortedPaths(List<Tuple> tuples, 
OrderDirection dir) {
@@ -1166,7 +1169,7 @@ public class LucenePropertyIndexTest ext
         Random rnd = new Random();
         List<Calendar> values = Lists.newArrayListWithCapacity(n);
         for (long i = 0; i < n; i++){
-            values.add(createCal(String.format("%02d/%02d/2%03d", 
rnd.nextInt(26) + 1, rnd.nextInt(10) + 1,i)));
+            values.add(createCal(String.format("%02d/%02d/2%03d", 
rnd.nextInt(26) + 1, rnd.nextInt(10) + 1, i)));
         }
         Collections.shuffle(values);
         return values;


Reply via email to