Author: alexparvulescu
Date: Mon Jan 13 13:10:44 2014
New Revision: 1557703

URL: http://svn.apache.org/r1557703
Log:
OAK-1301 Path conditions not respected in XPath query
 - fix + test for the initial query


Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DescendantNodeJoinConditionImpl.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexQueryTest.java
    
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2_index.txt

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DescendantNodeJoinConditionImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DescendantNodeJoinConditionImpl.java?rev=1557703&r1=1557702&r2=1557703&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DescendantNodeJoinConditionImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DescendantNodeJoinConditionImpl.java
 Mon Jan 13 13:10:44 2014
@@ -83,7 +83,7 @@ public class DescendantNodeJoinCondition
                 a = KNOWN_PATH;
             }
             if (a != null) {
-                f.restrictPath(a, Filter.PathRestriction.DIRECT_CHILDREN);
+                f.restrictPath(a, Filter.PathRestriction.ALL_CHILDREN);
             }
         }
     }

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexQueryTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexQueryTest.java?rev=1557703&r1=1557702&r2=1557703&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexQueryTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingIndexQueryTest.java
 Mon Jan 13 13:10:44 2014
@@ -156,4 +156,52 @@ public class TraversingIndexQueryTest ex
                 "//*[(jcr:like(child/@prop, 'aaa%') and jcr:like(child/@prop, 
'bbb%') and jcr:like(child/@prop, 'ccc%'))]",
                 "xpath", ImmutableList.of("/content/two"));
     }
+
+    @Test
+    public void testOak1301() throws Exception {
+        Tree t1 = root.getTree("/").addChild("home").addChild("users")
+                .addChild("testing").addChild("socialgraph_test_user_4");
+        t1.setProperty("jcr:primaryType", "rep:User");
+        t1.setProperty("rep:authorizableId", "socialgraph_test_user_4");
+
+        Tree s = t1.addChild("social");
+        s.setProperty("jcr:primaryType", "sling:Folder");
+
+        Tree r = s.addChild("relationships");
+        r.setProperty("jcr:primaryType", "sling:Folder");
+
+        Tree f = r.addChild("friend");
+        f.setProperty("jcr:primaryType", "sling:Folder");
+
+        Tree sg = f.addChild("socialgraph_test_group");
+        sg.setProperty("jcr:primaryType", "nt:unstructured");
+        sg.setProperty("id", "socialgraph_test_group");
+
+        Tree t2 = root.getTree("/").addChild("home").addChild("groups")
+                .addChild("testing").addChild("socialgraph_test_group");
+        root.commit();
+
+        // select [jcr:path], [jcr:score], * from [nt:base] as a where [id/*] =
+        // 'socialgraph_test_group' and isdescendantnode(a, '/home') /* xpath:
+        // /jcr:root/home//*[id='socialgraph_test_group'] */
+        assertQuery(
+                "/jcr:root/home//*[id='socialgraph_test_group']",
+                "xpath",
+                ImmutableList
+                        
.of("/home/users/testing/socialgraph_test_user_4/social/relationships/friend/socialgraph_test_group"));
+
+        // sql2 select c.[jcr:path] as [jcr:path], c.[jcr:score] as 
[jcr:score],
+        // c.* from [nt:base] as a inner join [nt:base] as b on ischildnode(b,
+        // a) inner join [nt:base] as c on isdescendantnode(c, b) where name(a)
+        // = 'social' and isdescendantnode(a, '/home') and name(b) =
+        // 'relationships' and c.[id/*] = 'socialgraph_test_group' /* xpath:
+        // /jcr:root/home//social/relationships//*[id='socialgraph_test_group']
+        // */
+        assertQuery(
+                
"/jcr:root/home//social/relationships//*[id='socialgraph_test_group']",
+                "xpath",
+                ImmutableList
+                        
.of("/home/users/testing/socialgraph_test_user_4/social/relationships/friend/socialgraph_test_group"));
+
+    }
 }

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2_index.txt
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2_index.txt?rev=1557703&r1=1557702&r2=1557703&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2_index.txt
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/sql2_index.txt
 Mon Jan 13 13:10:44 2014
@@ -65,7 +65,7 @@ explain select * from [nt:base] as a inn
 [nt:base] as [a] /* property jcr:uuid where ([a].[jcr:uuid] is not null) and 
([a].[jcr:uuid] in(cast('1' as long), cast('2' as long))) */ inner join 
[nt:base] as [b] /* property jcr:uuid where ([b].[jcr:uuid] is not null) and 
([b].[jcr:uuid] in(cast('3' as long), cast('4' as long))) */ on 
isdescendantnode([b], [a])
 
 explain select * from [nt:base] as a inner join [nt:base] as b on 
isdescendantnode(b, a) where a.[jcr:uuid] is not null and b.[x] is not null
-[nt:base] as [a] /* property jcr:uuid where [a].[jcr:uuid] is not null */ 
inner join [nt:base] as [b] /* traverse "/path/from/the/join/selector/*" where 
[b].[x] is not null */ on isdescendantnode([b], [a])
+[nt:base] as [a] /* property jcr:uuid where [a].[jcr:uuid] is not null */ 
inner join [nt:base] as [b] /* traverse "/path/from/the/join/selector//*" where 
[b].[x] is not null */ on isdescendantnode([b], [a])
 
 explain select [rep:excerpt] from [nt:base] where [jcr:uuid] is not null
 [nt:base] as [nt:base] /* property jcr:uuid (rep:excerpt) where 
[nt:base].[jcr:uuid] is not null */


Reply via email to