You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2014/06/24 18:09:38 UTC

[09/10] git commit: Merge branch '1.5.2-SNAPSHOT' into 1.6.1-SNAPSHOT

Merge branch '1.5.2-SNAPSHOT' into 1.6.1-SNAPSHOT

Conflicts:
	core/src/test/java/org/apache/accumulo/core/iterators/user/RowFilterTest.java


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/76c910bb
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/76c910bb
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/76c910bb

Branch: refs/heads/master
Commit: 76c910bbecf373a5b75c621a0051d9acf4f62ee0
Parents: fd080f0 c3de15b
Author: Josh Elser <el...@apache.org>
Authored: Tue Jun 24 11:56:59 2014 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Tue Jun 24 11:56:59 2014 -0400

----------------------------------------------------------------------
 .../accumulo/core/iterators/user/RowFilter.java |  15 +-
 .../core/iterators/user/RowFilterTest.java      | 215 +++++++++++++++----
 2 files changed, 193 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/76c910bb/core/src/test/java/org/apache/accumulo/core/iterators/user/RowFilterTest.java
----------------------------------------------------------------------
diff --cc core/src/test/java/org/apache/accumulo/core/iterators/user/RowFilterTest.java
index 7435514,9af6340..958ac18
--- a/core/src/test/java/org/apache/accumulo/core/iterators/user/RowFilterTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/user/RowFilterTest.java
@@@ -16,13 -16,20 +16,19 @@@
   */
  package org.apache.accumulo.core.iterators.user;
  
+ import static org.junit.Assert.assertEquals;
+ import static org.junit.Assert.assertTrue;
+ 
  import java.io.IOException;
  import java.util.Arrays;
+ import java.util.Collections;
  import java.util.HashSet;
+ import java.util.LinkedList;
+ import java.util.List;
  import java.util.Map.Entry;
- 
- import junit.framework.TestCase;
+ import java.util.Set;
+ import java.util.TreeMap;
  
 -import org.apache.accumulo.core.Constants;
  import org.apache.accumulo.core.client.BatchWriter;
  import org.apache.accumulo.core.client.BatchWriterConfig;
  import org.apache.accumulo.core.client.Connector;
@@@ -35,9 -43,11 +42,12 @@@ import org.apache.accumulo.core.data.Ke
  import org.apache.accumulo.core.data.Mutation;
  import org.apache.accumulo.core.data.Range;
  import org.apache.accumulo.core.data.Value;
+ import org.apache.accumulo.core.iterators.DefaultIteratorEnvironment;
  import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+ import org.apache.accumulo.core.iterators.SortedMapIterator;
 +import org.apache.accumulo.core.security.Authorizations;
  import org.apache.hadoop.io.Text;
