You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2014/11/27 12:35:58 UTC
svn commit: r1642112 - in /jackrabbit/oak/branches/1.0: ./
oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/
oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/
Author: chetanm
Date: Thu Nov 27 11:35:58 2014
New Revision: 1642112
URL: http://svn.apache.org/r1642112
Log:
OAK-2278 - Make current testcases pass with new index implementation
Merging revisions 1641597,1641598
Modified:
jackrabbit/oak/branches/1.0/ (props changed)
jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java
jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
Propchange: jackrabbit/oak/branches/1.0/
------------------------------------------------------------------------------
Merged /jackrabbit/oak/trunk:r1641597-1641598
Modified: jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java?rev=1642112&r1=1642111&r2=1642112&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java (original)
+++ jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexPlanner.java Thu Nov 27 11:35:58 2014
@@ -60,14 +60,19 @@ class IndexPlanner {
IndexPlan getPlan() {
IndexPlan.Builder builder = getPlanBuilder();
- if (defn.isTestMode()
- && builder == null){
- if (notSupportedFeature()) {
- return null;
- }
- String msg = String.format("No plan found for filter [%s] " +
- "while using definition [%s] and testMode is found to be enabled", filter, defn);
- throw new IllegalStateException(msg);
+ if (defn.isTestMode()){
+ if ( builder == null) {
+ if (notSupportedFeature()) {
+ return null;
+ }
+ String msg = String.format("No plan found for filter [%s] " +
+ "while using definition [%s] and testMode is found to be enabled", filter, defn);
+ throw new IllegalStateException(msg);
+ } else {
+ builder.setEstimatedEntryCount(1)
+ .setCostPerExecution(1e-3)
+ .setCostPerEntry(1e-3);
+ }
}
return builder != null ? builder.build() : null;
@@ -157,6 +162,11 @@ class IndexPlanner {
//TODO Support for property existence queries
//TODO support for nodeName queries
+
+ //Above logic would not return any plan for pure nodeType based query like
+ //select * from nt:unstructured. We can do that but this is better handled
+ //by NodeType index
+
return null;
}
@@ -250,6 +260,7 @@ class IndexPlanner {
&& filter.getPropertyRestrictions().isEmpty()){
//This mode includes name(), localname() queries
//OrImpl [a/name] = 'Hello' or [b/name] = 'World'
+ //Relative parent properties where [../foo1] is not null
return true;
}
return false;
Modified: jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java?rev=1642112&r1=1642111&r2=1642112&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java (original)
+++ jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java Thu Nov 27 11:35:58 2014
@@ -651,6 +651,22 @@ public class LucenePropertyIndex impleme
}
}
+ private static int determinePropertyType(PropertyDefinition defn, PropertyRestriction pr) {
+ int typeFromRestriction = pr.propertyType;
+ if (typeFromRestriction == PropertyType.UNDEFINED) {
+ //If no explicit type defined then determine the type from restriction
+ //value
+ if (pr.first != null && pr.first.getType() != Type.UNDEFINED) {
+ typeFromRestriction = pr.first.getType().tag();
+ } else if (pr.last != null && pr.last.getType() != Type.UNDEFINED) {
+ typeFromRestriction = pr.last.getType().tag();
+ } else if (pr.list != null && !pr.list.isEmpty()){
+ typeFromRestriction = pr.list.get(0).getType().tag();
+ }
+ }
+ return getPropertyType(defn, pr.propertyName, typeFromRestriction);
+ }
+
private static int getPropertyType(PropertyDefinition defn, String name, int defaultVal){
if (defn.isTypeDefined()) {
return defn.getType();
@@ -690,7 +706,7 @@ public class LucenePropertyIndex impleme
@CheckForNull
private static Query createQuery(PropertyRestriction pr,
PropertyDefinition defn) {
- int propType = getPropertyType(defn, pr.propertyName, pr.propertyType);
+ int propType = determinePropertyType(defn, pr);
switch (propType) {
case PropertyType.DATE: {
Long first = pr.first != null ? FieldFactory.dateToLong(pr.first.getValue(Type.DATE)) : null;
Modified: jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java?rev=1642112&r1=1642111&r2=1642112&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java (original)
+++ jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java Thu Nov 27 11:35:58 2014
@@ -39,7 +39,6 @@ import org.apache.jackrabbit.oak.api.Con
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
-import org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneInitializerHelper;
import org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider;
import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider;
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
@@ -269,6 +268,34 @@ public class LucenePropertyIndexTest ext
}
@Test
+ public void determinePropTypeFromRestriction() throws Exception{
+ Tree idx = createIndex("test1", of("propa", "propb"));
+ //Do not provide type information
+ root.commit();
+
+ Tree test = root.getTree("/").addChild("test");
+ test.addChild("a").setProperty("propa", 10);
+ test.addChild("b").setProperty("propa", 20);
+ test.addChild("c").setProperty("propa", 30);
+ test.addChild("c").setProperty("propb", "foo");
+ test.addChild("d").setProperty("propb", "foo");
+ root.commit();
+
+ assertThat(explain("select [jcr:path] from [nt:base] where [propa] >= 20"), containsString("lucene:test1"));
+
+ assertQuery("select [jcr:path] from [nt:base] where [propa] >= 20", asList("/test/b", "/test/c"));
+ assertQuery("select [jcr:path] from [nt:base] where [propa] >= 20", asList("/test/b", "/test/c"));
+ assertQuery("select [jcr:path] from [nt:base] where [propa] = 20", asList("/test/b"));
+ assertQuery("select [jcr:path] from [nt:base] where [propa] <= 20", asList("/test/b", "/test/a"));
+ assertQuery("select [jcr:path] from [nt:base] where [propa] < 20", asList("/test/a"));
+ assertQuery("select [jcr:path] from [nt:base] where [propa] = 20 or [propa] = 10 ", asList("/test/b", "/test/a"));
+ assertQuery("select [jcr:path] from [nt:base] where [propa] > 10 and [propa] < 30", asList("/test/b"));
+ assertQuery("select [jcr:path] from [nt:base] where [propa] in (10,20)", asList("/test/b", "/test/a"));
+ assertQuery("select [jcr:path] from [nt:base] where propa is not null", asList("/test/a", "/test/b", "/test/c"));
+
+ }
+
+ @Test
public void rangeQueriesWithDouble() throws Exception {
Tree idx = createIndex("test1", of("propa", "propb"));
Tree propIdx = idx.addChild(PROP_NODE).addChild("propa");