jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1483339 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/query/ast/ test/resources/org/apache/jackrabbit/oak/query/
Date Thu, 16 May 2013 13:09:51 GMT
Author: thomasm
Date: Thu May 16 13:09:50 2013
New Revision: 1483339

URL: http://svn.apache.org/r1483339
Log:
OAK-824 Query engine: automatic expansion of "x=1 or x=2" to "(x is not null) and (x=1 or
x=2)"

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AndImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ChildNodeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ConstraintImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DescendantNodeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DynamicOperandImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchScoreImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LengthImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LowerCaseImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeLocalNameImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeNameImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NotImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/OrImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyExistenceImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyValueImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SameNodeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/UpperCaseImpl.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/AndImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AndImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AndImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AndImpl.java
Thu May 16 13:09:50 2013
@@ -18,8 +18,12 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
+import java.util.Set;
+
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
 
+import com.google.common.collect.Sets;
+
 /**
  * An AND condition.
  */
@@ -39,6 +43,15 @@ public class AndImpl extends ConstraintI
     public ConstraintImpl getConstraint2() {
         return constraint2;
     }
+    
+    @Override
+    public Set<PropertyExistenceImpl> getPropertyExistenceConditions() {
+        Set<PropertyExistenceImpl> s1 = constraint1.getPropertyExistenceConditions();
+        Set<PropertyExistenceImpl> s2 = constraint2.getPropertyExistenceConditions();
+        Set<PropertyExistenceImpl> result = Sets.newHashSet(s1);
+        result.addAll(s2);
+        return result;
+    }
 
     @Override
     public boolean evaluate() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ChildNodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ChildNodeImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ChildNodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ChildNodeImpl.java
Thu May 16 13:09:50 2013
@@ -18,6 +18,9 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
+import java.util.Collections;
+import java.util.Set;
+
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
 import org.apache.jackrabbit.oak.spi.query.Filter;
@@ -49,6 +52,11 @@ public class ChildNodeImpl extends Const
     public void bindSelector(SourceImpl source) {
         selector = source.getExistingSelector(selectorName);
     }
+    
+    @Override
+    public Set<PropertyExistenceImpl> getPropertyExistenceConditions() {
+        return Collections.emptySet();
+    }
 
     @Override
     public boolean evaluate() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java
Thu May 16 13:09:50 2013
@@ -18,6 +18,9 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
+import java.util.Collections;
+import java.util.Set;
+
 import javax.jcr.PropertyType;
 
 import org.apache.jackrabbit.oak.api.PropertyValue;
@@ -58,6 +61,15 @@ public class ComparisonImpl extends Cons
         }
         return ifUnknown;
     }
+    
+    @Override
+    public Set<PropertyExistenceImpl> getPropertyExistenceConditions() {
+        PropertyExistenceImpl p = operand1.getPropertyExistence();
+        if (p == null) {
+            Collections.emptySet();
+        }
+        return Collections.singleton(p);
+    }
 
     @Override
     public boolean evaluate() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ConstraintImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ConstraintImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ConstraintImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ConstraintImpl.java
Thu May 16 13:09:50 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
+import java.util.Set;
+
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
 
 /**
@@ -29,6 +31,17 @@ public abstract class ConstraintImpl ext
      * @return true if the constraint matches
      */
     public abstract boolean evaluate();
+    
+    /**
+     * Get the set of property existence conditions that can be derived for this
+     * condition. For example, for the condition "x=1 or x=2", the property
+     * existence condition is "x is not null". For the condition "x=1 or y=2",
+     * there is no such condition. For the condition "x=1 and y=1", there are
+     * two (x is not null, and y is not null).
+     * 
+     * @return the common property existence condition (possibly empty)
+     */
+    public abstract Set<PropertyExistenceImpl> getPropertyExistenceConditions();
 
     /**
      * Apply the condition to the filter, further restricting the filter if

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DescendantNodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DescendantNodeImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DescendantNodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DescendantNodeImpl.java
Thu May 16 13:09:50 2013
@@ -18,6 +18,9 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
+import java.util.Collections;
+import java.util.Set;
+
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
 import org.apache.jackrabbit.oak.spi.query.Filter;
@@ -35,6 +38,11 @@ public class DescendantNodeImpl extends 
         this.selectorName = selectorName;
         this.ancestorPath = ancestorPath;
     }
+    
+    @Override
+    public Set<PropertyExistenceImpl> getPropertyExistenceConditions() {
+        return Collections.emptySet();
+    }
 
     @Override
     public boolean evaluate() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DynamicOperandImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DynamicOperandImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DynamicOperandImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/DynamicOperandImpl.java
Thu May 16 13:09:50 2013
@@ -45,4 +45,12 @@ public abstract class DynamicOperandImpl
 
     abstract int getPropertyType();
 
+    /**
+     * Get the property existence condition for this operand, if this operand is
+     * used as part of a condition.
+     * 
+     * @return the property existence condition, or null if none
+     */
+    public abstract PropertyExistenceImpl getPropertyExistence();
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java
Thu May 16 13:09:50 2013
@@ -23,6 +23,8 @@ import static org.apache.jackrabbit.oak.
 
 import java.text.ParseException;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Set;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.PropertyValue;
