Return-Path: X-Original-To: apmail-jackrabbit-commits-archive@www.apache.org Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9539099A8 for ; Tue, 28 Feb 2012 10:10:30 +0000 (UTC) Received: (qmail 3825 invoked by uid 500); 28 Feb 2012 10:10:30 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 3777 invoked by uid 500); 28 Feb 2012 10:10:29 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 3764 invoked by uid 99); 28 Feb 2012 10:10:29 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Feb 2012 10:10:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Feb 2012 10:10:24 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2C91D23888E4; Tue, 28 Feb 2012 10:10:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1294544 - in /jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader: ./ Cursor.java Filter.java Index.java IndexReader.java NodeReader.java TraversingCursor.java TraversingReader.java Date: Tue, 28 Feb 2012 10:10:02 -0000 To: commits@jackrabbit.apache.org From: thomasm@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120228101003.2C91D23888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: thomasm Date: Tue Feb 28 10:10:02 2012 New Revision: 1294544 URL: http://svn.apache.org/viewvc?rev=1294544&view=rev Log: Query implementation (WIP) Added: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/ - copied from r1292828, jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/index/ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/Cursor.java jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/Filter.java jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/IndexReader.java - copied, changed from r1292828, jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/index/Index.java jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/NodeReader.java jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/TraversingCursor.java jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/TraversingReader.java Removed: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/Index.java Added: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/Cursor.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/Cursor.java?rev=1294544&view=auto ============================================================================== --- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/Cursor.java (added) +++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/Cursor.java Tue Feb 28 10:10:02 2012 @@ -0,0 +1,49 @@ +/* + * 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.query.reader; + +import org.apache.jackrabbit.mk.simple.NodeImpl; + +/** + * A cursor to read a number of nodes sequentially. + */ +public interface Cursor { + + /** + * Skip to the next node if one is available. + * + * @return true if another row is available + */ + boolean next(); + + /** + * The path of the current node. + * + * @return the path + */ + String currentPath(); + + /** + * The current node. + * + * @return the node + */ + NodeImpl currentNode(); + +} Added: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/Filter.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/Filter.java?rev=1294544&view=auto ============================================================================== --- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/Filter.java (added) +++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/Filter.java Tue Feb 28 10:10:02 2012 @@ -0,0 +1,124 @@ +/* + * 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.query.reader; + +/** + * An index filter / lookup condition. + */ +public class Filter { + + /** + * The path, or "/" (the root node, meaning no filter) if not set. + */ + private String path = "/"; + + /** + * The node type, or null if not set. + */ + private String nodeType; + + /** + * The value prefix, or null if not set. + */ + private String valuePrefix; + + /** + * The first value to read, or null to read from the beginning. + */ + private String first; + + private boolean firstExcluding; + + /** + * The last value to read, or null to read until the end. + */ + private String last; + + private boolean lastExcluding; + + /** + * Only return distinct values. + */ + private boolean distinct; + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getNodeType() { + return nodeType; + } + + public void setNodeType(String nodeType) { + this.nodeType = nodeType; + } + + public String getValuePrefix() { + return valuePrefix; + } + + public void setValuePrefix(String valuePrefix) { + this.valuePrefix = valuePrefix; + } + + public String getFirst() { + return first; + } + + public void setFirst(String first) { + this.first = first; + } + + public boolean isFirstExcluding() { + return firstExcluding; + } + + public void setFirstExcluding(boolean firstExcluding) { + this.firstExcluding = firstExcluding; + } + + public String getLast() { + return last; + } + + public void setLast(String last) { + this.last = last; + } + + public boolean isLastExcluding() { + return lastExcluding; + } + + public void setLastExcluding(boolean lastExcluding) { + this.lastExcluding = lastExcluding; + } + + public boolean isDistinct() { + return distinct; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + +} Copied: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/IndexReader.java (from r1292828, jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/index/Index.java) URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/IndexReader.java?p2=jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/IndexReader.java&p1=jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/index/Index.java&r1=1292828&r2=1294544&rev=1294544&view=diff ============================================================================== --- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/index/Index.java (original) +++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/IndexReader.java Tue Feb 28 10:10:02 2012 @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.jackrabbit.query.index; +package org.apache.jackrabbit.query.reader; -public class Index { +public class IndexReader { /** * The path of what the index contains, or null if not set. @@ -90,4 +90,9 @@ public class Index { return buff.toString(); } + public Cursor execute() { + // TODO Auto-generated method stub + return null; + } + } Added: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/NodeReader.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/NodeReader.java?rev=1294544&view=auto ============================================================================== --- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/NodeReader.java (added) +++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/NodeReader.java Tue Feb 28 10:10:02 2012 @@ -0,0 +1,45 @@ +/* + * 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.query.reader; + +/** + * A node reader. The reader should use the data in the filter if possible to speed up reading. + */ +public interface NodeReader { + + /** + * Estimate the cost to use this reader with the given filter. The returned + * cost is a value between 1 (very fast; lookup of a unique node) and the + * estimated number of nodes to traverse. + * + * @param filter the filter + * @return the estimated cost in number of read nodes + */ + double getCost(Filter filter); + + /** + * Start reading nodes. + * + * @param filter the filter + * @param revisionId the revision + * @return a cursor to iterate over the result + */ + Cursor query(Filter filter, String revisionId); + +} Added: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/TraversingCursor.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/TraversingCursor.java?rev=1294544&view=auto ============================================================================== --- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/TraversingCursor.java (added) +++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/TraversingCursor.java Tue Feb 28 10:10:02 2012 @@ -0,0 +1,96 @@ +/* + * 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.query.reader; + +import java.util.ArrayList; +import org.apache.jackrabbit.mk.api.MicroKernel; +import org.apache.jackrabbit.mk.simple.NodeImpl; +import org.apache.jackrabbit.mk.util.PathUtils; + +/** + * A cursor that reads all nodes in a given subtree. + */ +public class TraversingCursor implements Cursor { + + private static final int CHILD_COUNT = 2000; + + private MicroKernel mk; + private String revisionId; + private ArrayList nodes = new ArrayList(); + private NodeImpl currentNode; + private String currentNodeName; + + public TraversingCursor(MicroKernel mk, String revisionId, String path) { + this.mk = mk; + this.revisionId = revisionId; + loadDepth(path, 0); + } + + private void loadDepth(String path, long offset) { + while (true) { + String s = mk.getNodes(path, revisionId, 0, offset, CHILD_COUNT); + NodeCursor c = new NodeCursor(); + c.node = NodeImpl.parse(s); + c.node.setPath(path); + nodes.add(c); + String child = c.node.getChildNodeName(0); + if (child != null) { + path = PathUtils.concat(path, child); + } else { + break; + } + } + } + + @Override + public NodeImpl currentNode() { + if (currentNode == null) { + currentNode = NodeImpl.parse(mk.getNodes(currentPath(), revisionId)); + } + return currentNode; + } + + @Override + public String currentPath() { + NodeCursor c = nodes.get(nodes.size() - 1); + return PathUtils.concat(c.node.getPath(), currentNodeName); + } + + @Override + public boolean next() { + currentNode = null; + while (true) { + if (nodes.size() == 0) { + return false; + } + NodeCursor c = nodes.get(nodes.size() - 1); + long pos = c.pos++ % CHILD_COUNT; + currentNodeName = c.node.getChildNodeName(pos); + if (currentNodeName != null) { + return true; + } + nodes.remove(nodes.size() - 1); + if (c.pos <= c.node.getTotalChildNodeCount()) { + loadDepth(c.node.getPath(), c.pos); + } + } + } + + static class NodeCursor { + NodeImpl node; + long offset; + long pos; + } + +} Added: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/TraversingReader.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/TraversingReader.java?rev=1294544&view=auto ============================================================================== --- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/TraversingReader.java (added) +++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/query/reader/TraversingReader.java Tue Feb 28 10:10:02 2012 @@ -0,0 +1,51 @@ +/* + * 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.query.reader; + +import org.apache.jackrabbit.mk.api.MicroKernel; +import org.apache.jackrabbit.mk.util.PathUtils; + +public class TraversingReader implements NodeReader { + + private final MicroKernel mk; + + public TraversingReader(MicroKernel mk) { + this.mk = mk; + } + + @Override + public Cursor query(Filter filter, String revisionId) { + return new TraversingCursor(mk, revisionId, filter.getPath()); + } + + @Override + public double getCost(Filter filter) { + String path = filter.getPath(); + // TODO estimate or read the node count + double nodeCount = 10000000; + if (!PathUtils.denotesRoot(path)) { + for (int depth = PathUtils.getDepth(path); depth > 0; depth--) { + // estimate 10 child nodes per node + nodeCount /= 10; + } + } + return nodeCount; + } + +}