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 1157D9D84 for ; Wed, 7 Mar 2012 16:27:03 +0000 (UTC) Received: (qmail 4797 invoked by uid 500); 7 Mar 2012 16:27:02 -0000 Delivered-To: apmail-avro-user-archive@avro.apache.org Received: (qmail 4383 invoked by uid 500); 7 Mar 2012 16:27:00 -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 4362 invoked by uid 99); 7 Mar 2012 16:27:00 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Mar 2012 16:27:00 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of kramachandran@iqt.org designates 38.127.128.196 as permitted sender) Received: from [38.127.128.196] (HELO E-VA-SRV-FW1A.iqt.org) (38.127.128.196) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Mar 2012 16:26:52 +0000 Received: from va-srv-ex2.a.internal (va-srv-ex2.a.internal [10.100.2.50]) by E-VA-SRV-FW1A.iqt.org (8.14.5/8.14.5) with ESMTP id q27GQUMl000772 for ; Wed, 7 Mar 2012 11:26:30 -0500 (EST) Received: from VA-SRV-EX1.a.internal ([fe80::d439:a27d:47ef:22ee]) by VA-SRV-EX2.a.internal ([fe80::457:b8b1:3a0a:e05c%16]) with mapi id 14.01.0355.002; Wed, 7 Mar 2012 11:26:25 -0500 From: "Ramachandran, Karthik" To: "user@avro.apache.org" Subject: Embedded Record types using GenericRecord Thread-Topic: Embedded Record types using GenericRecord Thread-Index: AQHM/H8J8bm+8au0uES3Vrv4fcwhgw== Date: Wed, 7 Mar 2012 16:26:23 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.100.3.41] Content-Type: multipart/alternative; boundary="_000_CB7CF6913A4Ekramachandraniqtorg_" MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org --_000_CB7CF6913A4Ekramachandraniqtorg_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi, I have a schema that looks like this: { "name" : "identified_wrapper", "type" : "record", "fields" : [ {"name" : "uuid", "type" : "string"}, {"name" : "filename", "type":"string"}, {"name" : "content_hash", "type":"string"}, {"name" : "body", "type":["bytes", "null"]}, {"name" : "mime_type", "type": ["string", "null"]}, {"name" : "type_specific", "type" : [{ "name" : "message_meta_data= ", "type" : "record", "fields" : [ {"name" : "subject", "ty= pe" : ["string", "null"]}] }, { "name" : "dublin_core_meta_= data", "type" : "record", "fields" : [ {"name" : "subject_one",= "type" : ["string", "null"]}] }, { "name" : "image_meta_data", "type" : "record", "fields" : [{"name" : "subj= ect_two", "type" : ["string", "null"]}] }, "null" ]} ] } I'm trying to populate this object but I can't figure out how to create rec= ords for the type_specific union type using GenericRecord. My code current= ly looks like : public static GenericRecord populateRecord(Schema schema) throws Except= ion { GenericRecord record =3D new GenericData.Record(schema); String uuid =3D generateUuid(); record.put(UUID, uuid); record.put(FILENAME, "TEST"); record.put(CONTENT_HASH, "797987"); record.put(BODY, null); record.put(MIME_TYPE, "123321"); GenericRecord record_dc =3D new GenericData.Record(schema); record_dc.put("subject", null); record.put("type_specific", record_dc); return record; } This returns with the error : Exception in thread "main" org.apache.avro.AvroRuntimeException: Not a vali= d schema field: subject at org.apache.avro.generic.GenericData$Record.put(GenericData.java:90) at org.iqt.cdl.SpecificMetadataAvroExample.populateRecord(SpecificMetadataA= vroExample.java:79) at org.iqt.cdl.SpecificMetadataAvroExample.main(SpecificMetadataAvroExample= .java:133) Is there a way to do this? Karthik --_000_CB7CF6913A4Ekramachandraniqtorg_ Content-Type: text/html; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable
Hi, 

I have a schema that looks like this: 

{
    "name" : "identified_wrapper", =
    "type" : "record", 
    "fields" : [ 
         {"name" : "uuid"= , "type" : "string"},
        {"name" : "filename&qu= ot;, "type":"string"},
        {"name" : "content_has= h", "type":"string"},
        {"name" : "body",= "type":["bytes", "null"]},
        {"name" : "mime_type",= "type": ["string", "null"]},
        {"name" : "type_specif= ic", "type" : [{
                    =                      = ;       "name" : "message_meta_data",
                    =                      = ;       "type" : "record", 
                    =                      = ;       "fields" : [
                    =                      = ;          {"name" : "subject"= , "type" : ["string", "null"]}]
                    =                      = ;    },
                    =                      = ;    {
                    =                      = ;       "name" : "dublin_core_meta_data"= ,
                    =                      = ;       "type" : "record", 
                    =                      = ;       "fields" : [
                    =                      = ;          {"name" : "subject_one&q= uot;, "type" : ["string", "null"]}]
                    =                      = ;    },
                    =                      = ;    {
                    =                      = ;       "name" : "image_meta_data",
                    =                      = ;       "type" : "record", 
                    =                      = ;       "fields" : [{"name" : "subj= ect_two", "type" : ["string", "null"]}]<= /div>
                    =                      = ;     },
                    =                      = ;     "null"
                    =                      = ;   ]}
    ]
}


I'm trying to populate this object but I can't figure out how to creat= e records for the type_specific union type using GenericRecord.  My co= de currently looks like : 



    public static GenericRecord populateRecord(Schema schema= ) throws Exception {
            GenericRecord record =3D new= GenericData.Record(schema);

            String uuid =3D generateUuid= ();
            record.put(UUID, uuid);
            record.put(FILENAME, "T= EST");
            record.put(CONTENT_HASH= , "797987");
            record.put(BODY, null);=
            record.put(MIME_TYPE, &= quot;123321");
            
            

            GenericRecord record_dc =3D = new GenericData.Record(schema);
            record_dc.put("subject&= quot;, null);
            record.put("type_s= pecific", record_dc);
            return record;
        }


This returns with the error : 

Exception in thread "main" org.apache.avro.AvroRuntimeExcept= ion: Not a valid schema field: subject
at = org.apache.avro.generic.GenericData$Record.put(GenericData.java:90)
at = org.iqt.cdl.SpecificMetadataAvroExample.populateRecord(SpecificMetadataAvro= Example.java:79)
at = org.iqt.cdl.SpecificMetadataAvroExample.main(SpecificMetadataAvroExample.ja= va:133)


Is there  a way to do this? 

Karthik 
--_000_CB7CF6913A4Ekramachandraniqtorg_--