jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1503252 - in /jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query: QueryPlanTest.java QueryTest.java
Date Mon, 15 Jul 2013 13:59:01 GMT
Author: thomasm
Date: Mon Jul 15 13:59:00 2013
New Revision: 1503252

URL: http://svn.apache.org/r1503252
Log:
OAK-894 Query: better cost estimates for indexes (test case)

Added:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryPlanTest.java
Modified:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java

Added: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryPlanTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryPlanTest.java?rev=1503252&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryPlanTest.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryPlanTest.java
Mon Jul 15 13:59:00 2013
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.query;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.RowIterator;
+
+import org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest;
+import org.apache.jackrabbit.oak.jcr.NodeStoreFixture;
+import org.junit.Test;
+
+/**
+ * Tests query plans.
+ */
+public class QueryPlanTest extends AbstractRepositoryTest {
+
+    public QueryPlanTest(NodeStoreFixture fixture) {
+        super(fixture);
+    }
+    
+    @Test
+    public void nodeType() throws Exception {
+        Session session = getAdminSession();
+        QueryManager qm = session.getWorkspace().getQueryManager();
+        Node testRootNode = session.getRootNode().addNode("testroot");
+        Node n1 = testRootNode.addNode("node1");
+        Node n2 = n1.addNode("node2");
+        n2.addNode("node3");
+        session.save();
+       
+        String sql2 = "select [jcr:path] as [path] from [nt:base] " + 
+                "where [node2/node3/jcr:primaryType] is not null";
+        
+        Query q;
+        QueryResult result;
+        RowIterator it;
+        
+        q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
+        result = q.execute();
+        it = result.getRows();
+        assertTrue(it.hasNext());
+        String plan = it.nextRow().getValue("plan").getString();
+        // should not use the index on "jcr:primaryType"
+        assertEquals("[nt:base] as [nt:base] /* traverse \"*\" " + 
+                "where [nt:base].[node2/node3/jcr:primaryType] is not null */", 
+                plan);
+        
+        // verify the result
+        q = qm.createQuery(sql2, Query.JCR_SQL2);
+        result = q.execute();
+        it = result.getRows();
+        assertTrue(it.hasNext());
+        String path = it.nextRow().getValue("path").getString();
+        assertEquals("/testroot/node1", path);
+        
+    }
+}

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java?rev=1503252&r1=1503251&r2=1503252&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
Mon Jul 15 13:59:00 2013
@@ -43,12 +43,10 @@ import javax.jcr.query.Row;
 import javax.jcr.query.RowIterator;
 
 import org.apache.jackrabbit.commons.JcrUtils;
-import org.apache.jackrabbit.commons.iterator.RowIterable;
 import org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest;
 import org.apache.jackrabbit.oak.jcr.NodeStoreFixture;
 import org.junit.Test;
 
-
 /**
  * Tests the query feature.
  */
@@ -227,8 +225,8 @@ public class QueryTest extends AbstractR
         QueryManager qm = session.getWorkspace().getQueryManager();
         Query q = qm.createQuery("//element(*, nt:folder)", Query.XPATH);
         Set<String> paths = new HashSet<String>();
-        for (Row r : new RowIterable(q.execute().getRows())) {
-            paths.add(r.getPath());
+        for (RowIterator it = q.execute().getRows(); it.hasNext();) {
+            paths.add(it.nextRow().getPath());
         }
         assertEquals(new HashSet<String>(Arrays.asList("/folder1", "/folder2", "/folder2/folder3")),
                 paths);



Mime
View raw message