incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twilli...@apache.org
Subject git commit: Support deletes by id
Date Sat, 01 Mar 2014 13:06:31 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/apache-blur-0.2 6c229c67a -> 992a122a6


Support deletes by id


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

Branch: refs/heads/apache-blur-0.2
Commit: 992a122a6169b4cd4dd290f4363c4e27b5f4c26c
Parents: 6c229c6
Author: twilliams <twilliams@apache.org>
Authored: Sat Mar 1 08:06:21 2014 -0500
Committer: twilliams <twilliams@apache.org>
Committed: Sat Mar 1 08:06:21 2014 -0500

----------------------------------------------------------------------
 whiteboard/slur/README.txt                      | 16 +++++-
 .../apache/blur/slur/SolrLookingBlurServer.java | 35 +++++++++++--
 .../blur/slur/SolrLookingBlurServerTest.java    | 54 +++++++++++++++++++-
 3 files changed, 98 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/992a122a/whiteboard/slur/README.txt
----------------------------------------------------------------------
diff --git a/whiteboard/slur/README.txt b/whiteboard/slur/README.txt
index 8b93c1d..f8f4cc7 100644
--- a/whiteboard/slur/README.txt
+++ b/whiteboard/slur/README.txt
@@ -1,13 +1,18 @@
+
 == Overview ==
 This project explores using SolrJ to work with a Blur installation.
 
 == Mismatches ==
-o) Commits - Blur commits on an update; Solr expects and explicit - rather 
+o) Commits - Blur commits on an update; Solr expects an explicit commit and rather 
 	 than buffering, I've chosen to go ahead and follow Blur's model.
 o) Row/SolrInputDocument - The parent document in Solr seems to be a "real" 
 	 document, with fields. So far, you can either have subdocuments or fields
 	 on the main document, but not both.
 o) Optimize - Solr offers waitFlush, waitSearcher and Blur just offers maxSegments.
+o) Deletes - The id's being passed to delete are understood to be RowIDs.  I gather that
+   Solr can delete child docs directly using this method but I don't yet see a safe way
+   to do that for us given only a single id. Maybe there's a way to do record deletions
+   by establishing a convention (e.g. "1->5", would be recordid:5 row:1)?  
 	 
 == Usage ==
 	
@@ -33,7 +38,14 @@ o) Optimize - Solr offers waitFlush, waitSearcher and Blur just offers
maxSegmen
 
     server.add(docs);
     
+  = Delete row/rows = 
+    server.delete("1");
+    
+    or
+    
+    List<String> ids = Lists.newArrayList("1", "2", "3", "4", "5");
+    server.deleteById(ids);
     
     == Notes ==
-    **caveate is that I don't have experience with SolrJ, so this may very
+    **caveat is that I don't have experience with SolrJ, so this may very
     well be dangerous.

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/992a122a/whiteboard/slur/src/main/java/org/apache/blur/slur/SolrLookingBlurServer.java
----------------------------------------------------------------------
diff --git a/whiteboard/slur/src/main/java/org/apache/blur/slur/SolrLookingBlurServer.java
b/whiteboard/slur/src/main/java/org/apache/blur/slur/SolrLookingBlurServer.java
index db2244d..b92fb6e 100644
--- a/whiteboard/slur/src/main/java/org/apache/blur/slur/SolrLookingBlurServer.java
+++ b/whiteboard/slur/src/main/java/org/apache/blur/slur/SolrLookingBlurServer.java
@@ -25,6 +25,8 @@ import org.apache.blur.thrift.BlurClient;
 import org.apache.blur.thrift.BlurClientManager;
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.RowMutation;
+import org.apache.blur.thrift.generated.RowMutationType;
 import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.SolrRequest.METHOD;
 import org.apache.solr.client.solrj.SolrServer;
