jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1401716 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast: ComparisonImpl.java PropertyValueImpl.java SelectorImpl.java SourceImpl.java
Date Wed, 24 Oct 2012 14:53:17 GMT
Author: thomasm
Date: Wed Oct 24 14:53:16 2012
New Revision: 1401716

URL: http://svn.apache.org/viewvc?rev=1401716&view=rev
Log:
OAK-361 QueryEngine JCR-SQL 'ESCAPE' parsing & support
OAK-347 QueryEngine 'like' interpretation error for paths

Modified:
    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/PropertyValueImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SourceImpl.java

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=1401716&r1=1401715&r2=1401716&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
Wed Oct 24 14:53:16 2012
@@ -136,28 +136,35 @@ public class ComparisonImpl extends Cons
     public void restrict(FilterImpl f) {
         PropertyValue v = operand2.currentValue();
         if (v != null) {
-            operand1.restrict(f, operator, v);
+       //     operand1.restrict(f, operator, v);
             // TODO OAK-347
-//            if (operator == Operator.LIKE) {
-//                String pattern;
-//                pattern = v.getString();
-//                LikePattern p = new LikePattern(pattern);
-//                String lowerBound = p.getLowerBound();
-//                String upperBound = p.getUpperBound();
-//                if (lowerBound == null && upperBound == null) {
-//                    // ignore
-//                } else if (operand1.supportsRangeConditions()) {
-//                    CoreValueFactory vf = query.getValueFactory();
-//                    if (lowerBound != null) {
-//                        operand1.restrict(f, Operator.GREATER_OR_EQUAL, vf.createValue(lowerBound));
-//                    }
-//                    if (upperBound != null) {
-//                        operand1.restrict(f, Operator.LESS_OR_EQUAL, vf.createValue(upperBound));
-//                    }
-//                }
-//            } else {
-//                operand1.restrict(f, operator, v);
-//            }
+            if (operator == Operator.LIKE) {
+                String pattern;
+                pattern = v.getValue(Type.STRING);
+                LikePattern p = new LikePattern(pattern);
+                String lowerBound = p.getLowerBound();
+                String upperBound = p.getUpperBound();
+                if (lowerBound == null && upperBound == null) {
+                    // ignore
+                } else if (lowerBound.equals(upperBound)) {
+                    // no wildcards
+                    operand1.restrict(f, Operator.EQUAL, v);
+                } else if (operand1.supportsRangeConditions()) {
+                    if (lowerBound != null) {
+                        PropertyValue pv = PropertyValues.newString(lowerBound);
+                        operand1.restrict(f, Operator.GREATER_OR_EQUAL, pv);
+                    }
+                    if (upperBound != null) {
+                        PropertyValue pv = PropertyValues.newString(upperBound);
+                        operand1.restrict(f, Operator.LESS_OR_EQUAL, pv);
+                    }
+                } else {
+                    // path conditions
+                    operand1.restrict(f, operator, v);
+                }
+            } else {
+                operand1.restrict(f, operator, v);
+            }
         }
     }
 

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=1401716&r1=1401715&r2=1401716&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
Wed Oct 24 14:53:16 2012
@@ -29,6 +29,7 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.query.Query;
 import org.apache.jackrabbit.oak.query.SQL2Parser;
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
 import org.apache.jackrabbit.oak.spi.query.PropertyValues;
@@ -80,6 +81,14 @@ public class PropertyValueImpl extends D
         }
         return s;
     }
+    
+    @Override
+    public boolean supportsRangeConditions() {
+        // the jcr:path pseudo-property doesn't support LIKE conditions,
+        // because the path doesn't might be escaped, and possibly contain
+        // expressions that would result in incorrect results (/test[1] for example)
+        return !propertyName.equals(Query.JCR_PATH);
+    }
 
     @Override
     public PropertyValue currentProperty() {
@@ -119,7 +128,8 @@ public class PropertyValueImpl extends D
         // warning: the returned property state may have a mixed type
         // (not all values may have the same type)
 
-        //TODO this doesn't play well with the idea that the types may be different
+        // TODO currently all property values are converted to strings - 
+        // this doesn't play well with the idea that the types may be different
         List<String> values = new ArrayList<String>();
         for (PropertyState p : tree.getProperties()) {
             if (matchesPropertyType(p)) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java?rev=1401716&r1=1401715&r2=1401716&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
Wed Oct 24 14:53:16 2012
@@ -28,6 +28,7 @@ import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.nodetype.NodeTypeManager;
 
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.PropertyValue;
 import org.apache.jackrabbit.oak.api.Tree;
@@ -138,7 +139,7 @@ public class SelectorImpl extends Source
                 continue;
             }
             if (nodeTypeName != null
-                    && !nodeTypeName.equals(NodeTypeConstants.NT_BASE)
+                    && !nodeTypeName.equals(JcrConstants.NT_BASE)
                     && !evaluateTypeMatch(tree)) {
                 continue;
             }
@@ -155,9 +156,9 @@ public class SelectorImpl extends Source
 
     private boolean evaluateTypeMatch(Tree tree) {
         Set<String> primary =
-                getStrings(tree, NodeTypeConstants.JCR_PRIMARYTYPE);
+                getStrings(tree, JcrConstants.JCR_PRIMARYTYPE);
         Set<String> mixins =
-                getStrings(tree, NodeTypeConstants.JCR_MIXINTYPES);
+                getStrings(tree, JcrConstants.JCR_MIXINTYPES);
 
         // TODO: Should retrieve matching node types only once per query
         // execution instead of again and again for each return row
@@ -188,7 +189,7 @@ public class SelectorImpl extends Source
         return false;
     }
 
-    private Set<String> getStrings(Tree tree, String name) {
+    private static Set<String> getStrings(Tree tree, String name) {
         ImmutableSet.Builder<String> builder = ImmutableSet.builder();
         PropertyState property = tree.getProperty(name);
         if (property != null) {
@@ -199,7 +200,7 @@ public class SelectorImpl extends Source
         return builder.build();
     }
 
-    private boolean evaluateTypeMatch(
+    private static boolean evaluateTypeMatch(
             NodeType type, Set<String> primary, Set<String> mixins) {
         String name = type.getName();
         if (type.isMixin()) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SourceImpl.java?rev=1401716&r1=1401715&r2=1401716&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SourceImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SourceImpl.java
Wed Oct 24 14:53:16 2012
@@ -127,6 +127,7 @@ public abstract class SourceImpl extends
     /**
      * Get the query plan.
      *
+     * @param root the root
      * @return the query plan
      */
     public abstract String getPlan(NodeState root);



Mime
View raw message