jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1138141 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/join/ test/java/org/apache/jackrabbit/core/query/
Date Tue, 21 Jun 2011 19:16:56 GMT
Author: alexparvulescu
Date: Tue Jun 21 19:16:55 2011
New Revision: 1138141

URL: http://svn.apache.org/viewvc?rev=1138141&view=rev
Log:
JCR-3000 SQL2 Join with OR clause still has some issues

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ConstraintSplitInfo.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/JoinTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ConstraintSplitInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ConstraintSplitInfo.java?rev=1138141&r1=1138140&r2=1138141&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ConstraintSplitInfo.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ConstraintSplitInfo.java
Tue Jun 21 19:16:55 2011
@@ -35,6 +35,10 @@ class ConstraintSplitInfo {
     private final List<Constraint> rightConstraints;
 
     private boolean isMultiple;
+    
+    private boolean hasLeftConstraints;
+    
+    private boolean hasRightConstraints;
 
     private ConstraintSplitInfo leftInnerConstraints = null;
 
@@ -49,27 +53,31 @@ class ConstraintSplitInfo {
             List<Constraint> leftConstraints, List<Constraint> rightConstraints)
{
         this.factory = factory;
         this.source = source;
-        this.isMultiple = false;
         this.leftConstraints = leftConstraints;
         this.rightConstraints = rightConstraints;
+        this.isMultiple = false;
+        this.hasLeftConstraints = false;
+        this.hasRightConstraints = false;
     }
 
     public void addLeftConstraint(Constraint c) {
         if (isMultiple) {
             leftInnerConstraints.addLeftConstraint(c);
-            leftInnerConstraints.addRightConstraint(c);
+            rightInnerConstraints.addLeftConstraint(c);
             return;
         }
         leftConstraints.add(c);
+        this.hasLeftConstraints = true;
     }
 
     public void addRightConstraint(Constraint c) {
         if (isMultiple) {
-            rightInnerConstraints.addLeftConstraint(c);
+            leftInnerConstraints.addRightConstraint(c);
             rightInnerConstraints.addRightConstraint(c);
             return;
         }
         rightConstraints.add(c);
+        this.hasRightConstraints = true;
     }
 
     public void splitOr() {
@@ -92,6 +100,8 @@ class ConstraintSplitInfo {
 
         this.leftConstraints.clear();
         this.rightConstraints.clear();
+        this.hasLeftConstraints = false;
+        this.hasRightConstraints = false;
     }
 
     public boolean isMultiple() {
@@ -124,6 +134,14 @@ class ConstraintSplitInfo {
         return Constraints.and(factory, rightConstraints);
     }
 
+    public boolean isHasLeftConstraints() {
+        return hasLeftConstraints;
+    }
+
+    public boolean isHasRightConstraints() {
+        return hasRightConstraints;
+    }
+
     @Override
     public String toString() {
         if (isMultiple) {
@@ -133,7 +151,8 @@ class ConstraintSplitInfo {
         }
         return "ConstraintSplitInfo [single" + ", leftConstraints="
                 + leftConstraints + ", rightConstraints=" + rightConstraints
-                + "]";
+                + ", hasLeftConstraints=" + hasLeftConstraints
+                + ", hasRightConstraints=" + hasRightConstraints + "]";
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java?rev=1138141&r1=1138140&r2=1138141&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java
Tue Jun 21 19:16:55 2011
@@ -245,7 +245,7 @@ public class QueryEngine {
             timeJoinRightSide = System.currentTimeMillis() - timeJoinRightSide;
             log.debug(genString(printIndentation)
                     + "SQL2 JOIN RIGHT SIDE took " + timeJoinRightSide
-                    + " ms. fetched" + rightRows.size() + " rows.");
+                    + " ms. fetched " + rightRows.size() + " rows.");
         }
 
         long timeMergeAndSort = System.currentTimeMillis();
@@ -275,12 +275,19 @@ public class QueryEngine {
                         + "SQL2 JOIN LEFT SIDE there are multiple inner splits.");
             }
             Set<Row> leftRows = new TreeSet<Row>(comparator);
-            leftRows.addAll(buildLeftRowsJoin(csi.getLeftInnerConstraints(),
-                    comparator, printIndentation + printIndentStep));
-            leftRows.addAll(buildLeftRowsJoin(csi.getRightInnerConstraints(),
-                    comparator, printIndentation + printIndentStep));
+            if (csi.getLeftInnerConstraints().isHasLeftConstraints()) {
+                leftRows.addAll(buildLeftRowsJoin(
+                        csi.getLeftInnerConstraints(), comparator,
+                        printIndentation + printIndentStep));
+            }
+            if (csi.getRightInnerConstraints().isHasLeftConstraints()) {
+                leftRows.addAll(buildLeftRowsJoin(
+                        csi.getRightInnerConstraints(), comparator,
+                        printIndentation + printIndentStep));
+            }
             return leftRows;
         }
+        
         Set<Row> leftRows = new TreeSet<Row>(comparator);
         QueryResult leftResult = execute(null, csi.getSource().getLeft(),
                 csi.getLeftConstraint(), null, 0, -1, printIndentation);
@@ -314,12 +321,14 @@ public class QueryEngine {
                         + "SQL2 JOIN RIGHT SIDE there are multiple inner splits.");
             }
             Set<Row> rightRows = new TreeSet<Row>(comparator);
-            rightRows.addAll(buildRightRowsJoin(csi.getLeftInnerConstraints(),
-                    rightConstraints, ignoreWhereConstraints, comparator,
-                    printIndentation + printIndentStep));
-            rightRows.addAll(buildRightRowsJoin(csi.getRightInnerConstraints(),
-                    rightConstraints, ignoreWhereConstraints, comparator,
-                    printIndentation + printIndentStep));
+                rightRows.addAll(buildRightRowsJoin(
+                        csi.getLeftInnerConstraints(), rightConstraints,
+                        ignoreWhereConstraints, comparator, printIndentation
+                                + printIndentStep));
+                rightRows.addAll(buildRightRowsJoin(
+                        csi.getRightInnerConstraints(), rightConstraints,
+                        ignoreWhereConstraints, comparator, printIndentation
+                                + printIndentStep));
             return rightRows;
         }
 
