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 C6ADF99AB for ; Wed, 23 May 2012 23:01:41 +0000 (UTC) Received: (qmail 8195 invoked by uid 500); 23 May 2012 23:01:41 -0000 Delivered-To: apmail-avro-dev-archive@avro.apache.org Received: (qmail 8093 invoked by uid 500); 23 May 2012 23:01:41 -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 8065 invoked by uid 99); 23 May 2012 23:01:41 -0000 Received: from issues-vm.apache.org (HELO issues-vm) (140.211.11.160) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 May 2012 23:01:41 +0000 Received: from isssues-vm.apache.org (localhost [127.0.0.1]) by issues-vm (Postfix) with ESMTP id 523E41416DF for ; Wed, 23 May 2012 23:01:41 +0000 (UTC) Date: Wed, 23 May 2012 23:01:41 +0000 (UTC) From: "John Jenkins (JIRA)" To: dev@avro.apache.org Message-ID: <375544743.13847.1337814101340.JavaMail.jiratomcat@issues-vm> In-Reply-To: <1235747447.5786.1337642562415.JavaMail.jiratomcat@issues-vm> Subject: [jira] [Commented] (AVRO-1099) Int / Float cannot be decoded 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-1099?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13282019#comment-13282019 ] John Jenkins commented on AVRO-1099: ------------------------------------ Sorry for the comment spam. I wish I could have just edited my original. If you change the "type" of "DoubleValue" from "double" to ["double", "int"] like this: {code} /** * This is a sample Avro schema for an entry with multiple possible types, * "double" or "int". */ private static final String DEFINITION = "{" + "\"namespace\":\"test\"," + "\"type\":\"record\"," + "\"name\":\"DoubleTest\"," + "\"fields\":[" + "{" + "\"type\":[\"double\", \"int\"]," + "\"name\":\"DoubleValue\"" + "}" + "]" + "}"; {code} Then, it will always throw an exception now matter which example you use: {code} Exception in thread "main" org.apache.avro.AvroTypeException: Expected start-union. Got VALUE_NUMBER_FLOAT at org.apache.avro.io.JsonDecoder.error(JsonDecoder.java:697) at org.apache.avro.io.JsonDecoder.readIndex(JsonDecoder.java:441) at org.apache.avro.io.ResolvingDecoder.doAction(ResolvingDecoder.java:229) at org.apache.avro.io.parsing.Parser.advance(Parser.java:88) at org.apache.avro.io.ResolvingDecoder.readIndex(ResolvingDecoder.java:206) at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:148) at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:173) at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:144) at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:135) at test.AvroIntTest.main(AvroIntTest.java:62) {code} > Int / Float cannot be decoded > ----------------------------- > > Key: AVRO-1099 > URL: https://issues.apache.org/jira/browse/AVRO-1099 > Project: Avro > Issue Type: Bug > Components: java > Affects Versions: 1.6.3 > Environment: Mac OS X 10.7.3. Eclipse IDE for Java EE Developers 1.4.2.20120213 > Reporter: John Jenkins > Labels: patch > > I am currently using a JSON library that is encoding 0 for a double to "0" instead of "0.0", without the quotes. First, I feel that "0" is a perfectly valid value for 0 as a double. But, I tried to code around it by changing the "type" of the field to "["double", "int"]", without the quotes and it is giving me this error: > Exception in thread "main" org.apache.avro.AvroTypeException: Expected start-union. Got VALUE_NUMBER_INT > at org.apache.avro.io.JsonDecoder.error(JsonDecoder.java:697) > at org.apache.avro.io.JsonDecoder.readIndex(JsonDecoder.java:441) > at org.apache.avro.io.ResolvingDecoder.doAction(ResolvingDecoder.java:229) > at org.apache.avro.io.parsing.Parser.advance(Parser.java:88) > at org.apache.avro.io.ResolvingDecoder.readIndex(ResolvingDecoder.java:206) > at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:148) > at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:173) > at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:144) > at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:135) > If I change it to just "int", then it works for a few records until it reaches a double. > Thank you, > John -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira