Return-Path: X-Original-To: apmail-avro-dev-archive@www.apache.org Delivered-To: apmail-avro-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E6F8CD233 for ; Tue, 11 Sep 2012 17:28:07 +0000 (UTC) Received: (qmail 44061 invoked by uid 500); 11 Sep 2012 17:28:07 -0000 Delivered-To: apmail-avro-dev-archive@avro.apache.org Received: (qmail 44010 invoked by uid 500); 11 Sep 2012 17:28:07 -0000 Mailing-List: contact dev-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 dev@avro.apache.org Received: (qmail 44000 invoked by uid 99); 11 Sep 2012 17:28:07 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Sep 2012 17:28:07 +0000 Date: Wed, 12 Sep 2012 04:28:07 +1100 (NCT) From: "Doug Cutting (JIRA)" To: dev@avro.apache.org Message-ID: <236676806.64301.1347384487677.JavaMail.jiratomcat@arcas> In-Reply-To: <129239653.60970.1347321727677.JavaMail.jiratomcat@arcas> Subject: [jira] [Updated] (AVRO-1153) Exception when trying to write object with Nullable field that is of Stringable type MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/AVRO-1153?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Doug Cutting updated AVRO-1153: ------------------------------- Status: Open (was: Patch Available) The getSchemaName(Object) method is called for every instance written and is hence performance sensitive. Catching an exception is expensive. Rather we might code this something like: {code} Class c = datum.getClass() if (c.isAnnotationPresent(Stringable.class) || stringableClasses.contains(c)) return Schema.Type.STRING.getName(); return super.getSchemaName(datum); {code} Perhaps we should also add a private method like: {code} private boolean isStringable(Class c) { return c.isAnnotationPresent(Stringable.class) || stringableClasses.contains(c); } {code} Since otherwise this idiom will now be repeated in three places. > Exception when trying to write object with Nullable field that is of Stringable type > ------------------------------------------------------------------------------------ > > Key: AVRO-1153 > URL: https://issues.apache.org/jira/browse/AVRO-1153 > Project: Avro > Issue Type: Bug > Components: java > Affects Versions: 1.7.2 > Reporter: Alexandre Normand > Assignee: Alexandre Normand > Labels: newbie, reflection > Attachments: AVRO-1153.patch, AVRO-1153.patch, AVRO-1153.patch > > > There seems to be an issue with [stringable fields|https://issues.apache.org/jira/browse/AVRO-1146] that are nullable. I'm mostly using ReflectData.AllowNull in my real usage of this feature and I'm seeing it fail with this: > {code} > org.apache.avro.AvroRuntimeException: Unknown datum type: 10 > at org.apache.avro.generic.GenericData.getSchemaName(GenericData.java:574) > at org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:539) > at org.apache.avro.generic.GenericDatumWriter.resolveUnion(GenericDatumWriter.java:137) > at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:70) > at org.apache.avro.reflect.ReflectDatumWriter.write(ReflectDatumWriter.java:104) > at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105) > at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65) > at org.apache.avro.reflect.ReflectDatumWriter.write(ReflectDatumWriter.java:104) > at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:57) > {code} > Here's a quick test that shows this problem: > {code} > public static class N1 { > BigDecimal number; > } > @Test public void testNullableStringableField() throws Exception { > N1 datum = new N1(); > datum.number = BigDecimal.TEN; > checkBinary(ReflectData.AllowNull.get(), ReflectData.AllowNull.get().getSchema(N1.class), datum, false); > } > {code} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira