You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2013/02/07 18:06:51 UTC

svn commit: r1443604 - in /avro/trunk: CHANGES.txt lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroTrevniOutputFormat.java lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/TestMetadataFiltering.java

Author: cutting
Date: Thu Feb  7 17:06:50 2013
New Revision: 1443604

URL: http://svn.apache.org/viewvc?rev=1443604&view=rev
Log:
AVRO-1242. Java: Fix AvroTrevniOutputFormat to correctly get file metadata from JobConf.  Contributed by Ted Malaska.

Added:
    avro/trunk/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/TestMetadataFiltering.java   (with props)
Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroTrevniOutputFormat.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1443604&r1=1443603&r2=1443604&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu Feb  7 17:06:50 2013
@@ -46,6 +46,9 @@ Trunk (not yet released)
     AVRO-1240. Java: Fix SpecificDatumReader(Class) constructor to use
     correct ClassLoader. (cutting)
 
+    AVRO-1242. Java: Fix AvroTrevniOutputFormat to correctly get file
+    metadata from JobConf. (Ted Malaska via cutting)
+
 Avro 1.7.3 (6 December 2012)
 
   NEW FEATURES

Modified: avro/trunk/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroTrevniOutputFormat.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroTrevniOutputFormat.java?rev=1443604&r1=1443603&r2=1443604&view=diff
==============================================================================
--- avro/trunk/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroTrevniOutputFormat.java (original)
+++ avro/trunk/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroTrevniOutputFormat.java Thu Feb  7 17:06:50 2013
@@ -71,11 +71,7 @@ public class AvroTrevniOutputFormat <T>
       ? AvroJob.getMapOutputSchema(job)
       : AvroJob.getOutputSchema(job);
 
-    final ColumnFileMetaData meta = new ColumnFileMetaData();
-    for (Map.Entry<String,String> e : job)
-      if (e.getKey().startsWith(META_PREFIX))
-        meta.put(e.getKey().substring(AvroJob.TEXT_PREFIX.length()),
-                 e.getValue().getBytes(MetaData.UTF8));
+    final ColumnFileMetaData meta = filterMetadata(job);
 
     final Path dir = FileOutputFormat.getTaskOutputPath(job, name);
     final FileSystem fs = dir.getFileSystem(job);
@@ -111,4 +107,13 @@ public class AvroTrevniOutputFormat <T>
     };
   }
 
+   static ColumnFileMetaData filterMetadata(final JobConf job) {
+    final ColumnFileMetaData meta = new ColumnFileMetaData();
+    for (Map.Entry<String,String> e : job)
+      if (e.getKey().startsWith(META_PREFIX))
+        meta.put(e.getKey().substring(META_PREFIX.length()),
+                 e.getValue().getBytes(MetaData.UTF8));
+    return meta;
+  }
+
 }

Added: avro/trunk/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/TestMetadataFiltering.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/TestMetadataFiltering.java?rev=1443604&view=auto
==============================================================================
--- avro/trunk/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/TestMetadataFiltering.java (added)
+++ avro/trunk/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/TestMetadataFiltering.java Thu Feb  7 17:06:50 2013
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.trevni.avro;
+
+import org.apache.avro.mapred.AvroJob;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.trevni.ColumnFileMetaData;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TestMetadataFiltering {
+
+  @Test public void testMetadataFiltering() throws Exception {
+    JobConf job = new JobConf();
+    
+    job.set(AvroTrevniOutputFormat.META_PREFIX + "test1", "1");
+    job.set(AvroTrevniOutputFormat.META_PREFIX + "test2", "2");
+    job.set("test3", "3");
+    job.set(AvroJob.TEXT_PREFIX + "test4", "4");
+    job.set(AvroTrevniOutputFormat.META_PREFIX + "test5", "5");
+    
+    ColumnFileMetaData metadata = AvroTrevniOutputFormat.filterMetadata(job);
+    
+    assertTrue(metadata.get("test1") != null);
+    assertTrue(new String(metadata.get("test1")).equals("1"));
+    assertTrue(metadata.get("test2") != null);
+    assertTrue(new String(metadata.get("test2")).equals("2"));
+    assertTrue(metadata.get("test5") != null);
+    assertTrue(new String(metadata.get("test5")).equals("5"));
+    assertTrue(metadata.get("test3") == null);
+    assertTrue(metadata.get("test4") == null);
+    
+  }
+  
+}

Propchange: avro/trunk/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/TestMetadataFiltering.java
------------------------------------------------------------------------------
    svn:eol-style = native