Return-Path: Delivered-To: apmail-avro-commits-archive@www.apache.org Received: (qmail 96410 invoked from network); 21 Jul 2010 21:15:28 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 21 Jul 2010 21:15:28 -0000 Received: (qmail 74777 invoked by uid 500); 21 Jul 2010 21:15:28 -0000 Delivered-To: apmail-avro-commits-archive@avro.apache.org Received: (qmail 74756 invoked by uid 500); 21 Jul 2010 21:15:28 -0000 Mailing-List: contact commits-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@avro.apache.org Delivered-To: mailing list commits@avro.apache.org Received: (qmail 74747 invoked by uid 99); 21 Jul 2010 21:15:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Jul 2010 21:15:28 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Jul 2010 21:15:25 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BDC9023889E2; Wed, 21 Jul 2010 21:14:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r966422 [2/2] - in /avro/trunk: ./ lang/java/src/java/org/apache/avro/generic/ lang/java/src/java/org/apache/avro/mapred/ lang/java/src/java/org/apache/avro/mapred/tether/ lang/java/src/java/org/apache/avro/reflect/ lang/java/src/java/org/a... Date: Wed, 21 Jul 2010 21:14:31 -0000 To: commits@avro.apache.org From: cutting@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100721211431.BDC9023889E2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/mapred/tether/WordCountTask.java URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/mapred/tether/WordCountTask.java?rev=966422&r1=966421&r2=966422&view=diff ============================================================================== --- avro/trunk/lang/java/src/test/java/org/apache/avro/mapred/tether/WordCountTask.java (original) +++ avro/trunk/lang/java/src/test/java/org/apache/avro/mapred/tether/WordCountTask.java Wed Jul 21 21:14:29 2010 @@ -22,32 +22,30 @@ import java.io.IOException; import java.util.StringTokenizer; import org.apache.avro.util.Utf8; -import org.apache.avro.mapred.WordCount; +import org.apache.avro.mapred.Pair; /** Example Java tethered mapreduce executable. Implements map and reduce * functions for word count. */ -public class WordCountTask extends TetherTask { +public class WordCountTask + extends TetherTask,Pair> { - @Override public void map(Utf8 text, Collector collector) + @Override public void map(Utf8 text, Collector> collector) throws IOException { StringTokenizer tokens = new StringTokenizer(text.toString()); - while (tokens.hasMoreTokens()) { - WordCount wc = new WordCount(); - wc.word = new Utf8(tokens.nextToken()); - wc.count = 1; - collector.collect(wc); - } + while (tokens.hasMoreTokens()) + collector.collect(new Pair(new Utf8(tokens.nextToken()),1L)); } - private int sum; + private long sum; - @Override public void reduce(WordCount wc, Collector c) { - sum += wc.count; + @Override public void reduce(Pair wc, + Collector> c) { + sum += wc.value(); } - @Override public void reduceFlush(WordCount wc, Collector c) + @Override public void reduceFlush(Pair wc, Collector> c) throws IOException { - wc.count = sum; + wc.value(sum); c.collect(wc); sum = 0; } Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/specific/TestSpecificData.java URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/specific/TestSpecificData.java?rev=966422&r1=966421&r2=966422&view=diff ============================================================================== --- avro/trunk/lang/java/src/test/java/org/apache/avro/specific/TestSpecificData.java (original) +++ avro/trunk/lang/java/src/test/java/org/apache/avro/specific/TestSpecificData.java Wed Jul 21 21:14:29 2010 @@ -17,11 +17,21 @@ */ package org.apache.avro.specific; +import java.util.List; +import java.util.ArrayList; + import static org.junit.Assert.*; import org.junit.Test; +import org.apache.avro.Schema; +import org.apache.avro.generic.GenericData; +import org.apache.avro.util.Utf8; + +import org.apache.avro.TestSchema; import org.apache.avro.test.TestRecord; +import org.apache.avro.test.MD5; +import org.apache.avro.test.Kind; public class TestSpecificData { @@ -38,4 +48,32 @@ public class TestSpecificData { new TestRecord().toString(); } + @Test + /** Test nesting of specific data within generic. */ + public void testSpecificWithinGeneric() throws Exception { + // define a record with a field that's a generated TestRecord + Schema schema = Schema.createRecord("Foo", "", "x.y.z", false); + List fields = new ArrayList(); + fields.add(new Schema.Field("f", TestRecord.SCHEMA$, "", null)); + schema.setFields(fields); + + // create a generic instance of this record + TestRecord nested = new TestRecord(); + nested.name = new Utf8("foo"); + nested.kind = Kind.BAR; + nested.hash = new MD5(); + System.arraycopy(new byte[]{0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5}, 0, + nested.hash.bytes(), 0, 16); + GenericData.Record record = new GenericData.Record(schema); + record.put("f", nested); + + // test that this instance can be written & re-read + TestSchema.checkBinary(schema, record, + new SpecificDatumWriter(), + new SpecificDatumReader()); + + } + + + } Added: avro/trunk/share/test/data/weather-sorted.avro URL: http://svn.apache.org/viewvc/avro/trunk/share/test/data/weather-sorted.avro?rev=966422&view=auto ============================================================================== Binary file - no diff available. Propchange: avro/trunk/share/test/data/weather-sorted.avro ------------------------------------------------------------------------------ svn:executable = * Propchange: avro/trunk/share/test/data/weather-sorted.avro ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: avro/trunk/share/test/data/weather.avro URL: http://svn.apache.org/viewvc/avro/trunk/share/test/data/weather.avro?rev=966422&view=auto ============================================================================== Binary file - no diff available. Propchange: avro/trunk/share/test/data/weather.avro ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: avro/trunk/share/test/data/weather.json URL: http://svn.apache.org/viewvc/avro/trunk/share/test/data/weather.json?rev=966422&view=auto ============================================================================== --- avro/trunk/share/test/data/weather.json (added) +++ avro/trunk/share/test/data/weather.json Wed Jul 21 21:14:29 2010 @@ -0,0 +1,5 @@ +{"station":"011990-99999","time":-619524000000,"temp":0} +{"station":"011990-99999","time":-619506000000,"temp":22} +{"station":"011990-99999","time":-619484400000,"temp":-11} +{"station":"012650-99999","time":-655531200000,"temp":111} +{"station":"012650-99999","time":-655509600000,"temp":78} Added: avro/trunk/share/test/schemas/weather.avsc URL: http://svn.apache.org/viewvc/avro/trunk/share/test/schemas/weather.avsc?rev=966422&view=auto ============================================================================== --- avro/trunk/share/test/schemas/weather.avsc (added) +++ avro/trunk/share/test/schemas/weather.avsc Wed Jul 21 21:14:29 2010 @@ -0,0 +1,8 @@ +{"type": "record", "name": "test.Weather", + "doc": "A weather reading.", + "fields": [ + {"name": "station", "type": "string", "order": "ignore"}, + {"name": "time", "type": "long"}, + {"name": "temp", "type": "int"} + ] +}