@@ -139,17 +141,42 @@ public class SolrLookingBlurServer extends SolrServer {
 
   @Override
   public UpdateResponse deleteById(List<String> ids) throws SolrServerException, IOException
{
-    throw new RuntimeException("Not Implemented.");
+    UpdateResponse response = new UpdateResponse();
+    long start = System.currentTimeMillis();
+
+    try {
+      if (ids.size() == 1) {
+        client().mutate(toDeleteMutation(ids.get(0)));
+      } else {
+        List<RowMutation> mutates = Lists.newArrayList();
+        for (String id : ids) {
+          mutates.add(toDeleteMutation(id));
+        }
+        client().mutateBatch(mutates);
+      }
+    } catch (Exception e) {
+      throw new SolrServerException("Unable to delete docs by ids.", e);
+    }
+    response.setElapsedTime((System.currentTimeMillis() - start));
+    return response;
+  }
+
+  private RowMutation toDeleteMutation(String id) {
+    RowMutation mutate = new RowMutation();
+    mutate.setRowId(id);
+    mutate.setRowMutationType(RowMutationType.DELETE_ROW);
+    mutate.setTable(tableName);
+    return mutate;
   }
 
   @Override
   public UpdateResponse deleteById(String id, int commitWithinMs) throws SolrServerException,
IOException {
-    throw new RuntimeException("Not Implemented.");
+    return deleteById(id);
   }
 
   @Override
   public UpdateResponse deleteById(String id) throws SolrServerException, IOException {
-    throw new RuntimeException("Not Implemented.");
+    return deleteById(Lists.newArrayList(id));
   }
 
   @Override
@@ -200,7 +227,7 @@ public class SolrLookingBlurServer extends SolrServer {
     } catch (TException e) {
       throw new SolrServerException(e);
     }
-    response.setElapsedTime((System.currentTimeMillis()-start));
+    response.setElapsedTime((System.currentTimeMillis() - start));
     return response;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/992a122a/whiteboard/slur/src/test/java/org/apache/blur/slur/SolrLookingBlurServerTest.java
----------------------------------------------------------------------
diff --git a/whiteboard/slur/src/test/java/org/apache/blur/slur/SolrLookingBlurServerTest.java
b/whiteboard/slur/src/test/java/org/apache/blur/slur/SolrLookingBlurServerTest.java
index 401cdd7..bce57f1 100644
--- a/whiteboard/slur/src/test/java/org/apache/blur/slur/SolrLookingBlurServerTest.java
+++ b/whiteboard/slur/src/test/java/org/apache/blur/slur/SolrLookingBlurServerTest.java
@@ -152,7 +152,59 @@ public class SolrLookingBlurServerTest {
     assertTotalResults(table, "rowid:2", 1l);
     assertTotalResults(table, "fam.value:1299", 1l);
     assertTotalResults(table, "fam.value:justincase", 0l);
-    
+
+    removeTable(table);
+  }
+
+  @Test
+  public void weShouldBeAbleToDeleteARowById() throws SolrServerException, IOException, BlurException,
+      TException {
+    String table = "weShouldBeAbleToDeleteARowById";
+    createTable(table);
+    SolrServer server = new SolrLookingBlurServer(miniCluster.getControllerConnectionStr(),
table);
+    SolrInputDocument doc1 = new SolrInputDocument();
+    doc1.addField("id", "1");
+    doc1.addField("fam.value", "123");
+    SolrInputDocument doc2 = new SolrInputDocument();
+    doc2.addField("id", "2");
+    doc2.addField("fam.value", "124");
+    List<SolrInputDocument> docs = Lists.newArrayList(doc1, doc2);
+
+    server.add(docs);
+
+    assertTotalResults(table, "rowid:1", 1l);
+    assertTotalResults(table, "rowid:2", 1l);
+
+    server.deleteById("1");
+
+    assertTotalResults(table, "rowid:1", 0l);
+    assertTotalResults(table, "rowid:2", 1l);
+
+    removeTable(table);
+  }
+
+  @Test
+  public void weShouldBeAbleToDeleteARowByAListOfIds() throws SolrServerException, IOException,
BlurException,
+      TException {
+    String table = "weShouldBeAbleToDeleteARowByAListOfIds";
+    createTable(table);
+    SolrServer server = new SolrLookingBlurServer(miniCluster.getControllerConnectionStr(),
table);
+    for (int i = 0; i < 20; i++) {
+      SolrInputDocument doc = new SolrInputDocument();
+      doc.addField("id", i);
+      doc.addField("fam.value", "value" + i);
+      server.add(doc);
+    }
+
+    assertTotalResults(table, "rowid:1", 1l);
+    assertTotalResults(table, "rowid:2", 1l);
+    List<String> ids = Lists.newArrayList("1", "2", "3", "4", "5");
+    server.deleteById(ids);
+
+    for (String id : ids) {
+      assertTotalResults(table, "rowid:" + id, 0l);
+    }
+
     removeTable(table);
   }
 


Mime
View raw message