+ import org.junit.Test;
  
  /**
   * 
@@@ -129,17 -159,52 +159,52 @@@ public class RowFilterTest 
      m.put("cf1", "cq9", "1");
      m.put("cf2", "cq1", "1");
      m.put("cf2", "cq2", "1");
-     bw.addMutation(m);
-     
+ 
+     mutations.add(m);
+     return mutations;
+   }
+ 
+   public TreeMap<Key,Value> createKeyValues() {
+     List<Mutation> mutations = createMutations();
+     TreeMap<Key,Value> keyValues = new TreeMap<Key,Value>();
+ 
+     final Text cf = new Text(), cq = new Text();
+     for (Mutation m : mutations) {
+       final Text row = new Text(m.getRow());
+       for (ColumnUpdate update : m.getUpdates()) {
+         cf.set(update.getColumnFamily());
+         cq.set(update.getColumnQualifier());
+ 
+         Key k = new Key(row, cf, cq);
+         Value v = new Value(update.getValue());
+ 
+         keyValues.put(k, v);
+       }
+     }
+ 
+     return keyValues;
+   }
+ 
+   @Test
+   public void test1() throws Exception {
+     MockInstance instance = new MockInstance("rft1");
+     Connector conn = instance.getConnector("", new PasswordToken(""));
+ 
+     conn.tableOperations().create("table1");
+     BatchWriter bw = conn.createBatchWriter("table1", new BatchWriterConfig());
+ 
+     for (Mutation m : createMutations()) {
+       bw.addMutation(m);
+     }
      IteratorSetting is = new IteratorSetting(40, SummingRowFilter.class);
      conn.tableOperations().attachIterator("table1", is);
 -
 -    Scanner scanner = conn.createScanner("table1", Constants.NO_AUTHS);
 +    
 +    Scanner scanner = conn.createScanner("table1", Authorizations.EMPTY);
      assertEquals(new HashSet<String>(Arrays.asList("2", "3")), getRows(scanner));
-     
+ 
      scanner.fetchColumn(new Text("cf1"), new Text("cq2"));
      assertEquals(new HashSet<String>(Arrays.asList("1", "3")), getRows(scanner));
-     
+ 
      scanner.clearColumns();
      scanner.fetchColumn(new Text("cf1"), new Text("cq1"));
      assertEquals(new HashSet<String>(), getRows(scanner));
@@@ -161,9 -226,87 +226,87 @@@
      scanner.fetchColumn(new Text("cf1"), new Text("cq2"));
      scanner.fetchColumn(new Text("cf1"), new Text("cq4"));
      assertEquals(new HashSet<String>(Arrays.asList("4")), getRows(scanner));
 -
 +    
    }
-   
+ 
+   @Test
+   public void testChainedRowFilters() throws Exception {
+     MockInstance instance = new MockInstance("rft1");
+     Connector conn = instance.getConnector("", new PasswordToken(""));
+ 
+     conn.tableOperations().create("chained_row_filters");
+     BatchWriter bw = conn.createBatchWriter("chained_row_filters", new BatchWriterConfig());
+     for (Mutation m : createMutations()) {
+       bw.addMutation(m);
+     }
+     conn.tableOperations().attachIterator("chained_row_filters", new IteratorSetting(40, "trueFilter1", TrueFilter.class));
+     conn.tableOperations().attachIterator("chained_row_filters", new IteratorSetting(41, "trueFilter2", TrueFilter.class));
 -    Scanner scanner = conn.createScanner("chained_row_filters", Constants.NO_AUTHS);
++    Scanner scanner = conn.createScanner("chained_row_filters", Authorizations.EMPTY);
+     assertEquals(new HashSet<String>(Arrays.asList("0", "1", "2", "3", "4")), getRows(scanner));
+   }
+ 
+   @Test
+   public void testFilterConjunction() throws Exception {
+     MockInstance instance = new MockInstance("rft1");
+     Connector conn = instance.getConnector("", new PasswordToken(""));
+ 
+     conn.tableOperations().create("filter_conjunction");
+     BatchWriter bw = conn.createBatchWriter("filter_conjunction", new BatchWriterConfig());
+     for (Mutation m : createMutations()) {
+       bw.addMutation(m);
+     }
+     conn.tableOperations().attachIterator("filter_conjunction", new IteratorSetting(40, "rowZeroOrOne", RowZeroOrOneFilter.class));
+     conn.tableOperations().attachIterator("filter_conjunction", new IteratorSetting(41, "rowOneOrTwo", RowOneOrTwoFilter.class));
 -    Scanner scanner = conn.createScanner("filter_conjunction", Constants.NO_AUTHS);
++    Scanner scanner = conn.createScanner("filter_conjunction", Authorizations.EMPTY);
+     assertEquals(new HashSet<String>(Arrays.asList("1")), getRows(scanner));
+   }
+ 
+   @Test
+   public void deepCopyCopiesTheSource() throws Exception {
+     SortedMapIterator source = new SortedMapIterator(createKeyValues());
+ 
+     RowFilter filter = new RowZeroOrOneFilter();
+     filter.init(source, Collections.<String,String> emptyMap(), new DefaultIteratorEnvironment());
+ 
+     filter.seek(new Range(), Collections.<ByteSequence> emptySet(), false);
+ 
+     // Save off the first key and value
+     Key firstKey = filter.getTopKey();
+     Value firstValue = filter.getTopValue();
+ 
+     // Assert that the row is valid given our filter
+     assertEquals("0", firstKey.getRow().toString());
+ 
+     // Read some extra data, just making sure it's all valid
+     Key lastKeyRead = null;
+     for (int i = 0; i < 5; i++) {
+       filter.next();
+       lastKeyRead = filter.getTopKey();
+       assertEquals("0", lastKeyRead.getRow().toString());
+     }
+ 
+     // Make a copy of the original RowFilter
+     RowFilter copy = (RowFilter) filter.deepCopy(new DefaultIteratorEnvironment());
+ 
+     // Because it's a copy, we should be able to safely seek this one without affecting the original
+     copy.seek(new Range(), Collections.<ByteSequence> emptySet(), false);
+ 
+     assertTrue("deepCopy'ed RowFilter did not have a top key", copy.hasTop());
+ 
+     Key firstKeyFromCopy = copy.getTopKey();
+     Value firstValueFromCopy = copy.getTopValue();
+ 
+     // Verify that we got the same first k-v pair we did earlier
+     assertEquals(firstKey, firstKeyFromCopy);
+     assertEquals(firstValue, firstValueFromCopy);
+ 
+     filter.next();
+     Key finalKeyRead = filter.getTopKey();
+ 
+     // Make sure we got a Key that was greater than the last Key we read from the original RowFilter
+     assertTrue("Expected next key read to be greater than the previous after deepCopy", lastKeyRead.compareTo(finalKeyRead) < 0);
+   }
+ 
    private HashSet<String> getRows(Scanner scanner) {
      HashSet<String> rows = new HashSet<String>();
      for (Entry<Key,Value> entry : scanner) {