jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1023787 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join: AbstractRow.java JoinMerger.java JoinRow.java QueryEngine.java SelectorRow.java SimpleRow.java
Date Mon, 18 Oct 2010 13:22:34 GMT
Author: jukka
Date: Mon Oct 18 13:22:34 2010
New Revision: 1023787

URL: http://svn.apache.org/viewvc?rev=1023787&view=rev
Log:
JCR-2715: Improved join query performance

Improved row handling

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/AbstractRow.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinRow.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SelectorRow.java
  (with props)
Removed:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SimpleRow.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/AbstractRow.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/AbstractRow.java?rev=1023787&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/AbstractRow.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/AbstractRow.java
Mon Oct 18 13:22:34 2010
@@ -0,0 +1,78 @@
+/*
+ * 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.core.query.lucene.join;
+
+import java.util.Map;
+
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.query.Row;
+import javax.jcr.query.qom.Operand;
+import javax.jcr.query.qom.PropertyValue;
+
+abstract class AbstractRow implements Row {
+
+    private final Map<String, PropertyValue> columns;
+
+    private final OperandEvaluator evaluator;
+
+    protected AbstractRow(
+            Map<String, PropertyValue> columns, OperandEvaluator evaluator) {
+        this.columns = columns;
+        this.evaluator = evaluator;
+    }
+
+    public Value[] getValues() throws RepositoryException {
+        Value[] values = new Value[columns.size()];
+        for (Operand operand : columns.values()) {
+            values = evaluator.getValues(operand, this);
+        }
+        return values;
+    }
+
+    public Value getValue(String columnName)
+            throws ItemNotFoundException, RepositoryException {
+        Operand operand = columns.get(columnName);
+        if (operand != null) {
+            return evaluator.getValue(operand, this);
+        } else {
+            throw new ItemNotFoundException(
+                    "Column " + columnName + " is not included in this row");
+        }
+    }
+
+    public String getPath() throws RepositoryException {
+        Node node = getNode();
+        if (node != null) {
+            return node.getPath();
+        } else {
+            return null;
+        }
+    }
+
+    public String getPath(String selectorName) throws RepositoryException {
+        Node node = getNode(selectorName);
+        if (node != null) {
+            return node.getPath();
+        } else {
+            return null;
+        }
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/AbstractRow.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java?rev=1023787&r1=1023786&r2=1023787&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java
Mon Oct 18 13:22:34 2010
@@ -27,10 +27,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.Value;
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.Row;
 import javax.jcr.query.RowIterator;
@@ -86,9 +84,9 @@ abstract class JoinMerger {
 
     private final String[] selectorNames;
 
-    private final String[] columnNames;
+    private final Map<String, PropertyValue> columns;
 
-    private final PropertyValue[] operands;
+    private final String[] columnNames;
 
     protected final OperandEvaluator evaluator;
 
@@ -109,10 +107,9 @@ abstract class JoinMerger {
         this.selectorNames =
             selectors.toArray(new String[selectors.size()]);
 
+        this.columns = columns;
         this.columnNames =
             columns.keySet().toArray(new String[columns.size()]);
-        this.operands =
-            columns.values().toArray(new PropertyValue[columns.size()]);
 
         this.evaluator = evaluator;
         this.factory = factory;
@@ -229,30 +226,8 @@ abstract class JoinMerger {
      * @throws RepositoryException if the rows can't be joined
      */
     private Row mergeRow(Row left, Row right) throws RepositoryException {
-        Node[] nodes = new Node[selectorNames.length];
-        double[] scores = new double[selectorNames.length];
-        for (int i = 0; i < selectorNames.length; i++) {
-            String selector = selectorNames[i];
-            if (left != null && leftSelectors.contains(selector)) {
-                nodes[i] = left.getNode(selector);
-                scores[i] = left.getScore(selector);
-            } else if (right != null && rightSelectors.contains(selector)) {
-                nodes[i] = right.getNode(selector);
-                scores[i] = right.getScore(selector);
-            } else {
-                nodes[i] = null;
-                scores[i] = 0.0;
-            }
-        }
-
-        Value[] values = new Value[operands.length];
-        Row row = new SimpleRow(
-                columnNames, values, selectorNames, nodes, scores);
-        for (int i = 0; i < operands.length; i++) {
-            values[i] = evaluator.getValue(operands[i], row);
-        }
-
-        return row;
+        return new JoinRow(
+                columns, evaluator, left, leftSelectors, right, rightSelectors);
     }
 
     public abstract Set<String> getLeftValues(Row row)

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinRow.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinRow.java?rev=1023787&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinRow.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinRow.java
Mon Oct 18 13:22:34 2010
@@ -0,0 +1,114 @@
+/*
+ * 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.core.query.lucene.join;
+
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.query.Row;
+import javax.jcr.query.qom.PropertyValue;
+
+public class JoinRow extends AbstractRow {
+
+    private final Row leftRow;
+
+    private final Set<String> leftSelectors;
+
+    private final Row rightRow;
+
+    private final Set<String> rightSelectors;
+
+    public JoinRow(
+            Map<String, PropertyValue> columns, OperandEvaluator evaluator,
+            Row leftRow, Set<String> leftSelectors,
+            Row rightRow, Set<String> rightSelectors) {
+        super(columns, evaluator);
+        this.leftRow = leftRow;
+        this.leftSelectors = leftSelectors;
+        this.rightRow = rightRow;
+        this.rightSelectors = rightSelectors;
+    }
+
+    public Node getNode() throws RepositoryException {
+        throw new RepositoryException();
+    }
+
+    public Node getNode(String selectorName) throws RepositoryException {
+        Row row = getRow(selectorName);
+        if (row != null) {
+            return row.getNode(selectorName);
+        } else {
+            return null;
+        }
+    }
+
+    public double getScore() throws RepositoryException {
+        throw new RepositoryException();
+    }
+
+    public double getScore(String selectorName) throws RepositoryException {
+        Row row = getRow(selectorName);
+        if (row != null) {
+            return row.getScore(selectorName);
+        } else {
+            return 0.0;
+        }
+    }
+
+    private Row getRow(String selector) throws RepositoryException {
+        if (leftSelectors.contains(selector)) {
+            return leftRow;
+        } else if (rightSelectors.contains(selector)) {
+            return rightRow;
+        } else {
+            throw new RepositoryException(
+                    "Selector " + selector + " is not included in this row");
+        }
+    }
+
+    //--------------------------------------------------------------< Object >
+
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("{ ");
+        for (String selector : leftSelectors) {
+            builder.append(selector);
+            builder.append("=");
+            try {
+                builder.append(leftRow.getNode(selector));
+            } catch (RepositoryException e) {
+                builder.append(e.getMessage());
+            }
+            builder.append(" ");
+        }
+        for (String selector : rightSelectors) {
+            builder.append(selector);
+            builder.append("=");
+            try {
+                builder.append(rightRow.getNode(selector));
+            } catch (RepositoryException e) {
+                builder.append(e.getMessage());
+            }
+            builder.append(" ");
+        }
+        builder.append("}");
+        return builder.toString();
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinRow.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1023787&r1=1023786&r2=1023787&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
Mon Oct 18 13:22:34 2010
@@ -289,51 +289,21 @@ public class QueryEngine {
         final String[] columnNames =
             columnMap.keySet().toArray(new String[columnMap.size()]);
 
-        final double[] scores = new double[] { 1.0 };
-
-//        Iterator<Node> nodes =
-//            TreeTraverser.nodeIterator(session.getRootNode());
+        final String selectorName = selector.getSelectorName();
         RangeIterator rows = new RangeIteratorAdapter(query.execute().getNodes()) {
             @Override
             public Object next() {
-                try {
-                    Value[] values = new Value[columnNames.length];
-                    Row row = new SimpleRow(
-                            columnNames, values, selectorNames,
-                            new Node[] { (Node) super.next() }, scores);
-                    for (int i = 0; i < values.length; i++) {
-                        values[i] = combine(evaluator.getValues(
-                                columnMap.get(columnNames[i]), row));
-                    }
-                    return row;
-                } catch (RepositoryException e) {
-                    throw new RuntimeException(e);
-                }
+                Node node = (Node) super.next();
+                return new SelectorRow(
+                        columnMap, evaluator, selectorName, node, 1.0);
             }
         };
 
-//        RangeIterator filtered = new FilteredRangeIterator(
-//                rows, getPredicate(selector, constraint));
         QueryResult result = new SimpleQueryResult(
                 columnNames, selectorNames, new RowIteratorAdapter(rows));
         return sort(result, orderings);
     }
 
-    private Value combine(Value[] values) throws RepositoryException {
-        if (values.length == 1) {
-            return values[0];
-        } else {
-            StringBuilder builder = new StringBuilder();
-            for (int i = 0; i < values.length; i++) {
-                if (i > 0) {
-                    builder.append('\n');
-                }
-                builder.append(values[i].getString());
-            }
-            return valueFactory.createValue(builder.toString());
-        }
-    }
-
     private Map<String, PropertyValue> getColumnMap(
             Column[] columns, Map<String, NodeType> selectors)
             throws RepositoryException {

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SelectorRow.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SelectorRow.java?rev=1023787&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SelectorRow.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SelectorRow.java
Mon Oct 18 13:22:34 2010
@@ -0,0 +1,76 @@
+/*
+ * 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.core.query.lucene.join;
+
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.query.qom.PropertyValue;
+
+/**
+ * A row implementation for a query with just a single selector.
+ */
+public class SelectorRow extends AbstractRow {
+
+    private final String selector;
+
+    private final Node node;
+
+    private final double score;
+
+    public SelectorRow(
+            Map<String, PropertyValue> columns, OperandEvaluator evaluator,
+            String selector, Node node, double score) {
+        super(columns, evaluator);
+        this.selector = selector;
+        this.node = node;
+        this.score = score;
+    }
+
+    public Node getNode() {
+        return node;
+    }
+
+    public Node getNode(String selectorName) throws RepositoryException {
+        checkSelectorName(selectorName);
+        return node;
+    }
+
+    public double getScore() {
+        return score;
+    }
+
+    public double getScore(String selectorName) throws RepositoryException {
+        checkSelectorName(selectorName);
+        return score;
+    }
+
+    private void checkSelectorName(String name) throws RepositoryException {
+        if (!selector.equals(name)) {
+            throw new RepositoryException(
+                    "Selector " + name + " is not included in this row");
+        }
+    }
+
+    //--------------------------------------------------------------< Object >
+
+    public String toString() {
+        return "{ " + selector + ": " + node + " }";
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SelectorRow.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message