Return-Path: X-Original-To: apmail-avro-user-archive@www.apache.org Delivered-To: apmail-avro-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 92B089F06 for ; Wed, 6 Jun 2012 23:17:03 +0000 (UTC) Received: (qmail 77188 invoked by uid 500); 6 Jun 2012 23:17:03 -0000 Delivered-To: apmail-avro-user-archive@avro.apache.org Received: (qmail 77141 invoked by uid 500); 6 Jun 2012 23:17:03 -0000 Mailing-List: contact user-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@avro.apache.org Delivered-To: mailing list user@avro.apache.org Received: (qmail 77126 invoked by uid 99); 6 Jun 2012 23:17:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jun 2012 23:17:03 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FSL_RCVD_USER,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of johntbates@gmail.com designates 209.85.220.171 as permitted sender) Received: from [209.85.220.171] (HELO mail-vc0-f171.google.com) (209.85.220.171) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jun 2012 23:16:55 +0000 Received: by vcbgb30 with SMTP id gb30so5670321vcb.30 for ; Wed, 06 Jun 2012 16:16:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=Xm7sO+ty1cFRsfG18gUKwRWobXZ3LKfJabrXnnstzMg=; b=raZUDZIX1kI1+5TvDy577cxCpynHty0TDYSAjU3h6IG18E5UfsioN5EFpoCYxI5V+V 5tF6WZ+nGjov53zgRmU3HrF7GEF0XFjNx4xH8XF1aqHCy6ah8J/MGdLYVlLTNDz6qVQl COhcwFY5mpc776ufp2b7qcBIKIMXFCGac140kzNY9tCo2MnUBr7XVHVP09yQgjX+w4js aQn3IFLl5+LenVDYI0tQZcGQ4ayCxFaKquKDRFEM2WBqcCGMnMTI5lnqG9SL0C2mhYZc ep3NZvBgZG+dw7jdsL5qv8FdMM8busR41SxorIvnXM2zA1qCg9gPKZgbDof62/W5WULS kaxg== MIME-Version: 1.0 Received: by 10.52.172.208 with SMTP id be16mr19636388vdc.62.1339024593593; Wed, 06 Jun 2012 16:16:33 -0700 (PDT) Received: by 10.220.34.76 with HTTP; Wed, 6 Jun 2012 16:16:33 -0700 (PDT) In-Reply-To: References: Date: Wed, 6 Jun 2012 16:16:33 -0700 Message-ID: Subject: Re: robustness of Schema.Field.pos() across schema versions From: John Bates To: user@avro.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks very much, Doug. It seems as though we might abandon that approach and only support Avro data, but I appreciate your thorough response! Thanks again, bates On Wed, Jun 6, 2012 at 3:46 PM, Doug Cutting wrote: > John, > > I think this will work fine. =A0The schema in SCHEMA$ is in sync with > the generated code. > > You should be able to avoid this copying by instead generating code > with a different base class that contains your methods. =A0In > particular, it should be easy to modify record.vm to instead use a > subclass of SpecificRecordBase. =A0Templates are found on the classpath. > > We might also add a feature where one can specify an alternate base > class through an API. =A0This might then be used by the Maven and Ant > tasks. =A0If that approach sounds useful, please file an issue in Jira. > > Doug > > On Wed, Jun 6, 2012 at 1:08 PM, John Bates wrote: >> Hi, all. >> >> I'm trying to subclass an Avro IDL-generated class so that it may >> implement an interface used by our project to deserialize data (and >> not necessarily Avro data) from an InputStream. =A0Ideally, I'd like to >> do something like this: >> >> public class MySubclass extends MyAvroGeneratedClass implements >> MySerializationInterface { >> =A0@Override >> =A0public void readObject(InputStream in) throws IOException, >> =A0 =A0 =A0ClassNotFoundException { >> >> =A0 =A0// AvroUtil.readObject exists and returns a SpecificRecord given >> an InputStream and Schema >> =A0 =A0MySubclass other =3D ((MyAvroGeneratedClass) AvroUtil.readObject(= in, >> MyAvroGeneratedClass.SCHEMA$)); >> >> =A0 =A0// Is this correct? =A0Is it robust? >> =A0 =A0List fields =3D other.getSchema().getFields(); >> =A0 =A0for(Schema.Field field : fields) { >> =A0 =A0 =A0field.name(); >> =A0 =A0 =A0int position =3D field.pos(); >> =A0 =A0 =A0this.put(position, other.get(position)); >> =A0 =A0} >> =A0} >> } >> >> I'm trying to avoid having to use the setters and getters supplied by >> the generated class, as that will require this subclass remains in >> sync with the IDL-generated class, which will probably be a point of >> failure. >> >> Is this approach robust to changes in the schema? =A0That is, if the >> schema changes at some point in the future, will it be possible to >> deserialize data that has been serialized with an older version of the >> schema? =A0Is there a better (read: more correct, more robust, more >> consistent with Avro's design) way to do this? >> >> I sincerely appreciate your help - I've been blocked for a few days on t= his. >> >> Thanks in advance, >> John Bates