Return-Path: Delivered-To: apmail-hadoop-avro-user-archive@minotaur.apache.org Received: (qmail 82907 invoked from network); 13 Apr 2010 01:14:20 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 13 Apr 2010 01:14:20 -0000 Received: (qmail 76025 invoked by uid 500); 13 Apr 2010 01:14:19 -0000 Delivered-To: apmail-hadoop-avro-user-archive@hadoop.apache.org Received: (qmail 75980 invoked by uid 500); 13 Apr 2010 01:14:19 -0000 Mailing-List: contact avro-user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: avro-user@hadoop.apache.org Delivered-To: mailing list avro-user@hadoop.apache.org Received: (qmail 75972 invoked by uid 99); 13 Apr 2010 01:14:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Apr 2010 01:14:19 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lurga.lee@gmail.com designates 209.85.217.225 as permitted sender) Received: from [209.85.217.225] (HELO mail-gx0-f225.google.com) (209.85.217.225) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Apr 2010 01:14:11 +0000 Received: by gxk25 with SMTP id 25so1517541gxk.11 for ; Mon, 12 Apr 2010 18:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :message-id:x-mailer:mime-version:content-type :content-transfer-encoding; bh=NBVCuehRytnykti8SQOUn8LygiG8gEGppZ/FukEVQ2A=; b=Z+Igcn/yAGcbZlCyYlsEFmaG+feBxdJ9eyvVdolklh9wc4/SDTr8ZNflI2G8X3VLIh 40UC81dW3dwCmO6lWc71pRee5WsqwEY2x2+vAbFLYpEGwuhazP0Op+A9h+pWS8KrLHD8 RZ0PBdxs4TyG9TlpwHFdqVPrRIh/I9pwEztvI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:x-mailer:mime-version:content-type :content-transfer-encoding; b=JBlK4lRc2WFOXoMolaHi7x7+psDEygjnR1llipuQLNNYr4Io7ZTdCYowFauw5fefbr vQcq6vT5r1PwCcwijX2JkPvL/eLGuVjr+liKHjccvJNm0Hi6/kQRilp6iHVLstr/gR/B USWJcNyhkRzBCfekH90Dmcfeb1mDLSa+ImNLg= Received: by 10.101.22.6 with SMTP id z6mr7489708ani.245.1271121226924; Mon, 12 Apr 2010 18:13:46 -0700 (PDT) Received: from LJZ ([222.247.55.186]) by mx.google.com with ESMTPS id a1sm2570097ibs.0.2010.04.12.18.13.44 (version=SSLv3 cipher=RC4-MD5); Mon, 12 Apr 2010 18:13:46 -0700 (PDT) Date: Tue, 13 Apr 2010 09:13:45 +0800 From: "Lurga" To: "avro-user" Subject: Question on writing/reading file with different schema Message-ID: <201004130913432506688@gmail.com> X-mailer: Foxmail 6, 15, 201, 22 [cn] Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Hello, I create a "Person" record (3 fields: first,last,age), and an "Extract" record (2 fields: first,last). Then I use "Person" to write some object to a file. When I use "Extract" to read data from the file, I got an exception: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -14. It seems like GenericDatumReader.readRecord won't skip the last fields. How can I read the data corretly? My code is below: public void browseName() throws IOException { List fields = new ArrayList(); fields.add(new Field("First", Schema.create(Type.STRING), null, null)); fields.add(new Field("Last", Schema.create(Type.STRING), null, null)); Schema extractSchema = Schema.createRecord(fields); DataFileReader reader = new DataFileReader(new File( fileName), new GenericDatumReader(extractSchema)); try { while (reader.hasNext()) { Record person = reader.next(); System.out.print(person.get("First").toString() + " " + person.get("Last").toString() + "\t"); } } finally { reader.close(); } } Regards, 2010-04-13 Lurga