@@ -418,7 +427,7 @@ public class QueryEngine {
         sb.append(csi.getSource());
         sb.append(IOUtils.LINE_SEPARATOR);
         sb.append(genString(printIndentation));
-        sb.append("SQL2 JOIN left constraint: ");
+        sb.append("SQL2 JOIN left constraint:  ");
         sb.append(csi.getLeftConstraint());
         sb.append(IOUtils.LINE_SEPARATOR);
         sb.append(genString(printIndentation));

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/JoinTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/JoinTest.java?rev=1138141&r1=1138140&r2=1138141&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/JoinTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/JoinTest.java
Tue Jun 21 19:16:55 2011
@@ -29,24 +29,36 @@ public class JoinTest extends AbstractQu
 
     private Node node;
 
+    private Node n1;
+
+    private Node n2;
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        node = testRootNode.addNode("jointest");
+        node = testRootNode.addNode("jointest", "nt:unstructured");
 
-        Node n1 = node.addNode("node1");
+        n1 = node.addNode("node1", "nt:unstructured");
         n1.addMixin(NodeType.MIX_REFERENCEABLE);
-        testRootNode.getSession().save();
 
-        Node n2 = node.addNode("node2");
+        n2 = node.addNode("node2", "nt:unstructured");
         n2.addMixin(NodeType.MIX_REFERENCEABLE);
-        testRootNode.getSession().save();
 
-        Node n3 = node.addNode("node3");
+        Node n3 = node.addNode("node3", "nt:unstructured");
         n3.addMixin(NodeType.MIX_REFERENCEABLE);
         n3.setProperty("testref",
                 new String[] { n1.getIdentifier(), n2.getIdentifier() },
                 PropertyType.REFERENCE);
+
+        Node parent2 = testRootNode
+                .addNode("jointest_other", "nt:unstructured");
+        parent2.setProperty("p", "abc");
+
+        Node p2n1 = parent2.addNode("node4", "nt:unstructured");
+        p2n1.setProperty("p", "abc");
+
+        parent2.addNode("node5", "nt:unstructured");
+
         testRootNode.getSession().save();
     }
 
