incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twilli...@apache.org
Subject git commit: Let child docs become records within row
Date Sat, 01 Mar 2014 14:04:32 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/apache-blur-0.2 c4d9663ca -> 36c4adea3


Let child docs become records within row


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

Branch: refs/heads/apache-blur-0.2
Commit: 36c4adea3b2b939f85899126e21b9408780b4fec
Parents: c4d9663
Author: twilliams <twilliams@apache.org>
Authored: Sat Mar 1 09:04:24 2014 -0500
Committer: twilliams <twilliams@apache.org>
Committed: Sat Mar 1 09:04:24 2014 -0500

----------------------------------------------------------------------
 .../org/apache/blur/slur/RowMutationHelper.java | 16 ++++----
 .../apache/blur/slur/RowMutationHelperTest.java | 20 +++++++++
 .../blur/slur/SolrLookingBlurServerTest.java    | 43 ++++++++++++++++++++
 3 files changed, 72 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/36c4adea/whiteboard/slur/src/main/java/org/apache/blur/slur/RowMutationHelper.java
----------------------------------------------------------------------
diff --git a/whiteboard/slur/src/main/java/org/apache/blur/slur/RowMutationHelper.java b/whiteboard/slur/src/main/java/org/apache/blur/slur/RowMutationHelper.java
index 80549e6..2d2cca4 100644
--- a/whiteboard/slur/src/main/java/org/apache/blur/slur/RowMutationHelper.java
+++ b/whiteboard/slur/src/main/java/org/apache/blur/slur/RowMutationHelper.java
@@ -34,7 +34,6 @@ public class RowMutationHelper {
   public static List<RowMutation> from(Collection<SolrInputDocument> docs, String
table) {
     List<RowMutation> mutations = Lists.newArrayList();
     for(SolrInputDocument d: docs) {
-      System.out.println("DOC: " + d.getFieldValue("id"));
       mutations.add(from(d, table));
     }
     return mutations;
@@ -44,22 +43,25 @@ public class RowMutationHelper {
     validate(doc);
 
     RowMutation mutate = new RowMutation();
-    mutate.setRowId(extractRowId(doc));
+    String rowid = extractId(doc);
+    mutate.setRowId(rowid);
     mutate.setTable(table);
     List<RecordMutation> recordMutations = Lists.newArrayList();
     if (doc.hasChildDocuments()) {
-
+      for(SolrInputDocument child: doc.getChildDocuments()) {
+        recordMutations.add(createRecordMutation(child, extractId(child)));
+      }
     } else {
-      recordMutations.add(createRecordMutation(doc, extractRowId(doc)));
+      recordMutations.add(createRecordMutation(doc, rowid));
     }
     mutate.setRecordMutations(recordMutations);
     return mutate;
   }
 
-  private static String extractRowId(SolrInputDocument doc) {
-    Object id = doc.getFieldValue("id");
+  private static String extractId(SolrInputDocument doc) {
+    Object id = doc.getFieldValue("rowid");
     if (id == null) {
-      id = doc.getFieldValue("rowid");
+      id = doc.getFieldValue("id");
     }
     if (id == null) {
       throw new IllegalArgumentException("Document must either have id or rowid field.");

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/36c4adea/whiteboard/slur/src/test/java/org/apache/blur/slur/RowMutationHelperTest.java
----------------------------------------------------------------------
diff --git a/whiteboard/slur/src/test/java/org/apache/blur/slur/RowMutationHelperTest.java
b/whiteboard/slur/src/test/java/org/apache/blur/slur/RowMutationHelperTest.java
index 88a8b30..5bf9158 100644
--- a/whiteboard/slur/src/test/java/org/apache/blur/slur/RowMutationHelperTest.java
+++ b/whiteboard/slur/src/test/java/org/apache/blur/slur/RowMutationHelperTest.java
@@ -72,6 +72,26 @@ public class RowMutationHelperTest {
     assertEquals("value2", vals.get(1).toString());
   }
 
+  @Test
+  public void documentWithChildDocumentsShouldBeRowWithRecords() {
+    SolrInputDocument doc = new SolrInputDocument();
+    doc.addField("id", "1");
+    
+    List<SolrInputDocument> children = Lists.newArrayList();
+    
+    for(int i = 0; i < 10; i++) {
+      SolrInputDocument child = new SolrInputDocument();
+      child.addField("id", i);
+      child.addField("fam.key", "value" + i);
+      children.add(child);
+    }
+    doc.addChildDocuments(children);
+
+    RowMutation mutate = RowMutationHelper.from(doc, "foo");
+
+    assertEquals("Children should turn into records.", 10, mutate.getRecordMutationsSize());
+  }
+  
   @Test(expected = IllegalArgumentException.class)
   public void docWithChildrenCantItselfHaveFieldValues() {
     SolrInputDocument parent = new SolrInputDocument();

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/36c4adea/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 bce57f1..05360c2 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
@@ -108,6 +108,37 @@ public class SolrLookingBlurServerTest {
   }
 
   @Test
+  public void childDocsShouldBecomeRecordsOfRow() throws SolrServerException, IOException,
BlurException, TException {
+    String table = "childDocsShouldBecomeRecordsOfRow";
+    createTable(table);
+    SolrServer server = new SolrLookingBlurServer(miniCluster.getControllerConnectionStr(),
table);
+    SolrInputDocument doc = new SolrInputDocument();
+    doc.addField("id", "1");
+    
+    List<SolrInputDocument> children = Lists.newArrayList();
+    for(int i = 0; i < 100; i++) {
+      SolrInputDocument child = new SolrInputDocument();
+      child.addField("id", i);
+      child.addField("fam.key", "value" + i);
+      children.add(child);
+    }
+    doc.addChildDocuments(children);
+    
+    server.add(doc);
+
+    TableStats stats = client().tableStats(table);
+
+    assertEquals("We should have one record.", 100, stats.recordCount);
+    assertEquals("We should have one row.", 1, stats.rowCount);
+
+    assertTotalResults(table, "fam.key:value1", 1l);
+    assertTotalRecordResults(table, "recordid:99", 1l);
+
+    removeTable(table);
+  }  
+  
+
+  @Test
   public void docShouldBeDiscoverableWithMultiValuedFields() throws SolrServerException,
IOException, BlurException,
       TException {
     String table = "docShouldBeDiscoverableWithMultiValuedFields";
@@ -217,6 +248,18 @@ public class SolrLookingBlurServerTest {
 
     assertEquals("Should find our row.", expected, results.getTotalResults());
   }
+  private void assertTotalRecordResults(String table, String q, long expected) throws BlurException,
TException {
+    BlurQuery bquery = new BlurQuery();
+    Query query = new Query();
+    query.setQuery(q);
+    query.setRowQuery(false);
+    bquery.setQuery(query);
+   
+    BlurResults results = client().query(table, bquery);
+
+    assertEquals("Should find our record.", expected, results.getTotalResults());
+    
+  }
 
   private void removeTable(String table) {
     try {


Mime
View raw message