incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twilli...@apache.org
Subject git commit: Add some more terms coverage; fix NPE when terms is called with a startsWith value that doesn't exist
Date Sat, 20 Sep 2014 23:11:55 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/master dc0bb7ccb -> ce7fecc5d


Add some more terms coverage; fix NPE when terms is called with a startsWith value that doesn't
exist


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/ce7fecc5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/ce7fecc5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/ce7fecc5

Branch: refs/heads/master
Commit: ce7fecc5dcb45caed939acec8c0a6835db2b9bcb
Parents: dc0bb7c
Author: twilliams <twilliams@apache.org>
Authored: Sat Sep 20 19:11:14 2014 -0400
Committer: twilliams <twilliams@apache.org>
Committed: Sat Sep 20 19:11:14 2014 -0400

----------------------------------------------------------------------
 .../org/apache/blur/manager/IndexManager.java   | 12 +++--
 .../java/org/apache/blur/thrift/TermsTests.java | 54 +++++++++++++++++++-
 2 files changed, 61 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ce7fecc5/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java b/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java
index 0bc23d2..0fad374 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java
@@ -111,6 +111,7 @@ import org.apache.lucene.index.StoredFieldVisitor;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
+import org.apache.lucene.index.TermsEnum.SeekStatus;
 import org.apache.lucene.queries.BooleanFilter;
 import org.apache.lucene.queryparser.classic.ParseException;
 import org.apache.lucene.search.BooleanClause.Occur;
@@ -1013,15 +1014,18 @@ public class IndexManager {
     List<String> terms = new ArrayList<String>(size);
     AtomicReader areader = BlurUtil.getAtomicReader(reader);
     Terms termsAll = areader.terms(term.field());
-
+    
     if (termsAll == null) {
       return terms;
     }
 
     TermsEnum termEnum = termsAll.iterator(null);
-
-    termEnum.seekCeil(term.bytes());
-
+    SeekStatus status = termEnum.seekCeil(term.bytes());
+    
+    if (status == SeekStatus.END) {
+      return terms;
+    }
+    
     BytesRef currentTermText = termEnum.term();
     do {
       terms.add(currentTermText.utf8ToString());

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ce7fecc5/blur-core/src/test/java/org/apache/blur/thrift/TermsTests.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/thrift/TermsTests.java b/blur-core/src/test/java/org/apache/blur/thrift/TermsTests.java
index 2048b7c..ae906fe 100644
--- a/blur-core/src/test/java/org/apache/blur/thrift/TermsTests.java
+++ b/blur-core/src/test/java/org/apache/blur/thrift/TermsTests.java
@@ -16,6 +16,7 @@ package org.apache.blur.thrift;
  * limitations under the License.
  */
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import java.io.IOException;
 import java.util.List;
@@ -27,7 +28,7 @@ import org.junit.Test;
 import com.google.common.collect.Lists;
 
 public class TermsTests extends BaseClusterTest {
-
+  
   @Test
   public void testTermsList() throws BlurException, TException, IOException, InterruptedException
{
     final String tableName = "testTermsList";
@@ -39,6 +40,57 @@ public class TermsTests extends BaseClusterTest {
     
     assertEquals(list, terms);
   }
+  
+  @Test
+  public void shouldBeAbleToSkipToTerms() throws Exception {
+    final String tableName = "shouldBeAbleToNavigateTerms";
+    TableGen.define(tableName)
+      .cols("test", "col1")
+      .addRecord("1","1", "aaa")
+      .addRecord("2","2", "bbb")
+      .addRecord("3","3", "ccc")
+      .addRecord("4","4", "ddd")
+      .build(getClient());
+    
+    List<String> terms = getClient().terms(tableName, "test", "col1", "c", (short)10);
+    List<String> expected = Lists.newArrayList("ccc", "ddd");
+    
+    assertEquals(expected, terms);
+  }
+  
+  @Test
+  public void shouldOnlyReturnNumberOfTermsRequested() throws Exception {
+    final String tableName = "shouldOnlyReturnNumberOfTermsRequested";
+    TableGen.define(tableName)
+      .cols("test", "col1")
+      .addRecord("1","1", "aaa")
+      .addRecord("2","2", "bbb")
+      .addRecord("3","3", "ccc")
+      .addRecord("4","4", "ddd")
+      .build(getClient());
+    
+    List<String> terms = getClient().terms(tableName, "test", "col1", "c", (short)1);
+    List<String> expected = Lists.newArrayList("ccc");
+    
+    assertEquals(expected, terms);
+  }
+  
+  @Test
+  public void shouldGetEmptyListForNonExistentTerms() throws Exception {
+    final String tableName = "shouldGetEmptyListForNonExistantTerms";
+    TableGen.define(tableName)
+      .cols("test", "col1")
+      .addRecord("1","1", "aaa")
+      .addRecord("2","2", "bbb")
+      .addRecord("3","3", "ccc")
+      .addRecord("4","4", "ddd")
+      .build(getClient());
+    
+    List<String> terms = getClient().terms(tableName, "test", "col1", "z", (short)1);
+    assertNotNull(terms);
+    assertEquals(0, terms.size());
+  }
+  
   @Test(expected=BlurException.class)
   public void termsShouldFailOnUnknownTable() throws BlurException, TException {
     getClient().terms("termsShouldFailOnUnknownTable", "test","col1", null, (short)10);


Mime
View raw message