@@ -62,8 +74,9 @@ public class JoinTest extends AbstractQu
      * href="https://issues.apache.org/jira/browse/JCR-2718">JCR-2718</a>
      */
     public void testMultiValuedReferenceJoin() throws Exception {
-        String join = "SELECT a.*, b.*" + " FROM [nt:base] AS a"
-                + " INNER JOIN [nt:base] AS b ON a.[jcr:uuid] = b.testref";
+        String join = "SELECT a.*, b.*"
+                + " FROM [nt:unstructured] AS a"
+                + " INNER JOIN [nt:unstructured] AS b ON a.[jcr:uuid] = b.testref";
         checkResult(qm.createQuery(join, Query.JCR_SQL2).execute(), 2);
     }
 
@@ -74,8 +87,8 @@ public class JoinTest extends AbstractQu
     public void testJoinWithOR() throws Exception {
 
         String join = "SELECT a.*, b.*"
-                + " FROM [nt:base] AS a"
-                + " INNER JOIN [nt:base] AS b ON a.[jcr:uuid] = b.testref WHERE "
+                + " FROM [nt:unstructured] AS a"
+                + " INNER JOIN [nt:unstructured] AS b ON a.[jcr:uuid] = b.testref WHERE "
                 + "a.[jcr:primaryType] IS NOT NULL OR b.[jcr:primaryType] IS NOT NULL";
 
         Query q = qm.createQuery(join, Query.JCR_SQL2);
@@ -83,6 +96,32 @@ public class JoinTest extends AbstractQu
         checkResult(result, 2);
     }
 
+    public void testJoinWithOR2() throws Exception {
+
+        String join = "SELECT a.*, b.*"
+                + " FROM [nt:unstructured] AS a"
+                + " INNER JOIN [nt:unstructured] AS b ON ISCHILDNODE(b, a) WHERE "
+                + "a.[p] = 'abc' or b.[p] = 'abc' ";
+
+        Query q = qm.createQuery(join, Query.JCR_SQL2);
+        QueryResult result = q.execute();
+        checkResult(result, 2);
+    }
+
+    public void testJoinWithOR3() throws Exception {
+        StringBuilder join = new StringBuilder(
+                "SELECT a.* FROM [nt:unstructured] AS a");
+        join.append("  INNER JOIN [nt:unstructured] AS b ON ISCHILDNODE(b, a) ");
+        join.append("  WHERE  ");
+        join.append("  ( CONTAINS(b.*, 'abc' ) OR CONTAINS(a.*, 'abc') )  ");
+        join.append("  AND ");
+        join.append("  NAME(b) = 'node4' ");
+
+        Query q = qm.createQuery(join.toString(), Query.JCR_SQL2);
+        QueryResult result = q.execute();
+        checkResult(result, 1);
+    }
+
     /**
      * Test case for <a
      * href="https://issues.apache.org/jira/browse/JCR-2852">JCR-2852</a> <br>
@@ -104,8 +143,8 @@ public class JoinTest extends AbstractQu
         // AND ((NAME(parentRelationshipStatus) = 'parentRelationshipStatus'))
 
         StringBuilder join = new StringBuilder(
-                "SELECT a.*, b.* FROM [nt:base] AS a");
-        join.append("  INNER JOIN [nt:base] AS b ON a.[jcr:uuid] = b.testref ");
+                "SELECT a.*, b.* FROM [nt:unstructured] AS a");
+        join.append("  INNER JOIN [nt:unstructured] AS b ON a.[jcr:uuid] = b.testref ");
         join.append("  WHERE  ");
         join.append("  ISSAMENODE(b, '/testroot/jointest/node3') ");
         join.append("  AND ");
@@ -125,5 +164,4 @@ public class JoinTest extends AbstractQu
         QueryResult result = q.execute();
         checkResult(result, 2);
     }
-
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java?rev=1138141&r1=1138140&r2=1138141&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
Tue Jun 21 19:16:55 2011
@@ -65,6 +65,10 @@ public class TestAll extends TestCase {
         suite.addTestSuite(SimilarQueryTest.class);
         suite.addTestSuite(FulltextSQL2QueryTest.class);
         suite.addTestSuite(LimitAndOffsetTest.class);
+        suite.addTestSuite(SQL2NodeLocalNameTest.class);
+        suite.addTestSuite(SQL2OuterJoinTest.class);
+        suite.addTestSuite(SQL2PathEscapingTest.class);
+        suite.addTestSuite(SQL2QueryResultTest.class);
 
         return suite;
     }



Mime
View raw message