accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bil...@apache.org
Subject svn commit: r1208488 - in /incubator/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, 30 Nov 2011 16:19:30 GMT
Author: billie
Date: Wed Nov 30 16:19:28 2011
New Revision: 1208488

URL: http://svn.apache.org/viewvc?rev=1208488&view=rev
Log:
ACCUMULO-153 slightly modified patch

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

Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java?rev=1208488&r1=1208487&r2=1208488&view=diff
==============================================================================
--- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java
(original)
+++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java
Wed Nov 30 16:19:28 2011
@@ -380,7 +380,7 @@ public abstract class InputFormatBase<K,
    * @deprecated since 1.4, see {@link #addIterator(JobContext, IteratorSetting)}
    */
   public static void setIteratorOption(JobContext job, String iteratorName, String key, String
value) {
-    if (value == null)
+    if (iteratorName == null || key == null || value == null)
       return;
     
     String iteratorOptions = job.getConfiguration().get(ITERATORS_OPTIONS);
@@ -943,8 +943,8 @@ public abstract class InputFormatBase<K,
     public AccumuloIteratorOption(String iteratorOption) {
       StringTokenizer tokenizer = new StringTokenizer(iteratorOption, FIELD_SEP);
       this.iteratorName = tokenizer.nextToken();
-      this.key = tokenizer.nextToken();
       try {
+        this.key = URLDecoder.decode(tokenizer.nextToken(), "UTF-8");
         this.value = URLDecoder.decode(tokenizer.nextToken(), "UTF-8");
       } catch (UnsupportedEncodingException e) {
         throw new RuntimeException(e);
@@ -966,7 +966,7 @@ public abstract class InputFormatBase<K,
     @Override
     public String toString() {
       try {
-        return new String(iteratorName + FIELD_SEP + key + FIELD_SEP + URLEncoder.encode(value,
"UTF-8"));
+        return new String(iteratorName + FIELD_SEP + URLEncoder.encode(key, "UTF-8") + FIELD_SEP
+ URLEncoder.encode(value, "UTF-8"));
       } catch (UnsupportedEncodingException e) {
         throw new RuntimeException(e);
       }

Modified: incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java?rev=1208488&r1=1208487&r2=1208488&view=diff
==============================================================================
--- incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java
(original)
+++ incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloInputFormatTest.java
Wed Nov 30 16:19:28 2011
@@ -145,6 +145,42 @@ public class AccumuloInputFormatTest {
   }
   
   /**
+   * Test adding iterator options where the keys and values contain both the FIELD_SEPARATOR
character (':') and ITERATOR_SEPARATOR (',') characters. There
+   * should be no exceptions thrown when trying to parse these types of option entries.
+   * 
+   * This test makes sure that the expected raw values, as appears in the Job, are equal
to what's expected.
+   */
+  @Test
+  public void testIteratorOptionEncoding() throws Throwable {
+    String key = "colon:delimited:key";
+    String value = "comma,delimited,value";
+    IteratorSetting someSetting = new IteratorSetting(1, "iterator", "Iterator.class");
+    someSetting.addOption(key, value);
+    Job job = new Job();
+    AccumuloInputFormat.addIterator(job, someSetting);
+    
+    final String rawConfigOpt = new AccumuloIteratorOption("iterator", key, value).toString();
+    
+    assertEquals(rawConfigOpt, job.getConfiguration().get("AccumuloInputFormat.iterators.options"));
+    
+    List<AccumuloIteratorOption> opts = AccumuloInputFormat.getIteratorOptions(job);
+    assertEquals(1, opts.size());
+    assertEquals(opts.get(0).getKey(), key);
+    assertEquals(opts.get(0).getValue(), value);
+    
+    someSetting.addOption(key + "2", value);
+    someSetting.setPriority(2);
+    someSetting.setName("it2");
+    AccumuloInputFormat.addIterator(job, someSetting);
+    opts = AccumuloInputFormat.getIteratorOptions(job);
+    assertEquals(3, opts.size());
+    for (AccumuloIteratorOption opt : opts) {
+      assertEquals(opt.getKey().substring(0, key.length()), key);
+      assertEquals(opt.getValue(), value);
+    }
+  }
+  
+  /**
    * Test getting iterator settings for multiple iterators set
    */
   @SuppressWarnings("deprecation")



Mime
View raw message