@@ -98,6 +100,14 @@ public class FullTextSearchImpl extends 
         builder.append(')');
         return builder.toString();
     }
+    
+    @Override
+    public Set<PropertyExistenceImpl> getPropertyExistenceConditions() {
+        if (propertyName == null) {
+            return Collections.emptySet();
+        }
+        return Collections.singleton(new PropertyExistenceImpl(selector, selectorName, propertyName));
+    }
 
     @Override
     public boolean evaluate() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchScoreImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchScoreImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchScoreImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchScoreImpl.java
Thu May 16 13:09:50 2013
@@ -46,6 +46,11 @@ public class FullTextSearchScoreImpl ext
     public String toString() {
         return "score(" + quote(selectorName) + ')';
     }
+    
+    @Override
+    public PropertyExistenceImpl getPropertyExistence() {
+        return null;
+    }
 
     @Override
     public PropertyValue currentProperty() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LengthImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LengthImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LengthImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LengthImpl.java
Thu May 16 13:09:50 2013
@@ -48,6 +48,11 @@ public class LengthImpl extends DynamicO
     public String toString() {
         return "length(" + propertyValue + ')';
     }
+    
+    @Override
+    public PropertyExistenceImpl getPropertyExistence() {
+        return propertyValue.getPropertyExistence();
+    }
 
     @Override
     public PropertyValue currentProperty() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LowerCaseImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LowerCaseImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LowerCaseImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LowerCaseImpl.java
Thu May 16 13:09:50 2013
@@ -50,6 +50,11 @@ public class LowerCaseImpl extends Dynam
     public String toString() {
         return "lower(" + operand + ')';
     }
+    
+    @Override
+    public PropertyExistenceImpl getPropertyExistence() {
+        return operand.getPropertyExistence();
+    }
 
     @Override
     public PropertyValue currentProperty() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeLocalNameImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeLocalNameImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeLocalNameImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeLocalNameImpl.java
Thu May 16 13:09:50 2013
@@ -51,6 +51,11 @@ public class NodeLocalNameImpl extends D
     public void bindSelector(SourceImpl source) {
         selector = source.getExistingSelector(selectorName);
     }
+    
+    @Override
+    public PropertyExistenceImpl getPropertyExistence() {
+        return null;
+    }
 
     @Override
     public PropertyValue currentProperty() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeNameImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeNameImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeNameImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NodeNameImpl.java
Thu May 16 13:09:50 2013
@@ -58,6 +58,11 @@ public class NodeNameImpl extends Dynami
     public boolean supportsRangeConditions() {
         return false;
     }
+    
+    @Override
+    public PropertyExistenceImpl getPropertyExistence() {
+        return null;
+    }
 
     @Override
     public PropertyValue currentProperty() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NotImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NotImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NotImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/NotImpl.java
Thu May 16 13:09:50 2013
@@ -18,6 +18,9 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
+import java.util.Collections;
+import java.util.Set;
+
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
 
 /**
@@ -39,6 +42,11 @@ public class NotImpl extends ConstraintI
     public boolean evaluate() {
         return !constraint.evaluate();
     }
+    
+    @Override
+    public Set<PropertyExistenceImpl> getPropertyExistenceConditions() {
+        return Collections.emptySet();
+    }
 
     @Override
     boolean accept(AstVisitor v) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/OrImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/OrImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/OrImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/OrImpl.java
Thu May 16 13:09:50 2013
@@ -18,8 +18,12 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
+import java.util.Set;
+
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
 
+import com.google.common.collect.Sets;
+
 /**
  * An "or" condition.
  */
@@ -40,6 +44,19 @@ public class OrImpl extends ConstraintIm
     public ConstraintImpl getConstraint2() {
         return constraint2;
     }
