You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/01/02 17:10:43 UTC
svn commit: r1649071 - in /lucene/dev/trunk/lucene/join/src:
java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
test/org/apache/lucene/search/join/TestBlockJoinValidation.java
Author: jpountz
Date: Fri Jan 2 16:10:43 2015
New Revision: 1649071
URL: http://svn.apache.org/r1649071
Log:
LUCENE-5873: BJQ: Throw an error if the top-level filter is not in the child space instead of just asserting.
Modified:
lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
lucene/dev/trunk/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java
Modified: lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java?rev=1649071&r1=1649070&r2=1649071&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java (original)
+++ lucene/dev/trunk/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java Fri Jan 2 16:10:43 2015
@@ -50,6 +50,7 @@ public class ToChildBlockJoinQuery exten
* ToChildBlockJoinScorer#validateParentDoc} on mis-use,
* when the parent query incorrectly returns child docs. */
static final String INVALID_QUERY_MESSAGE = "Parent query yields document which is not matched by parents filter, docID=";
+ static final String ILLEGAL_ADVANCE_ON_PARENT = "Expect to be advanced on child docs only. got docID=";
private final BitDocIdSetFilter parentsFilter;
private final Query parentQuery;
@@ -279,7 +280,6 @@ public class ToChildBlockJoinQuery exten
@Override
public int advance(int childTarget) throws IOException {
- assert childTarget >= parentBits.length() || !parentBits.get(childTarget);
//System.out.println("Q.advance childTarget=" + childTarget);
if (childTarget == NO_MORE_DOCS) {
@@ -287,6 +287,10 @@ public class ToChildBlockJoinQuery exten
return childDoc = parentDoc = NO_MORE_DOCS;
}
+ if (parentBits.get(childTarget)) {
+ throw new IllegalStateException(ILLEGAL_ADVANCE_ON_PARENT + childTarget);
+ }
+
assert childDoc == -1 || childTarget != parentDoc: "childTarget=" + childTarget;
if (childDoc == -1 || childTarget > parentDoc) {
// Advance to new parent:
Modified: lucene/dev/trunk/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java?rev=1649071&r1=1649070&r2=1649071&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java (original)
+++ lucene/dev/trunk/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java Fri Jan 2 16:10:43 2015
@@ -30,6 +30,7 @@ import org.apache.lucene.index.IndexWrit
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Filter;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryWrapperFilter;
@@ -113,6 +114,17 @@ public class TestBlockJoinValidation ext
}
@Test
+ public void testValidationForToChildBjqWithChildFilterQuery() throws Exception {
+ Query parentQueryWithRandomChild = createParentQuery();
+
+ ToChildBlockJoinQuery blockJoinQuery = new ToChildBlockJoinQuery(parentQueryWithRandomChild, parentsFilter, false);
+ Filter childFilter = new QueryWrapperFilter(new TermQuery(new Term("common_field", "1")));
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage(ToChildBlockJoinQuery.ILLEGAL_ADVANCE_ON_PARENT);
+ indexSearcher.search(blockJoinQuery, childFilter, 1);
+ }
+
+ @Test
public void testAdvanceValidationForToChildBjq() throws Exception {
int randomChildNumber = getRandomChildNumber(0);
// we need to make advance method meet wrong document, so random child number
@@ -163,6 +175,7 @@ public class TestBlockJoinValidation ext
Document result = new Document();
result.add(newStringField("id", createFieldValue(segmentNumber * AMOUNT_OF_PARENT_DOCS + parentNumber), Field.Store.YES));
result.add(newStringField("parent", createFieldValue(parentNumber), Field.Store.NO));
+ result.add(newStringField("common_field", "1", Field.Store.NO));
return result;
}
@@ -170,6 +183,7 @@ public class TestBlockJoinValidation ext
Document result = new Document();
result.add(newStringField("id", createFieldValue(segmentNumber * AMOUNT_OF_PARENT_DOCS + parentNumber, childNumber), Field.Store.YES));
result.add(newStringField("child", createFieldValue(childNumber), Field.Store.NO));
+ result.add(newStringField("common_field", "1", Field.Store.NO));
return result;
}
@@ -201,6 +215,10 @@ public class TestBlockJoinValidation ext
return childQueryWithRandomParent;
}
+ private static Query createParentQuery() {
+ return new TermQuery(new Term("id", createFieldValue(getRandomParentId())));
+ }
+
private static int getRandomParentId() {
return random().nextInt(AMOUNT_OF_PARENT_DOCS * AMOUNT_OF_SEGMENTS);
}