accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ujustgotbi...@apache.org
Subject svn commit: r1499198 - in /accumulo/branches/1.4/src/core/src: main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java
Date Wed, 03 Jul 2013 04:04:20 GMT
Author: ujustgotbilld
Date: Wed Jul  3 04:04:20 2013
New Revision: 1499198

URL: http://svn.apache.org/r1499198
Log:
ACCUMULO-1267 Added check to see if a user actually sets a regex before applying the RegExFilter
to the record reader's scanner.

Modified:
    accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java
    accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java

Modified: accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java?rev=1499198&r1=1499197&r2=1499198&view=diff
==============================================================================
--- accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java
(original)
+++ accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java
Wed Jul  3 04:04:20 2013
@@ -1131,9 +1131,13 @@ public abstract class InputFormatBase<K,
           scanner = new ClientSideIteratorScanner(scanner);
         }
         setupMaxVersions(conf, scanner);
-        IteratorSetting is = new IteratorSetting(50, RegExFilter.class);
-        RegExFilter.setRegexs(is, conf.get(ROW_REGEX), conf.get(COLUMN_FAMILY_REGEX), conf.get(COLUMN_QUALIFIER_REGEX),
null, false);
-        scanner.addScanIterator(is);
+        if (conf.get(ROW_REGEX) != null || conf.get(COLUMN_FAMILY_REGEX) != null || conf.get(COLUMN_QUALIFIER_REGEX)
!= null ||
+            conf.get(VALUE_REGEX) != null) {
+          IteratorSetting is = new IteratorSetting(50, RegExFilter.class);
+          RegExFilter.setRegexs(is, conf.get(ROW_REGEX), conf.get(COLUMN_FAMILY_REGEX), conf.get(COLUMN_QUALIFIER_REGEX),
+            conf.get(VALUE_REGEX), false);
+          scanner.addScanIterator(is);
+        }
         setupIterators(conf, scanner);
       } catch (Exception e) {
         throw new IOException(e);

Modified: accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java?rev=1499198&r1=1499197&r2=1499198&view=diff
==============================================================================
--- accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java
(original)
+++ accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java
Wed Jul  3 04:04:20 2013
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertTru
 
 import java.io.IOException;
 import java.util.List;
+import java.util.regex.Pattern;
 
 import org.apache.accumulo.core.client.BatchWriter;
 import org.apache.accumulo.core.client.Connector;
@@ -46,6 +47,7 @@ import org.apache.hadoop.mapreduce.Recor
 import org.apache.hadoop.mapreduce.TaskAttemptContext;
 import org.apache.hadoop.mapreduce.TaskAttemptID;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class AccumuloInputFormatTest {
@@ -353,4 +355,35 @@ public class AccumuloInputFormatTest {
       mapper.map(rr.getCurrentKey(), rr.getCurrentValue(), context);
     }
   }
+  
+  @SuppressWarnings("deprecation")
+  @Test
+  public void testRegex() throws Exception {
+    MockInstance mockInstance = new MockInstance("testmapinstance");
+    Connector c = mockInstance.getConnector("root", new byte[] {});
+    c.tableOperations().create("testtable3");
+    BatchWriter bw = c.createBatchWriter("testtable3", 10000L, 1000L, 4);
+    for (int i = 0; i < 100; i++) {
+      Mutation m = new Mutation(new Text(String.format("%09x", i + 1)));
+      m.put(new Text(), new Text(), new Value(String.format("%09x", i).getBytes()));
+      bw.addMutation(m);
+    }
+    bw.close();
+    
+    JobContext job = new JobContext(new Configuration(), new JobID());
+    AccumuloInputFormat.setInputInfo(job.getConfiguration(), "root", "".getBytes(), "testtable3",
new Authorizations());
+    AccumuloInputFormat.setMockInstance(job.getConfiguration(), "testmapinstance");
+    final String regex = ".*1.*";
+    AccumuloInputFormat.setRegex(job, RegexType.ROW, regex);
+    AccumuloInputFormat input = new AccumuloInputFormat();
+    RangeInputSplit ris = new RangeInputSplit();
+    TaskAttemptContext tac = new TaskAttemptContext(job.getConfiguration(), new TaskAttemptID());
+    RecordReader<Key,Value> rr = input.createRecordReader(ris, tac);
+    rr.initialize(ris, tac);
+    
+    Pattern p = Pattern.compile(regex);
+    while (rr.nextKeyValue()) {
+      Assert.assertTrue( p.matcher( rr.getCurrentKey().getRow().toString()).matches());
+    }
+  }
 }



Mime
View raw message