+    
+    @Override
+    public Set<PropertyExistenceImpl> getPropertyExistenceConditions() {
+        Set<PropertyExistenceImpl> s1 = constraint1.getPropertyExistenceConditions();
+        if (s1.isEmpty()) {
+            return s1;
+        }
+        Set<PropertyExistenceImpl> s2 = constraint2.getPropertyExistenceConditions();
+        if (s2.isEmpty()) {
+            return s2;
+        }
+        return Sets.intersection(s1, s2);
+    }
 
     @Override
     public boolean evaluate() {
@@ -58,8 +75,13 @@ public class OrImpl extends ConstraintIm
 
     @Override
     public void restrict(FilterImpl f) {
-        // ignore
-        // TODO convert OR conditions to UNION
+        Set<PropertyExistenceImpl> set = getPropertyExistenceConditions();
+        if (set.isEmpty()) {
+            return;
+        }
+        for (PropertyExistenceImpl p : set) {
+            p.restrict(f);
+        }
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyExistenceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyExistenceImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyExistenceImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyExistenceImpl.java
Thu May 16 13:09:50 2013
@@ -18,6 +18,9 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
+import java.util.Collections;
+import java.util.Set;
+
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
 
 /**
@@ -29,6 +32,12 @@ public class PropertyExistenceImpl exten
     private final String propertyName;
     private SelectorImpl selector;
 
+    public PropertyExistenceImpl(SelectorImpl selector, String selectorName, String propertyName)
{
+        this.selector = selector;
+        this.selectorName = selectorName;
+        this.propertyName = propertyName;
+    }
+    
     public PropertyExistenceImpl(String selectorName, String propertyName) {
         this.selectorName = selectorName;
         this.propertyName = propertyName;
@@ -40,6 +49,11 @@ public class PropertyExistenceImpl exten
     }
 
     @Override
+    public Set<PropertyExistenceImpl> getPropertyExistenceConditions() {
+        return Collections.singleton(this);
+    }
+
+    @Override
     boolean accept(AstVisitor v) {
         return v.visit(this);
     }
@@ -66,5 +80,27 @@ public class PropertyExistenceImpl exten
             s.restrictSelector(this);
         }
     }
+    
+    @Override
+    public int hashCode() {
+        return ((selectorName == null) ? 0 : selectorName.hashCode()) * 31 +
+                ((propertyName == null) ? 0 : propertyName.hashCode());
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        } else if (obj == null || getClass() != obj.getClass()) {
+            return false;
+        }
+        PropertyExistenceImpl other = (PropertyExistenceImpl) obj;
+        return equalsStrings(selectorName, other.selectorName) &&
+                equalsStrings(propertyName, other.propertyName);
+    }
+    
+    private static boolean equalsStrings(String a, String b) {
+        return a == null || b == null ? a == b : a.equals(b);
+    }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyValueImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyValueImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyValueImpl.java
Thu May 16 13:09:50 2013
@@ -89,6 +89,14 @@ public class PropertyValueImpl extends D
         // expressions that would result in incorrect results (/test[1] for example)
         return !propertyName.equals(Query.JCR_PATH);
     }
+    
+    @Override
+    public PropertyExistenceImpl getPropertyExistence() {
+        if (propertyName.equals("*")) {
+            return null;
+        }
+        return new PropertyExistenceImpl(selector, selectorName, propertyName);
+    }
 
     @Override
     public PropertyValue currentProperty() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SameNodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SameNodeImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SameNodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SameNodeImpl.java
Thu May 16 13:09:50 2013
@@ -18,6 +18,9 @@
  */
 package org.apache.jackrabbit.oak.query.ast;
 
+import java.util.Collections;
+import java.util.Set;
+
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
 import org.apache.jackrabbit.oak.spi.query.Filter;
 
@@ -41,6 +44,11 @@ public class SameNodeImpl extends Constr
         // TODO normalize paths
         return selector.currentPath().equals(p);
     }
+    
+    @Override
+    public Set<PropertyExistenceImpl> getPropertyExistenceConditions() {
+        return Collections.emptySet();
+    }
 
     @Override
     boolean accept(AstVisitor v) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/UpperCaseImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/UpperCaseImpl.java?rev=1483339&r1=1483338&r2=1483339&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/UpperCaseImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/UpperCaseImpl.java
Thu May 16 13:09:50 2013
@@ -50,6 +50,11 @@ public class UpperCaseImpl extends Dynam
     public String toString() {
         return "upper(" + operand + ')';
     }
+    
+    @Override
+    public PropertyExistenceImpl getPropertyExistence() {
+        return operand.getPropertyExistence();
+    }
 
     @Override
     public PropertyValue currentProperty() {

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=1483339&r1=1483338&r2=1483339&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
Thu May 16 13:09:50 2013
@@ -25,6 +25,18 @@
 
 # property type (value prefix) index
 
+explain select * from [nt:base] where [jcr:uuid]=1 or [b]=2
+[nt:base] as [nt:base] /* traverse "*" */
+
+explain select * from [nt:base] where length([jcr:uuid])=1 or upper([jcr:uuid])='1' or lower([jcr:uuid])='3'
+[nt:base] as [nt:base] /* property jcr:uuid */
+
+explain select * from [nt:base] where [jcr:uuid] = '1' or ([jcr:uuid] = '2' and [b] = '3')
+[nt:base] as [nt:base] /* property jcr:uuid */
+
+explain select * from [nt:base] where [jcr:uuid] = '1' or [jcr:uuid] = '2'
+[nt:base] as [nt:base] /* property jcr:uuid */
+
 explain select * from [nt:base] where [jcr:uuid] = '123'
 [nt:base] as [nt:base] /* property jcr:uuid=123 where [nt:base].[jcr:uuid] = cast('123' as
string) */
 



Mime
View raw message